GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - vbfox/stidgen: Generate Strongly Typed Id types in C#

BranchesTags
Open more actions menu

Latest commit

 

History

321 Commits
321 Commits

Folders and files

NameName
Last commit message
Last commit date
.config
.config
 
 
.github
.github
 
 
.paket
.paket
 
 
.vscode
.vscode
 
 
samples
samples
 
 
src
src
 
 
.editorconfig
.editorconfig
 
 
.gitattributes
.gitattributes
 
 
.gitignore
.gitignore
 
 
LICENSE.md
LICENSE.md
 
 
Readme.md
Readme.md
 
 
Release Notes.md
Release Notes.md
 
 
build.cmd
build.cmd
 
 
build.sh
build.sh
 
 
global.json
global.json
 
 
paket.cmd
paket.cmd
 
 
paket.dependencies
paket.dependencies
 
 
paket.lock
paket.lock
 
 
paket.sh
paket.sh
 
 

Repository files navigation

Strongly Typed ID type Generator

Github Actions Status Nuget Package

This tool uses simple text files as input like :

public Corp.Product.UserId<string>

public Corp.Product.TweetId<long>
    EqualsUnderlying: true

And generate for each type specified a type that can be used as a strongly-typed ID:

  • It's an immutable value type with a single member.
  • The struct is partial to allow addition of methods and properties.
  • null values are disallowed by default and an extensibility point is available to add more application-dependent checks.
  • Casts from and to the underlying type are available. (explicit by default)
  • Equality member and operators are lifted, by default the ID types are only equals between themselves but equality with the underlying type is can be enabled with EqualsUnderlying setting.
  • IEquatable<T> is implemented.
  • IConvertible is implemented if the underlying type implement it.
  • IComparable<Id> is implemented if IComparable<Underlying> is implemented by the underlying type.
  • Other IComparable<T> implementations are lifted if EqualsUnderlying is set.
  • string IDs are interned by default.

Examples of generated files can be found in the sample folder.

Installation

The recommended way is via paket or nuget.

For nuget :

nuget install stidgen -ExcludeVersion -OutputDirectory packages

For paket, add nuget stidgen to your paket.dependencies and then to install it :

/.paket/paket.exe install

A zip file containing the latest released version can also be found in the latest GitHub release.

Usage

Then to generate all files specified by a stidgen definition file :

./packages/stidgen/tools/stidgen.exe myfile.stidgen

Definition file format

Each definition file can contain a number of types of the form :

public|internal [Namespace.]TypeName<UnderlyingType>
    PropertyA: value
    PropertyB: value

Properties :

  • ValueProperty (string): Specify the name of the property containing the underlying value. Default to "Value".
  • AllowNull (bool): Allow null underlying values (only applies if the underlying type is a reference type). Default to false.
  • InternString (bool): Intern string underlying values (only applies if the underlying type is string. Default to true.
  • EqualsUnderlying (bool): Make the underlying be equal to the Id type when Equals, CompareTo and == are called.
    Also implements IEquatable<Underlying> and IComparable<Underlying> on the id type.
  • CastToUnderlying ("explicit" or "implicit"): Specify how is generated the cast from the id type to the underlying type. Default to "explicit".
  • CastFromUnderlying ("explicit" or "implicit"): Specify how is generated the cast from the underlying type to the id type. Default to "explicit".
  • FileName (string): Full name of the file to generate for this type. Default to "TypeName.Generated.cs".
  • ProtobufnetSerializable (bool): Enable the generation of [ProtoContract] and [ProtoMember] attributes for protobuf-net support. Default to false.

About

Generate Strongly Typed Id types in C#

Topics

code-generationcsharp

Resources

Readme
MIT license
Activity

Stars

11 stars

Watchers

2 watching

Forks

2 forks
Report repository

Releases

Used by

Contributors

Languages

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.