From 7d214764e06998773f59b852c1c7819d799710a5 Mon Sep 17 00:00:00 2001 From: Fabricio Caneva Date: Sat, 12 Oct 2024 13:08:56 -0300 Subject: [PATCH] downgrade to netstandard2.0 --- .../EnhancedConfigurationGenerator.cs | 12 ++++++------ .../Generators/SettingsProviderGenerator.cs | 10 +++++++--- external/sourcegen/Utils/ConfigurationFilter.cs | 17 +++++++++++------ external/sourcegen/sourcegen.csproj | 2 +- .../Assets/Plugins/config-assets.sourcegen.dll | 4 ++-- 5 files changed, 27 insertions(+), 18 deletions(-) diff --git a/external/sourcegen/Generators/EnhancedConfigurationGenerator.cs b/external/sourcegen/Generators/EnhancedConfigurationGenerator.cs index 3e86337..0b33c50 100644 --- a/external/sourcegen/Generators/EnhancedConfigurationGenerator.cs +++ b/external/sourcegen/Generators/EnhancedConfigurationGenerator.cs @@ -46,7 +46,7 @@ public partial class {meta.ClassName} : ScriptableObject {{ if (_instance == null) {{ _instance = Services.ConfigLoader.Load<{meta.ClassName}>(ConfigurationTypes[""{meta.FullyQualifiedName}""]); }} - + return _instance; }} }} @@ -57,9 +57,9 @@ public partial class {meta.ClassName} : ScriptableObject {{ sb.AppendLine($" public static {field.Type} {field.PropertyName} => Instance.{field.Name};"); } - sb.Append(@$" - }} -}} + sb.Append(@" + } +} "); return sb.ToString(); @@ -79,10 +79,10 @@ private static IEnumerable GetFields(INamedTypeSymbol attributeType, PropertyName = ConvertToPropertyName(x.Name) }); } - + private static string ConvertToPropertyName(string name) { name = name.Replace("m_", "").Replace("_", ""); - return name[..1].ToUpper() + name[1..]; + return char.ToUpper(name[0]) + name.Substring(1); } private struct MemberInfo { diff --git a/external/sourcegen/Generators/SettingsProviderGenerator.cs b/external/sourcegen/Generators/SettingsProviderGenerator.cs index 04f80bd..a97d197 100644 --- a/external/sourcegen/Generators/SettingsProviderGenerator.cs +++ b/external/sourcegen/Generators/SettingsProviderGenerator.cs @@ -48,8 +48,10 @@ private static SettingsProvider CreateProvider(AssetMetadata metadata, string na "); foreach (var provider in providers) { - var displayName = !string.IsNullOrWhiteSpace(provider.DisplayName) ? provider.DisplayName : provider.Metadata.ClassName; - + var displayName = !string.IsNullOrWhiteSpace(provider.DisplayName) + ? provider.DisplayName + : provider.Metadata.ClassName; + sb.Append($@" [SettingsProvider] public static SettingsProvider Create{provider.Metadata.FullyQualifiedName.Sanitize()}Provider() {{ @@ -66,7 +68,9 @@ private static SettingsProvider CreateProvider(AssetMetadata metadata, string na } private static string GetKeywords(IReadOnlyCollection keywords) { - return keywords.Count == 0 ? "null" : $"new string[] {{{string.Join(", ", keywords.Select(x => @$"""{x}"""))}}}"; + return keywords.Count == 0 + ? "null" + : $"new string[] {{{string.Join(", ", keywords.Select(x => $"\"{x}\""))}}}"; } } } \ No newline at end of file diff --git a/external/sourcegen/Utils/ConfigurationFilter.cs b/external/sourcegen/Utils/ConfigurationFilter.cs index a1b9072..437063a 100644 --- a/external/sourcegen/Utils/ConfigurationFilter.cs +++ b/external/sourcegen/Utils/ConfigurationFilter.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using ConfigAssets.Sourcegen.Models; using Microsoft.CodeAnalysis; @@ -11,8 +12,8 @@ public static class ConfigurationFilter { private static readonly SymbolDisplayFormat SymbolDisplayFormat = new SymbolDisplayFormat(typeQualificationStyle: SymbolDisplayTypeQualificationStyle.NameAndContainingTypesAndNamespaces); - public static IEnumerable<(ClassDeclarationSyntax @class, ISymbol classSymbol, ConfigAttributeData data)> FilterProviders(Compilation compilation, - IEnumerable classes) { + public static IEnumerable<(ClassDeclarationSyntax @class, ISymbol classSymbol, ConfigAttributeData data)> + FilterProviders(Compilation compilation, IEnumerable classes) { var targetAttribute = compilation.GetType(ConfigAttributeName); foreach (var @class in classes) { @@ -54,16 +55,19 @@ private static void ReadAttributeData(ConfigAttributeData data, AttributeData at foreach (var pair in attribute.NamedArguments.Where(x => !x.Value.IsNull)) { switch (pair.Key) { case "GenerateSingleton": - data.GenerateSingleton = (bool)pair.Value.Value!; + Debug.Assert(pair.Value.Value != null, "pair.Value.Value != null"); + data.GenerateSingleton = (bool)pair.Value.Value; break; case "DisplayName": data.DisplayName = (string)pair.Value.Value; break; case "Scope": - data.Scope = (int)pair.Value.Value!; + Debug.Assert(pair.Value.Value != null, "pair.Value.Value != null"); + data.Scope = (int)pair.Value.Value; break; case "EnableProvider": - data.EnableProvider = (bool)pair.Value.Value!; + Debug.Assert(pair.Value.Value != null, "pair.Value.Value != null"); + data.EnableProvider = (bool)pair.Value.Value; break; case "Keywords": data.Keywords = pair.Value.Values.Select(x => (string)x.Value).ToArray(); @@ -75,7 +79,8 @@ private static void ReadAttributeData(ConfigAttributeData data, AttributeData at private static void ReadMetadata(ConfigAttributeData data, ISymbol symbol) { data.Metadata.ClassName = symbol.Name; data.Metadata.FullyQualifiedName = GetFullyQualifiedName(symbol); - data.Metadata.Namespace = data.Metadata.FullyQualifiedName[..^(symbol.Name.Length + 1)]; + data.Metadata.Namespace = + data.Metadata.FullyQualifiedName.Substring(0, data.Metadata.FullyQualifiedName.Length - (symbol.Name.Length + 1)); } } } \ No newline at end of file diff --git a/external/sourcegen/sourcegen.csproj b/external/sourcegen/sourcegen.csproj index abc1e1b..b3c2a3e 100644 --- a/external/sourcegen/sourcegen.csproj +++ b/external/sourcegen/sourcegen.csproj @@ -1,7 +1,7 @@ - netstandard2.1 + netstandard2.0 config-assets.sourcegen ConfigAssets.Sourcegen diff --git a/unity/Assets/Plugins/config-assets.sourcegen.dll b/unity/Assets/Plugins/config-assets.sourcegen.dll index 431e300..6d63ea5 100644 --- a/unity/Assets/Plugins/config-assets.sourcegen.dll +++ b/unity/Assets/Plugins/config-assets.sourcegen.dll @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:afa24fe1536f695e76b79ee0b39fe7a317dd09124777da2b04ee515f8671b088 -size 28672 +oid sha256:7d1f4269f12882b7aff7b635bc2a9edbe10fe0e8c07e9f3870885f57024fda22 +size 30208