File tree Expand file tree Collapse file tree 2 files changed +40
-1
lines changed
LinkDotNet.Blog.Generators Expand file tree Collapse file tree 2 files changed +40
-1
lines changed Original file line number Diff line number Diff line change 1+ # LinkDotNet.Blog.Generators
2+
3+ This project is a lightweight version of https://github.com/linkdotnet/Enumeration
4+
5+ The goal is that we have this:
6+ ``` csharp
7+ public abstract record Enumeration <TEnumeration >(string Key )
8+ where TEnumeration : Enumeration <TEnumeration >
9+ {
10+ public static FrozenSet <TEnumeration > All { get ; } = GetEnumerations ();
11+
12+ public static bool operator == (Enumeration <TEnumeration >? a , string ? b )
13+ => a is not null && b is not null && a .Key .Equals (b , StringComparison .Ordinal );
14+
15+ public static bool operator != (Enumeration <TEnumeration >? a , string ? b ) => ! (a == b );
16+
17+ public static TEnumeration Create (string key )
18+ => All .SingleOrDefault (p => p .Key == key )
19+ ?? throw new InvalidOperationException ($" {key } is not a valid value for {typeof (TEnumeration ).Name }" );
20+
21+ public sealed override string ToString () => Key ;
22+
23+ private static FrozenSet <TEnumeration > GetEnumerations ()
24+ {
25+ var enumerationType = typeof (TEnumeration );
26+
27+ return enumerationType
28+ .GetFields (BindingFlags .Public | BindingFlags .Static | BindingFlags .DeclaredOnly )
29+ .Where (info => info .FieldType == typeof (TEnumeration ))
30+ .Select (info => (TEnumeration )info .GetValue (null )! )
31+ .ToFrozenSet ();
32+ }
33+ }
34+ ```
35+
36+ At compile time! The idea is that we have the ` EnumerationAttribute ` that will scaffold the code for us.
Original file line number Diff line number Diff line change 44 <PackageReference Include =" AspNetCore.HealthChecks.UI.Client" />
55 <PackageReference Include =" Azure.Storage.Blobs" />
66 <PackageReference Include =" Blazored.Toast" />
7- <PackageReference Include =" LinkDotNet.BuildInformation" />
7+ <PackageReference Include =" LinkDotNet.BuildInformation" >
8+ <IncludeAssets >runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets >
9+ <PrivateAssets >all</PrivateAssets >
10+ </PackageReference >
811 <PackageReference Include =" NCronJob" />
912 <PackageReference Include =" Markdig" />
1013 <PackageReference Include =" Microsoft.AspNetCore.Authentication.OpenIdConnect" />
You can’t perform that action at this time.
0 commit comments