From 8cc1ecb0eed75f9d58fcacc463bc8f83ae800d83 Mon Sep 17 00:00:00 2001 From: Cedric Decoster Date: Sat, 14 Sep 2024 09:51:22 +0200 Subject: [PATCH] Next ver 068 (#84) * updated to 0.6.7 added new rust enum version updated net api to 24-rc5 * updated comments * next version --- README.md | 4 +-- .../Substrate.ServiceLayer.csproj | 2 +- .../Substrate/.template.config/template.json | 4 +-- .../Service/Node/EnumBuilder.cs | 31 +++++++++++++------ .../Substrate.DotNet/Substrate.DotNet.csproj | 2 +- Version.props | 4 +-- 6 files changed, 29 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 70bb814..f76a99f 100644 --- a/README.md +++ b/README.md @@ -56,7 +56,7 @@ Using a terminal of your choice, create a new directory for your project and exe ```sh dotnet new sln dotnet new substrate \ - --sdk_version 0.6.7 \ + --sdk_version 0.6.8 \ --rest_service PROJECTNAME.RestService \ --net_api PROJECTNAME.NetApiExt \ --net_integration PROJECTNAME.Integration \ @@ -127,7 +127,7 @@ You can also watch our short step-by-step tutorial that guides you through the e - AstarNET ```sh dotnet new substrate \ - --sdk_version 0.6.7 \ + --sdk_version 0.6.8 \ --rest_service AstarNET.RestService \ --net_api AstarNET.NetApiExt \ --net_api AstarNET.Integration \ diff --git a/Substrate.ServiceLayer/Substrate.ServiceLayer.csproj b/Substrate.ServiceLayer/Substrate.ServiceLayer.csproj index a9662ed..22594ce 100644 --- a/Substrate.ServiceLayer/Substrate.ServiceLayer.csproj +++ b/Substrate.ServiceLayer/Substrate.ServiceLayer.csproj @@ -12,7 +12,7 @@ - + diff --git a/Tools/Substrate.DotNet.Template/templates/Substrate/.template.config/template.json b/Tools/Substrate.DotNet.Template/templates/Substrate/.template.config/template.json index 0815bf3..e62acdc 100644 --- a/Tools/Substrate.DotNet.Template/templates/Substrate/.template.config/template.json +++ b/Tools/Substrate.DotNet.Template/templates/Substrate/.template.config/template.json @@ -12,14 +12,14 @@ "symbols": { "sdk_version": { "datatype": "string", - "defaultValue": "0.6.7", + "defaultValue": "0.6.8", "description": "Uses the given Substrate .NET Toolchain version.", "replaces": "SUBSTRATE_TOOLCHAIN_VERSION", "type": "parameter" }, "api_version": { "datatype": "string", - "defaultValue": "0.9.24-rc5", + "defaultValue": "0.9.24-rc6", "description": "Uses the given Substrate .NET API version.", "replaces": "SUBSTRATE_NETAPI_VERSION", "type": "parameter" diff --git a/Tools/Substrate.DotNet/Service/Node/EnumBuilder.cs b/Tools/Substrate.DotNet/Service/Node/EnumBuilder.cs index 8115319..aa027a0 100644 --- a/Tools/Substrate.DotNet/Service/Node/EnumBuilder.cs +++ b/Tools/Substrate.DotNet/Service/Node/EnumBuilder.cs @@ -31,16 +31,19 @@ public override TypeBuilderBase Create() ClassName = $"Enum{enumName}"; ReferenzName = $"{NamespaceName}.{ClassName}"; - CodeNamespace typeNamespace = new(NamespaceName); + var typeNamespace = new CodeNamespace(NamespaceName); TargetUnit.Namespaces.Add(typeNamespace); // Create the enum itself - CodeTypeDeclaration enumType = new(enumName) + var enumType = new CodeTypeDeclaration(enumName) { IsEnum = true }; enumType.Comments.AddRange(GetComments(typeDef.Docs, null, enumName)); + // Detect if this enum has associated types + bool hasAssociatedTypes = false; + if (typeDef.Variants != null) { foreach (TypeVariant variant in typeDef.Variants) @@ -51,11 +54,17 @@ public override TypeBuilderBase Create() }; enumMember.Comments.AddRange(GetComments(variant.Docs, null, variant.Name)); enumType.Members.Add(enumMember); + + // Check if this variant has associated types + if (variant.TypeFields != null && variant.TypeFields.Length > 0) + { + hasAssociatedTypes = true; + } } } typeNamespace.Types.Add(enumType); - // Generate the class based on BaseEnumRust + // Generate the appropriate class based on whether there are associated types var targetClass = new CodeTypeDeclaration(ClassName) { IsClass = true, @@ -63,14 +72,13 @@ public override TypeBuilderBase Create() }; targetClass.Comments.AddRange(GetComments(typeDef.Docs, typeDef)); - if (typeDef.Variants != null) + if (hasAssociatedTypes) { - // Constructor to register decoders + // Generate the class based on BaseEnumRust (with associated types) var codeConstructor = new CodeConstructor { Attributes = MemberAttributes.Public }; - codeConstructor.Comments.AddRange(GetComments(new string[] { "Initializes a new instance of the class." }, null)); foreach (TypeVariant variant in typeDef.Variants) @@ -96,15 +104,18 @@ public override TypeBuilderBase Create() ); } + targetClass.BaseTypes.Add(new CodeTypeReference($"BaseEnumRust<{enumName}>")); targetClass.Members.Add(codeConstructor); } + else + { + // Generate the class based on BaseEnum (without associated types) + targetClass.BaseTypes.Add(new CodeTypeReference($"BaseEnum<{enumName}>")); + } - targetClass.BaseTypes.Add(new CodeTypeReference($"BaseEnumRust<{enumName}>")); typeNamespace.Types.Add(targetClass); return this; } - - } -} +} \ No newline at end of file diff --git a/Tools/Substrate.DotNet/Substrate.DotNet.csproj b/Tools/Substrate.DotNet/Substrate.DotNet.csproj index be34680..b7d9cc3 100644 --- a/Tools/Substrate.DotNet/Substrate.DotNet.csproj +++ b/Tools/Substrate.DotNet/Substrate.DotNet.csproj @@ -40,7 +40,7 @@ - + diff --git a/Version.props b/Version.props index b2684a8..3c465ca 100644 --- a/Version.props +++ b/Version.props @@ -4,10 +4,10 @@ 0 6 - 7 + 8 $(VersionMajor).$(VersionMinor).$(VersionPatch) - 0.6.7 + 0.6.8 $(AssemblyVersion)