Skip to content

Commit 84dbe77

Browse files
committed
docs: add readme
1 parent bb5ac81 commit 84dbe77

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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.

src/LinkDotNet.Blog.Web/LinkDotNet.Blog.Web.csproj

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
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"/>

0 commit comments

Comments
 (0)