From aed38921f1656d40cfe5ed6219f327f668eaa036 Mon Sep 17 00:00:00 2001 From: Andy Gocke Date: Fri, 23 Aug 2024 16:17:10 -0700 Subject: [PATCH 1/2] One more CPM fix --- src/pack/Serde.Pkg.proj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pack/Serde.Pkg.proj b/src/pack/Serde.Pkg.proj index b7354a9..9bce2a9 100644 --- a/src/pack/Serde.Pkg.proj +++ b/src/pack/Serde.Pkg.proj @@ -18,7 +18,7 @@ - + runtime; build; native; contentfiles; analyzers; buildtransitive all From bbfa464ed91bead6f3011f5b461364a7ba5c65a7 Mon Sep 17 00:00:00 2001 From: Andy Gocke Date: Mon, 26 Aug 2024 21:43:40 -0700 Subject: [PATCH 2/2] Fix more package issues and warnings --- Directory.Packages.props | 13 ++++++++----- src/generator/Generator.Deserialize.cs | 2 +- src/generator/Generator.Impl.cs | 6 +++--- src/generator/Generator.Serialize.cs | 2 +- src/generator/HelpersAndUtilities/Utilities.cs | 4 ++++ src/generator/SerdeGenerator.csproj | 1 + src/generator/SerdeInfoGenerator.cs | 4 ++-- src/generator/TypeDeclContext.cs | 2 +- src/generator/Wrappers.cs | 4 ++-- 9 files changed, 23 insertions(+), 15 deletions(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index 8291d76..bbb927f 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -1,25 +1,28 @@ true + true - - - + + - + + + + - \ No newline at end of file + diff --git a/src/generator/Generator.Deserialize.cs b/src/generator/Generator.Deserialize.cs index f18b116..94b38bd 100644 --- a/src/generator/Generator.Deserialize.cs +++ b/src/generator/Generator.Deserialize.cs @@ -95,7 +95,7 @@ private static MethodDeclarationSyntax GenerateEnumDeserializeMethod( throw new InvalidDeserializeValueException($"Unexpected value: {errorName}"); } return index switch { - {{string.Join("," + Environment.NewLine, members + {{string.Join("," + Utilities.NewLine, members .Select((m, i) => $"{i} => {typeSyntax}.{m.Name}")) }}, _ => throw new InvalidDeserializeValueException($"Unexpected index: {index}") }; diff --git a/src/generator/Generator.Impl.cs b/src/generator/Generator.Impl.cs index a948413..38d61bd 100644 --- a/src/generator/Generator.Impl.cs +++ b/src/generator/Generator.Impl.cs @@ -94,10 +94,10 @@ internal static void GenerateImpl( usings: List(new[] { UsingDirective(IdentifierName("System")), UsingDirective(IdentifierName("Serde")) }), attributeLists: default, members: List(new[] { newType })); - tree = tree.NormalizeWhitespace(eol: Environment.NewLine); + tree = tree.NormalizeWhitespace(eol: Utilities.NewLine); context.AddSource(srcName, - Environment.NewLine + "#nullable enable" + Environment.NewLine + tree.ToFullString()); + Utilities.NewLine + "#nullable enable" + Utilities.NewLine + tree.ToFullString()); } internal static (string FileName, string Body) MakePartialDecl( @@ -126,7 +126,7 @@ internal static (string FileName, string Body) MakePartialDecl( newType = typeDeclContext.WrapNewType(newType); - return (srcName, Environment.NewLine + "#nullable enable" + Environment.NewLine + newType); + return (srcName, Utilities.NewLine + "#nullable enable" + Utilities.NewLine + newType); } /// diff --git a/src/generator/Generator.Serialize.cs b/src/generator/Generator.Serialize.cs index b4cc391..12fdc62 100644 --- a/src/generator/Generator.Serialize.cs +++ b/src/generator/Generator.Serialize.cs @@ -45,7 +45,7 @@ internal static (MemberDeclarationSyntax[], BaseListSyntax) GenSerialize( statements.Add(ParseStatement($$""" var index = value switch { - {{string.Join("," + Environment.NewLine, fieldsAndProps + {{string.Join("," + Utilities.NewLine, fieldsAndProps .Select((m, i) => $"{typeSyntax}.{m.Name} => {i}")) }}, var v => throw new InvalidOperationException($"Cannot serialize unnamed enum value '{v}' of enum '{{enumType.Name}}'"), }; diff --git a/src/generator/HelpersAndUtilities/Utilities.cs b/src/generator/HelpersAndUtilities/Utilities.cs index 36cfc3b..ef05f14 100644 --- a/src/generator/HelpersAndUtilities/Utilities.cs +++ b/src/generator/HelpersAndUtilities/Utilities.cs @@ -33,6 +33,10 @@ public static bool IsSorted(this ReadOnlySpan span, IComparer comparer) internal static class Utilities { +#pragma warning disable RS1035 + public static readonly string NewLine = Environment.NewLine; +#pragma warning restore RS1035 + public static T NotNull(this T? value) where T : struct => value!.Value; public static string Concat(this string recv, string other) diff --git a/src/generator/SerdeGenerator.csproj b/src/generator/SerdeGenerator.csproj index 1e91503..39002d9 100644 --- a/src/generator/SerdeGenerator.csproj +++ b/src/generator/SerdeGenerator.csproj @@ -11,6 +11,7 @@ $(DefineConstants);SRCGEN true $(NoWarn);CS1591 + true diff --git a/src/generator/SerdeInfoGenerator.cs b/src/generator/SerdeInfoGenerator.cs index f7f3f55..bbdf7dd 100644 --- a/src/generator/SerdeInfoGenerator.cs +++ b/src/generator/SerdeInfoGenerator.cs @@ -57,7 +57,7 @@ public static void GenerateSerdeInfo( typeString = typeString + "<" + new string(',', receiverType.TypeParameters.Length - 1) + ">"; } - var membersString = string.Join("," + Environment.NewLine, + var membersString = string.Join("," + Utilities.NewLine, SymbolUtilities.GetDataMembers(receiverType, SerdeUsage.Both).SelectNotNull(GetMemberEntry)); List makeArgs = [ $"\"{receiverType.Name}\"", $"typeof({typeString}).GetCustomAttributesData()" ]; @@ -83,7 +83,7 @@ public static void GenerateSerdeInfo( } """); - var argsString = string.Join("," + Environment.NewLine + " ", makeArgs); + var argsString = string.Join("," + Utilities.NewLine + " ", makeArgs); var body = $$""" static global::Serde.ISerdeInfo global::Serde.ISerdeInfoProvider.SerdeInfo { get; } = Serde.SerdeInfo.Make{{makeFuncSuffix}}( diff --git a/src/generator/TypeDeclContext.cs b/src/generator/TypeDeclContext.cs index c1d59a1..8c3dfe2 100644 --- a/src/generator/TypeDeclContext.cs +++ b/src/generator/TypeDeclContext.cs @@ -64,7 +64,7 @@ public string WrapNewType(string newType) } if (NamespaceNames.Count > 0) { - newType = "namespace " + string.Join(".", NamespaceNames) + ";" + Environment.NewLine + newType; + newType = "namespace " + string.Join(".", NamespaceNames) + ";" + Utilities.NewLine + newType; } return newType; diff --git a/src/generator/Wrappers.cs b/src/generator/Wrappers.cs index 2283f36..6e4cbed 100644 --- a/src/generator/Wrappers.cs +++ b/src/generator/Wrappers.cs @@ -53,9 +53,9 @@ readonly partial struct {{wrapperName}} { } usings: default, attributeLists: default, members: List(new[] { newType })); - tree = tree.NormalizeWhitespace(eol: Environment.NewLine); + tree = tree.NormalizeWhitespace(eol: Utilities.NewLine); - context.AddSource(fullWrapperName, Environment.NewLine + tree.ToFullString()); + context.AddSource(fullWrapperName, Utilities.NewLine + tree.ToFullString()); } // If the target is a core type, we can wrap it