From b8d35768de4d1b66c2b65c92c1d36b0f3bd1fad8 Mon Sep 17 00:00:00 2001 From: "David G. Moore, Jr." Date: Fri, 29 Dec 2023 00:39:53 -0500 Subject: [PATCH] Added the new Runtime project --- ....Enumerations.CodeGenerator.Runtime.csproj | 11 +++ ...mjr.Enumerations.CodeGenerator.Runtime.sln | 42 ++++++++++ Runtime/EnumerationJsonConverter.cs | 34 ++++++++ Runtime/EnumerationJsonConverterAttribute.cs | 7 ++ Runtime/EnumerationJsonConverterFactory.cs | 20 +++++ Runtime/EnumerationSerializationDto.cs | 80 +++++++++++++++++++ Runtime/README.md | 27 +++++++ Runtime/UniversalUriResolver.cs | 50 ++++++++++++ ....Enumerations.CodeGenerator.Samples.csproj | 1 + ...mjr.Enumerations.CodeGenerator.Samples.sln | 26 +++--- src/Dgmjr.Enumerations.CodeGenerator.csproj | 5 ++ src/Dgmjr.Enumerations.CodeGenerator.sln | 14 ++++ ...ateEnumerationTypeAttributeDeclarations.cs | 32 +++----- src/Resources/Header.scriban | 1 + src/Resources/IEnumeration.scriban | 1 + src/Resources/NestedEnumerationType.scriban | 2 +- 16 files changed, 320 insertions(+), 33 deletions(-) create mode 100644 Runtime/Dgmjr.Enumerations.CodeGenerator.Runtime.csproj create mode 100644 Runtime/Dgmjr.Enumerations.CodeGenerator.Runtime.sln create mode 100644 Runtime/EnumerationJsonConverter.cs create mode 100644 Runtime/EnumerationJsonConverterAttribute.cs create mode 100644 Runtime/EnumerationJsonConverterFactory.cs create mode 100644 Runtime/EnumerationSerializationDto.cs create mode 100644 Runtime/README.md create mode 100644 Runtime/UniversalUriResolver.cs diff --git a/Runtime/Dgmjr.Enumerations.CodeGenerator.Runtime.csproj b/Runtime/Dgmjr.Enumerations.CodeGenerator.Runtime.csproj new file mode 100644 index 0000000..a546d6f --- /dev/null +++ b/Runtime/Dgmjr.Enumerations.CodeGenerator.Runtime.csproj @@ -0,0 +1,11 @@ + + + netstandard2.0 + + + + + + + + diff --git a/Runtime/Dgmjr.Enumerations.CodeGenerator.Runtime.sln b/Runtime/Dgmjr.Enumerations.CodeGenerator.Runtime.sln new file mode 100644 index 0000000..e130f55 --- /dev/null +++ b/Runtime/Dgmjr.Enumerations.CodeGenerator.Runtime.sln @@ -0,0 +1,42 @@ +Microsoft Visual Studio Solution File, Format Version 12.00 +# +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{B283EBC2-E01F-412D-9339-FD56EF114549}" + ProjectSection(SolutionItems) = preProject + ..\..\..\..\..\Directory.Build.props = ..\..\..\..\..\Directory.Build.props + ..\..\..\..\..\Directory.Build.targets = ..\..\..\..\..\Directory.Build.targets + ..\..\..\..\..\global.json = ..\..\..\..\..\global.json + ..\..\..\..\..\Packages\Versions.Local.props = ..\..\..\..\..\Packages\Versions.Local.props + EndProjectSection +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dgmjr.Enumerations.CodeGenerator.Runtime", "Dgmjr.Enumerations.CodeGenerator.Runtime.csproj", "{E33DF0D9-620C-4445-82BB-6A5E88D76295}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Local|Any CPU = Local|Any CPU + Debug|Any CPU = Debug|Any CPU + Testing|Any CPU = Testing|Any CPU + Staging|Any CPU = Staging|Any CPU + Production|Any CPU = Production|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {E33DF0D9-620C-4445-82BB-6A5E88D76295}.Local|Any CPU.ActiveCfg = Local|Any CPU + {E33DF0D9-620C-4445-82BB-6A5E88D76295}.Local|Any CPU.Build.0 = Local|Any CPU + {E33DF0D9-620C-4445-82BB-6A5E88D76295}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E33DF0D9-620C-4445-82BB-6A5E88D76295}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E33DF0D9-620C-4445-82BB-6A5E88D76295}.Testing|Any CPU.ActiveCfg = Testing|Any CPU + {E33DF0D9-620C-4445-82BB-6A5E88D76295}.Testing|Any CPU.Build.0 = Testing|Any CPU + {E33DF0D9-620C-4445-82BB-6A5E88D76295}.Staging|Any CPU.ActiveCfg = Staging|Any CPU + {E33DF0D9-620C-4445-82BB-6A5E88D76295}.Staging|Any CPU.Build.0 = Staging|Any CPU + {E33DF0D9-620C-4445-82BB-6A5E88D76295}.Production|Any CPU.ActiveCfg = Local|Any CPU + {E33DF0D9-620C-4445-82BB-6A5E88D76295}.Production|Any CPU.Build.0 = Local|Any CPU + {E33DF0D9-620C-4445-82BB-6A5E88D76295}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E33DF0D9-620C-4445-82BB-6A5E88D76295}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {44E1535F-C020-4710-88C8-13B03F0C33B8} + EndGlobalSection +EndGlobal diff --git a/Runtime/EnumerationJsonConverter.cs b/Runtime/EnumerationJsonConverter.cs new file mode 100644 index 0000000..a8d16c1 --- /dev/null +++ b/Runtime/EnumerationJsonConverter.cs @@ -0,0 +1,34 @@ +namespace Dgmjr.Enumerations; + +using Dgmjr.Abstractions; + +public class EnumerationJsonConverter : JsonConverter + where TEnumeration : IIdentifiable, + IHaveADescription, + IHaveAName, + IHaveAShortName, + IHaveAUri, + IHaveAValue, + IHaveADisplayName, + IHaveAGuid +{ + public override TEnumeration Read( + ref Utf8JsonReader reader, + type typeToConvert, + Jso options + ) + { + var dto = Deserialize>(reader.ValueSpan, options); + return UniversalUriResolver.ResolveUri(dto.Uri); + } + + public override void Write( + Utf8JsonWriter writer, + TEnumeration value, + Jso options + ) + { + var dto = EnumerationSerializationDto.FromEnumeration(value); + Serialize(writer, dto, options); + } +} diff --git a/Runtime/EnumerationJsonConverterAttribute.cs b/Runtime/EnumerationJsonConverterAttribute.cs new file mode 100644 index 0000000..1989923 --- /dev/null +++ b/Runtime/EnumerationJsonConverterAttribute.cs @@ -0,0 +1,7 @@ +namespace Dgmjr.Enumerations; + +public sealed class EnumerationJsonConverterAttribute : JConverterAttribute +{ + public EnumerationJsonConverterAttribute() + : base(typeof(EnumerationJsonConverterFactory)) { } +} diff --git a/Runtime/EnumerationJsonConverterFactory.cs b/Runtime/EnumerationJsonConverterFactory.cs new file mode 100644 index 0000000..7b357e1 --- /dev/null +++ b/Runtime/EnumerationJsonConverterFactory.cs @@ -0,0 +1,20 @@ +namespace Dgmjr.Enumerations; + +using Dgmjr.Abstractions; + +public class EnumerationJsonConverterFactory : JsonConverterFactory +{ + private static readonly type[] Interfaces = [typeof(IIdentifiable), typeof(IHaveAGuid), typeof(IHaveAUri), typeof(IHaveAValue), typeof(IHaveAName), typeof(IHaveAShortName), typeof(IHaveADisplayName), typeof(IHaveADescription)]; + + public override bool CanConvert(type typeToConvert) => + TrueForAll(Interfaces, i => i.IsAssignableFrom(typeToConvert)); + + public override JConverter? CreateConverter( + type typeToConvert, + Jso options + ) + { + var converterType = typeof(EnumerationJsonConverter<>).MakeGenericType(typeToConvert); + return (JConverter?)Activator.CreateInstance(converterType); + } +} diff --git a/Runtime/EnumerationSerializationDto.cs b/Runtime/EnumerationSerializationDto.cs new file mode 100644 index 0000000..fba866c --- /dev/null +++ b/Runtime/EnumerationSerializationDto.cs @@ -0,0 +1,80 @@ +namespace Dgmjr.Enumerations; + +using System.Collections.Concurrent; +using System.Collections.Immutable; +using System.Text.Json.Nodes; + +using Dgmjr.Abstractions; + +public record class EnumerationSerializationDto(uri Uri, + string Description, + IDictionary Ids, + IStringDictionary Names +) +{ + protected const string Id = "id"; + protected const string Guid = "guid"; + protected const string Name = "name"; + protected const string Short = "short"; + protected const string Display = "display"; + public static readonly EnumerationSerializationDto Empty = + new( + uri.Empty, + string.Empty, + ImmutableDictionary.Empty, + ImmutableDictionary.Empty + ); + + public static EnumerationSerializationDto FromEnumeration( + object e + ) => + new( + (e as IHaveAUri).Uri.ToString(), + (e as IHaveADescription).Description, + new Dictionary() { { Id, (e as IIdentifiable).Id }, { Guid, (e as IHaveAGuid).Guid } }, + new StringDictionary() + { + { Name, (e as IHaveAName).Name }, + { Short, (e as IHaveAShortName).ShortName }, + { Display, (e as IHaveADisplayName).DisplayName } + } + ); + + public uri Uri { get; init; } = Uri; + public string Description { get; init; } = Description; + public IDictionary Ids { get; init; } = + new Dictionary(Ids, StringComparer.OrdinalIgnoreCase); + public IStringDictionary Names { get; init; } = + new StringDictionary(Names, StringComparer.OrdinalIgnoreCase); +} + +public record class EnumerationSerializationDto( + uri Uri, + string Description, + IDictionary Ids, + IStringDictionary Names +) : EnumerationSerializationDto(Uri, Description, Ids, Names) + where TEnumeration : IIdentifiable, + IHaveADescription, + IHaveAName, + IHaveAShortName, + IHaveAUri, + IHaveAValue, + IHaveADisplayName, + IHaveAGuid +{ + public static EnumerationSerializationDto FromEnumeration( + TEnumeration e + ) => + new( + e.Uri.ToString(), + e.Description, + new Dictionary() { { Id, e.Id }, { Guid, e.Guid } }, + new StringDictionary() + { + { Name, e.Name }, + { Short, e.ShortName }, + { Display, e.DisplayName } + } + ); +} diff --git a/Runtime/README.md b/Runtime/README.md new file mode 100644 index 0000000..31cf793 --- /dev/null +++ b/Runtime/README.md @@ -0,0 +1,27 @@ +--- +title: +lastmod: 2023-26-28T19:26:44.3950-05:00Z +date: 2023-26-28T19:26:44.3952-05:00Z +license: MIT +slug: Dgmjr.Enumerations.CodeGenerator.Runtime-readme +version: +authors: + - dgmjr; +description: Dgmjr.Enumerations.CodeGenerator.Runtime Readme #TODO: write description for Dgmjr.Enumerations.CodeGenerator.Runtime Readme +keywords: +- Dgmjr.Enumerations.CodeGenerator.Runtime + - dgmjr + - dgmjr-io +type: readme +--- +# Dgmjr.Enumerations.CodeGenerator.Runtime Readme + +## Package Description +## Getting Started +## Prerequisites +## Installation +## Usage +## Contributing +## Versioning +Built from [commit on branch main at ] +(/tree/) diff --git a/Runtime/UniversalUriResolver.cs b/Runtime/UniversalUriResolver.cs new file mode 100644 index 0000000..f961e5a --- /dev/null +++ b/Runtime/UniversalUriResolver.cs @@ -0,0 +1,50 @@ +namespace Dgmjr.Enumerations; + +using System.Collections.Concurrent; + +using Dgmjr.Abstractions; + +public static class UniversalUriResolver +{ + private static readonly IDictionary _cache = new ConcurrentDictionary(); + const string Parse = nameof(Parse); + delegate object ParseDelegate(string s); + + public static TEnumeration ResolveUri( + uri uri + ) + where TEnumeration : IIdentifiable, + IHaveADescription, + IHaveAName, + IHaveAShortName, + IHaveAUri, + IHaveAValue, + IHaveADisplayName, + IHaveAGuid + => (TEnumeration)(_cache[uri] = _cache.TryGetValue(uri, out var value) ? (TEnumeration)value : CurrentDomain.GetAssemblies().SelectMany(a => a.GetTypes()).Select(GetParseDelegate).WhereNotNull().Select(d => { try { return d(uri.ToString()); } catch { return null; } }).WhereNotNull().FirstOrDefault()); + + static MethodInfo? GetParseMethod( + this type type + ) + where TEnumeration : IIdentifiable, + IHaveADescription, + IHaveAName, + IHaveAShortName, + IHaveAUri, + IHaveAValue, + IHaveADisplayName, + IHaveAGuid => + type.GetRuntimeMethods().FirstOrDefault(m => m.Name == Parse && typeof(TEnumeration).IsAssignableFrom(m.ReturnType) && m.GetParameters().Length == 1 && m.GetParameters()[0].ParameterType == typeof(string)); + + static ParseDelegate? GetParseDelegate(this type type) + where TEnumeration : IIdentifiable, + IHaveADescription, + IHaveAName, + IHaveAShortName, + IHaveAUri, + IHaveAValue, + IHaveADisplayName, + IHaveAGuid + => + type.GetParseMethod().CreateDelegate(typeof(ParseDelegate)) as ParseDelegate; +} diff --git a/Samples/Dgmjr.Enumerations.CodeGenerator.Samples.csproj b/Samples/Dgmjr.Enumerations.CodeGenerator.Samples.csproj index ce4bbf8..4cfc332 100644 --- a/Samples/Dgmjr.Enumerations.CodeGenerator.Samples.csproj +++ b/Samples/Dgmjr.Enumerations.CodeGenerator.Samples.csproj @@ -23,6 +23,7 @@ + diff --git a/Samples/Dgmjr.Enumerations.CodeGenerator.Samples.sln b/Samples/Dgmjr.Enumerations.CodeGenerator.Samples.sln index de1b012..59ba6b9 100644 --- a/Samples/Dgmjr.Enumerations.CodeGenerator.Samples.sln +++ b/Samples/Dgmjr.Enumerations.CodeGenerator.Samples.sln @@ -8,7 +8,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution ..\..\..\..\..\Packages\Versions.Local.props = ..\..\..\..\..\Packages\Versions.Local.props EndProjectSection EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dgmjr.Enumerations.CodeGenerator.Samples", "Dgmjr.Enumerations.CodeGenerator.Samples.csproj", "{72AF42ED-1B8A-46BA-BDB6-E666F7019AF7}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dgmjr.Enumerations.CodeGenerator.Samples", "Dgmjr.Enumerations.CodeGenerator.Samples.csproj", "{D33298F0-5910-47AB-A268-803BACB636B9}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -20,18 +20,18 @@ Global Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {72AF42ED-1B8A-46BA-BDB6-E666F7019AF7}.Local|Any CPU.ActiveCfg = Local|Any CPU - {72AF42ED-1B8A-46BA-BDB6-E666F7019AF7}.Local|Any CPU.Build.0 = Local|Any CPU - {72AF42ED-1B8A-46BA-BDB6-E666F7019AF7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {72AF42ED-1B8A-46BA-BDB6-E666F7019AF7}.Debug|Any CPU.Build.0 = Debug|Any CPU - {72AF42ED-1B8A-46BA-BDB6-E666F7019AF7}.Testing|Any CPU.ActiveCfg = Testing|Any CPU - {72AF42ED-1B8A-46BA-BDB6-E666F7019AF7}.Testing|Any CPU.Build.0 = Testing|Any CPU - {72AF42ED-1B8A-46BA-BDB6-E666F7019AF7}.Staging|Any CPU.ActiveCfg = Staging|Any CPU - {72AF42ED-1B8A-46BA-BDB6-E666F7019AF7}.Staging|Any CPU.Build.0 = Staging|Any CPU - {72AF42ED-1B8A-46BA-BDB6-E666F7019AF7}.Production|Any CPU.ActiveCfg = Local|Any CPU - {72AF42ED-1B8A-46BA-BDB6-E666F7019AF7}.Production|Any CPU.Build.0 = Local|Any CPU - {72AF42ED-1B8A-46BA-BDB6-E666F7019AF7}.Release|Any CPU.ActiveCfg = Release|Any CPU - {72AF42ED-1B8A-46BA-BDB6-E666F7019AF7}.Release|Any CPU.Build.0 = Release|Any CPU + {D33298F0-5910-47AB-A268-803BACB636B9}.Local|Any CPU.ActiveCfg = Local|Any CPU + {D33298F0-5910-47AB-A268-803BACB636B9}.Local|Any CPU.Build.0 = Local|Any CPU + {D33298F0-5910-47AB-A268-803BACB636B9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D33298F0-5910-47AB-A268-803BACB636B9}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D33298F0-5910-47AB-A268-803BACB636B9}.Testing|Any CPU.ActiveCfg = Testing|Any CPU + {D33298F0-5910-47AB-A268-803BACB636B9}.Testing|Any CPU.Build.0 = Testing|Any CPU + {D33298F0-5910-47AB-A268-803BACB636B9}.Staging|Any CPU.ActiveCfg = Staging|Any CPU + {D33298F0-5910-47AB-A268-803BACB636B9}.Staging|Any CPU.Build.0 = Staging|Any CPU + {D33298F0-5910-47AB-A268-803BACB636B9}.Production|Any CPU.ActiveCfg = Local|Any CPU + {D33298F0-5910-47AB-A268-803BACB636B9}.Production|Any CPU.Build.0 = Local|Any CPU + {D33298F0-5910-47AB-A268-803BACB636B9}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D33298F0-5910-47AB-A268-803BACB636B9}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/src/Dgmjr.Enumerations.CodeGenerator.csproj b/src/Dgmjr.Enumerations.CodeGenerator.csproj index 1aed6cf..e12fa10 100644 --- a/src/Dgmjr.Enumerations.CodeGenerator.csproj +++ b/src/Dgmjr.Enumerations.CodeGenerator.csproj @@ -36,6 +36,7 @@ + @@ -54,6 +55,10 @@ + + + + diff --git a/src/Dgmjr.Enumerations.CodeGenerator.sln b/src/Dgmjr.Enumerations.CodeGenerator.sln index 132e9e5..6676520 100644 --- a/src/Dgmjr.Enumerations.CodeGenerator.sln +++ b/src/Dgmjr.Enumerations.CodeGenerator.sln @@ -8,6 +8,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution ..\..\..\..\..\Packages\Versions.Local.props = ..\..\..\..\..\Packages\Versions.Local.props EndProjectSection EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dgmjr.Enumerations.CodeGenerator.Runtime", "..\Runtime\Dgmjr.Enumerations.CodeGenerator.Runtime.csproj", "{C259423F-CBF0-4111-9B9F-356907207E00}" +EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dgmjr.Enumerations.CodeGenerator", "Dgmjr.Enumerations.CodeGenerator.csproj", "{C4622771-2A7B-42E6-9B3C-8F71CDD7E65B}" EndProject Global @@ -20,6 +22,18 @@ Global Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution + {C259423F-CBF0-4111-9B9F-356907207E00}.Local|Any CPU.ActiveCfg = Local|Any CPU + {C259423F-CBF0-4111-9B9F-356907207E00}.Local|Any CPU.Build.0 = Local|Any CPU + {C259423F-CBF0-4111-9B9F-356907207E00}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C259423F-CBF0-4111-9B9F-356907207E00}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C259423F-CBF0-4111-9B9F-356907207E00}.Testing|Any CPU.ActiveCfg = Testing|Any CPU + {C259423F-CBF0-4111-9B9F-356907207E00}.Testing|Any CPU.Build.0 = Testing|Any CPU + {C259423F-CBF0-4111-9B9F-356907207E00}.Staging|Any CPU.ActiveCfg = Staging|Any CPU + {C259423F-CBF0-4111-9B9F-356907207E00}.Staging|Any CPU.Build.0 = Staging|Any CPU + {C259423F-CBF0-4111-9B9F-356907207E00}.Production|Any CPU.ActiveCfg = Local|Any CPU + {C259423F-CBF0-4111-9B9F-356907207E00}.Production|Any CPU.Build.0 = Local|Any CPU + {C259423F-CBF0-4111-9B9F-356907207E00}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C259423F-CBF0-4111-9B9F-356907207E00}.Release|Any CPU.Build.0 = Release|Any CPU {C4622771-2A7B-42E6-9B3C-8F71CDD7E65B}.Local|Any CPU.ActiveCfg = Local|Any CPU {C4622771-2A7B-42E6-9B3C-8F71CDD7E65B}.Local|Any CPU.Build.0 = Local|Any CPU {C4622771-2A7B-42E6-9B3C-8F71CDD7E65B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU diff --git a/src/Resources/GenerateEnumerationTypeAttributeDeclarations.cs b/src/Resources/GenerateEnumerationTypeAttributeDeclarations.cs index bc4a626..e2a365c 100644 --- a/src/Resources/GenerateEnumerationTypeAttributeDeclarations.cs +++ b/src/Resources/GenerateEnumerationTypeAttributeDeclarations.cs @@ -1,37 +1,31 @@ using System; -using static System.AttributeTargets; -using ATargets = System.AttributeTargets; +using Targets = System.AttributeTargets; +using UsageAttribute = System.AttributeUsageAttribute; -[AttributeUsage(Class | Struct | ATargets.Enum)] -internal abstract class GenerateEnumerationTypeAttribute : Attribute +[Usage(Targets.Class | Targets.Struct | Targets.Enum)] +internal abstract class GenerateEnumerationTypeAttribute( + string? typeName = default, + string? @namespace = default +) : Attribute { - protected GenerateEnumerationTypeAttribute( - string? typeName = default, - string? @namespace = default - ) - { - Namespace = @namespace; - TypeName = typeName; - } - - public string? Namespace { get; } - public string? TypeName { get; } + public string? Namespace { get; } = @namespace; + public string? TypeName { get; } = @typeName; } -[AttributeUsage(Class | Struct | ATargets.Enum)] +[Usage(Targets.Class | Targets.Struct | Targets.Enum)] internal sealed class GenerateEnumerationRecordStructAttribute( string? typeName = default, string? @namespace = default ) : GenerateEnumerationTypeAttribute(typeName, @namespace) { } -[AttributeUsage(Class | Struct | ATargets.Enum)] +[Usage(Targets.Class | Targets.Struct | Targets.Enum)] internal sealed class GenerateEnumerationStructAttribute( string? typeName = default, string? @namespace = default ) : GenerateEnumerationTypeAttribute(typeName, @namespace) { } -[AttributeUsage(Class | Struct | ATargets.Enum)] +[Usage(Targets.Class | Targets.Struct | Targets.Enum)] internal sealed class GenerateEnumerationRecordClassAttribute( string? typeName = default, string? @namespace = default, @@ -41,7 +35,7 @@ internal sealed class GenerateEnumerationRecordClassAttribute( public Type? BaseType { get; } = baseType; } -[AttributeUsage(Class | Struct | ATargets.Enum)] +[Usage(Targets.Class | Targets.Struct | Targets.Enum)] internal sealed class GenerateEnumerationClassAttribute( string? typeName = default, string? @namespace = default, diff --git a/src/Resources/Header.scriban b/src/Resources/Header.scriban index 6672d9f..0650499 100644 --- a/src/Resources/Header.scriban +++ b/src/Resources/Header.scriban @@ -23,4 +23,5 @@ using System.Text.Json.Serialization; using System.Text.Json; using System.Xml.Serialization; using JsonIgnoreAttribute = System.Text.Json.Serialization.JsonIgnoreAttribute; +using Dgmjr.Enumerations; #nullable enable diff --git a/src/Resources/IEnumeration.scriban b/src/Resources/IEnumeration.scriban index 30d57f0..b8d3bf1 100644 --- a/src/Resources/IEnumeration.scriban +++ b/src/Resources/IEnumeration.scriban @@ -2,6 +2,7 @@ namespace {{ dto_namespace }}.Abstractions; using {{ dto_namespace }}; {{ compiler_generated_attributes }} +[EnumerationJsonConverter] public partial interface I{{ dto_type_name }} : IHaveAName, IHaveAValue, diff --git a/src/Resources/NestedEnumerationType.scriban b/src/Resources/NestedEnumerationType.scriban index fe31513..07222f5 100644 --- a/src/Resources/NestedEnumerationType.scriban +++ b/src/Resources/NestedEnumerationType.scriban @@ -6,7 +6,7 @@ public partial {{ data_structure_type }} @{{ dto_type_name }} {{ if base_type != /// {{ description }} /// {{ compiler_generated_attributes }} - [{{ field_name }}JsonConverterAttribute] + [EnumerationJsonConverter] public partial {{ data_structure_type }} @{{ field_name }} : {{ if base_type != "" && base_type != null }}{{ dto_type_name }}, {{ end }} I{{ enumeration_name }}