Skip to content

Commit

Permalink
downgrade to netstandard2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
caneva20 committed Oct 12, 2024
1 parent e4a037f commit 7d21476
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 18 deletions.
12 changes: 6 additions & 6 deletions external/sourcegen/Generators/EnhancedConfigurationGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public partial class {meta.ClassName} : ScriptableObject {{
if (_instance == null) {{
_instance = Services.ConfigLoader.Load<{meta.ClassName}>(ConfigurationTypes[""{meta.FullyQualifiedName}""]);
}}
return _instance;
}}
}}
Expand All @@ -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();
Expand All @@ -79,10 +79,10 @@ private static IEnumerable<MemberInfo> 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 {
Expand Down
10 changes: 7 additions & 3 deletions external/sourcegen/Generators/SettingsProviderGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {{
Expand All @@ -66,7 +68,9 @@ private static SettingsProvider CreateProvider(AssetMetadata metadata, string na
}

private static string GetKeywords(IReadOnlyCollection<string> 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}\""))}}}";
}
}
}
17 changes: 11 additions & 6 deletions external/sourcegen/Utils/ConfigurationFilter.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using ConfigAssets.Sourcegen.Models;
using Microsoft.CodeAnalysis;
Expand All @@ -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<ClassDeclarationSyntax> classes) {
public static IEnumerable<(ClassDeclarationSyntax @class, ISymbol classSymbol, ConfigAttributeData data)>
FilterProviders(Compilation compilation, IEnumerable<ClassDeclarationSyntax> classes) {
var targetAttribute = compilation.GetType(ConfigAttributeName);

foreach (var @class in classes) {
Expand Down Expand Up @@ -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();
Expand All @@ -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));
}
}
}
2 changes: 1 addition & 1 deletion external/sourcegen/sourcegen.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<TargetFramework>netstandard2.0</TargetFramework>
<AssemblyName>config-assets.sourcegen</AssemblyName>
<RootNamespace>ConfigAssets.Sourcegen</RootNamespace>
</PropertyGroup>
Expand Down
4 changes: 2 additions & 2 deletions unity/Assets/Plugins/config-assets.sourcegen.dll
Git LFS file not shown

0 comments on commit 7d21476

Please sign in to comment.