From 498d13a3683be202e1b1247a3e8ef25396d3e2ce Mon Sep 17 00:00:00 2001 From: Paulo Morgado <470455+paulomorgado@users.noreply.github.com> Date: Fri, 13 Jun 2025 16:49:34 +0100 Subject: [PATCH] Refactor enum handling for improved performance in targets that do not have ReadOnlySpan support. Updated `SourceGenerationHelper` to use `global::System.MemoryExtensions.AsSpan` for string comparisons, enhancing performance and consistency. Removed conditional compilation directives for .NET Core versions, streamlining the codebase. Added a package reference to `System.Memory` version `4.6.3` in the project file. Updated multiple test files in the `EnumGeneratorTests` namespace to align with the new implementation, ensuring valid and efficient tests. Overall, these changes simplify string handling in enum generation and validation. --- .../SourceGenerationHelper.cs | 44 +++-- ...scapades.EnumGenerators.NetStandard.csproj | 1 + ...ExtensionsForFlagsEnum_Params.verified.txt | 38 +++-- ...numExtensionsInChildNamespace.verified.txt | 32 ++-- ...umExtensionsInGlobalNamespace.verified.txt | 32 ++-- ...teEnumExtensionsInNestedClass.verified.txt | 32 ++-- ...eEnumExtensionsWithCustomName.verified.txt | 34 ++-- ...EnumExtensionsWithCustomNames.verified.txt | 56 ++++--- ...ExtensionsWithCustomNamespace.verified.txt | 34 ++-- ...onsWithCustomNamespaceAndName.verified.txt | 32 ++-- ...ExtensionsWithSameDisplayName.verified.txt | 50 +++--- ...lEnumExtensionsWithCustomName.verified.txt | 38 +++-- ...ExtensionsWithCustomNamespace.verified.txt | 38 +++-- ...onsWithCustomNamespaceAndName.verified.txt | 38 +++-- ...ts.CanGenerateForExternalEnum.verified.txt | 56 ++++--- ...nGenerateForExternalFlagsEnum.verified.txt | 56 ++++--- ...erateForMultipleExternalEnums.verified.txt | 154 ++++++++++-------- ...mespaceAndClassNameAreTheSame.verified.txt | 28 ++-- ...rObsoleteEnums_CS0612_Issue97.verified.txt | 32 ++-- ...rObsoleteEnums_CS0618_Issue97.verified.txt | 32 ++-- ...bsoleteMembers_CS0612_Issue97.verified.txt | 32 ++-- ...bsoleteMembers_CS0618_Issue97.verified.txt | 32 ++-- ...QuotesAndSlashesInDescription.verified.txt | 82 +++++----- ...SameNameInDifferentNamespaces.verified.txt | 76 +++++---- ...rceptEnumInDifferentNamespace.verified.txt | 40 +++-- ...nterceptEnumInGlobalNamespace.verified.txt | 38 +++-- ...InterceptExternalEnumToString.verified.txt | 56 ++++--- ...ptorTests.CanInterceptHasFlag.verified.txt | 38 +++-- ...nterceptMultipleEnumsToString.verified.txt | 76 +++++---- ...torTests.CanInterceptToString.verified.txt | 32 ++-- ...InterceptToStringWhenCsharp11.verified.txt | 32 ++-- ...nterceptableAttributeToString.verified.txt | 56 ++++--- ...EnumWithoutInterceptorPackage.verified.txt | 32 ++-- ...eptUsageInStringInterpolation.verified.txt | 32 ++-- ...nterceptUsageWithEnumDirectly.verified.txt | 32 ++-- ...fObsoleteEnums_CS0612_Issue97.verified.txt | 34 ++-- ...fObsoleteEnums_CS0618_Issue97.verified.txt | 32 ++-- ...tEnumMarkedAsNotInterceptable.verified.txt | 76 +++++---- ...lEnumMarkedAsNotInterceptable.verified.txt | 94 ++++++----- ...InterceptToStringWhenDisabled.verified.txt | 32 ++-- ...nterceptToStringWhenOldCsharp.verified.txt | 32 ++-- ...tTests.GeneratesEnumCorrectly.verified.txt | 32 ++-- ...umWithRepeatedValuesCorrectly.verified.txt | 40 +++-- ...s.GeneratesFlagsEnumCorrectly.verified.txt | 32 ++-- 44 files changed, 1166 insertions(+), 781 deletions(-) diff --git a/src/NetEscapades.EnumGenerators/SourceGenerationHelper.cs b/src/NetEscapades.EnumGenerators/SourceGenerationHelper.cs index bd87017..9bd521e 100644 --- a/src/NetEscapades.EnumGenerators/SourceGenerationHelper.cs +++ b/src/NetEscapades.EnumGenerators/SourceGenerationHelper.cs @@ -468,7 +468,6 @@ public static bool IsDefined(string name, bool allowMatchingMetadataAttribute) """ - #if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Returns a boolean telling whether an enum with the given name exists in the enumeration /// @@ -508,10 +507,10 @@ public static bool IsDefined(in global::System.ReadOnlySpan name, bool all sb.Append( """ - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan( """) .Append(SymbolDisplay.FormatLiteral(dn, quote: true)) - .Append(", global::System.StringComparison.Ordinal) => true,"); + .Append("), global::System.StringComparison.Ordinal) => true,"); } } @@ -541,10 +540,10 @@ public static bool IsDefined(in global::System.ReadOnlySpan name, bool all sb.Append( """ - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof( + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof( """).Append(fullyQualifiedName).Append('.') .Append(member.Key) - .Append("), global::System.StringComparison.Ordinal) => true,"); + .Append(")), global::System.StringComparison.Ordinal) => true,"); } sb.Append( @@ -553,7 +552,6 @@ public static bool IsDefined(in global::System.ReadOnlySpan name, bool all _ => false, }; } - #endif """); sb.Append( @@ -949,7 +947,6 @@ private static bool TryParseWithCase( } } - #if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Converts the string representation of the name or numeric value of /// an current when global::System.MemoryExtensions.Equals(current, + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan( """) .Append(SymbolDisplay.FormatLiteral(dn, quote: true)).Append( """ - , global::System.StringComparison.OrdinalIgnoreCase): + ), global::System.StringComparison.OrdinalIgnoreCase): result = """).Append(fullyQualifiedName).Append('.').Append(member.Key).Append( """ @@ -1206,11 +1203,11 @@ private static bool TryParseIgnoreCase( sb.Append( """ - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof( + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof( """).Append(fullyQualifiedName).Append('.') .Append(member.Key).Append( """ - ), global::System.StringComparison.OrdinalIgnoreCase): + )), global::System.StringComparison.OrdinalIgnoreCase): result = """).Append(fullyQualifiedName).Append('.').Append(member.Key).Append( """ @@ -1225,7 +1222,13 @@ private static bool TryParseIgnoreCase( case global::System.ReadOnlySpan current when """).Append(enumToGenerate.UnderlyingType).Append( """ - .TryParse(name, out var numericResult): + .TryParse( + name + #if !NETCOREAPP || NETCOREAPP2_0 || NETCOREAPP1_1 || NETCOREAPP1_0 + + .ToString() + #endif + , out var numericResult): result = ( """).Append(fullyQualifiedName).Append( """ @@ -1267,11 +1270,11 @@ private static bool TryParseWithCase( sb.Append( """ - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan( """) .Append(SymbolDisplay.FormatLiteral(dn, quote: true)).Append( """ - , global::System.StringComparison.Ordinal): + ), global::System.StringComparison.Ordinal): result = """).Append(fullyQualifiedName).Append('.').Append(member.Key).Append( """ @@ -1303,11 +1306,11 @@ private static bool TryParseWithCase( sb.Append( """ - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof( + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof( """).Append(fullyQualifiedName).Append('.') .Append(member.Key).Append( """ - ), global::System.StringComparison.Ordinal): + )), global::System.StringComparison.Ordinal): result = """).Append(fullyQualifiedName).Append('.').Append(member.Key).Append( """ @@ -1322,7 +1325,13 @@ private static bool TryParseWithCase( case global::System.ReadOnlySpan current when """).Append(enumToGenerate.UnderlyingType).Append( """ - .TryParse(name, out var numericResult): + .TryParse( + name + #if !NETCOREAPP || NETCOREAPP2_0 || NETCOREAPP1_1 || NETCOREAPP1_0 + + .ToString() + #endif + , out var numericResult): result = ( """).Append(fullyQualifiedName).Append( """ @@ -1333,7 +1342,6 @@ private static bool TryParseWithCase( return false; } } - #endif """); var orderedNames = GetNamesOrderedByValue(enumToGenerate); diff --git a/tests/NetEscapades.EnumGenerators.NetStandard/NetEscapades.EnumGenerators.NetStandard.csproj b/tests/NetEscapades.EnumGenerators.NetStandard/NetEscapades.EnumGenerators.NetStandard.csproj index 5b2ecdd..794d31a 100644 --- a/tests/NetEscapades.EnumGenerators.NetStandard/NetEscapades.EnumGenerators.NetStandard.csproj +++ b/tests/NetEscapades.EnumGenerators.NetStandard/NetEscapades.EnumGenerators.NetStandard.csproj @@ -18,5 +18,6 @@ + diff --git a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsForFlagsEnum_Params.verified.txt b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsForFlagsEnum_Params.verified.txt index 7023687..cb4be52 100644 --- a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsForFlagsEnum_Params.verified.txt +++ b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsForFlagsEnum_Params.verified.txt @@ -120,7 +120,6 @@ namespace MyTestNameSpace }; } -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Returns a boolean telling whether an enum with the given name exists in the enumeration /// @@ -142,13 +141,12 @@ namespace MyTestNameSpace { return name switch { - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.First), global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Second), global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Third), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.First)), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.Second)), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.Third)), global::System.StringComparison.Ordinal) => true, _ => false, }; } -#endif /// /// Converts the string representation of the name or numeric value of @@ -332,7 +330,6 @@ namespace MyTestNameSpace } } -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Converts the string representation of the name or numeric value of /// an to the equivalent instance. @@ -461,16 +458,22 @@ namespace MyTestNameSpace { switch (name) { - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.First), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.First)), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyTestNameSpace.MyEnum.First; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Second), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.Second)), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyTestNameSpace.MyEnum.Second; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Third), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.Third)), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyTestNameSpace.MyEnum.Third; return true; - case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse( + name +#if !NETCOREAPP || NETCOREAPP2_0 || NETCOREAPP1_1 || NETCOREAPP1_0 + + .ToString() +#endif + , out var numericResult): result = (global::MyTestNameSpace.MyEnum)numericResult; return true; default: @@ -489,16 +492,22 @@ namespace MyTestNameSpace { switch (name) { - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.First), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.First)), global::System.StringComparison.Ordinal): result = global::MyTestNameSpace.MyEnum.First; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Second), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.Second)), global::System.StringComparison.Ordinal): result = global::MyTestNameSpace.MyEnum.Second; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Third), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.Third)), global::System.StringComparison.Ordinal): result = global::MyTestNameSpace.MyEnum.Third; return true; - case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse( + name +#if !NETCOREAPP || NETCOREAPP2_0 || NETCOREAPP1_1 || NETCOREAPP1_0 + + .ToString() +#endif + , out var numericResult): result = (global::MyTestNameSpace.MyEnum)numericResult; return true; default: @@ -506,7 +515,6 @@ namespace MyTestNameSpace return false; } } -#endif /// /// Retrieves an array of the values of the members defined in diff --git a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsInChildNamespace.verified.txt b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsInChildNamespace.verified.txt index 26db5d5..1e10de6 100644 --- a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsInChildNamespace.verified.txt +++ b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsInChildNamespace.verified.txt @@ -105,7 +105,6 @@ namespace MyTestNameSpace }; } -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Returns a boolean telling whether an enum with the given name exists in the enumeration /// @@ -127,12 +126,11 @@ namespace MyTestNameSpace { return name switch { - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.First), global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Second), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.First)), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.Second)), global::System.StringComparison.Ordinal) => true, _ => false, }; } -#endif /// /// Converts the string representation of the name or numeric value of @@ -310,7 +308,6 @@ namespace MyTestNameSpace } } -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Converts the string representation of the name or numeric value of /// an to the equivalent instance. @@ -439,13 +436,19 @@ namespace MyTestNameSpace { switch (name) { - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.First), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.First)), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyTestNameSpace.MyEnum.First; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Second), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.Second)), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyTestNameSpace.MyEnum.Second; return true; - case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse( + name +#if !NETCOREAPP || NETCOREAPP2_0 || NETCOREAPP1_1 || NETCOREAPP1_0 + + .ToString() +#endif + , out var numericResult): result = (global::MyTestNameSpace.MyEnum)numericResult; return true; default: @@ -464,13 +467,19 @@ namespace MyTestNameSpace { switch (name) { - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.First), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.First)), global::System.StringComparison.Ordinal): result = global::MyTestNameSpace.MyEnum.First; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Second), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.Second)), global::System.StringComparison.Ordinal): result = global::MyTestNameSpace.MyEnum.Second; return true; - case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse( + name +#if !NETCOREAPP || NETCOREAPP2_0 || NETCOREAPP1_1 || NETCOREAPP1_0 + + .ToString() +#endif + , out var numericResult): result = (global::MyTestNameSpace.MyEnum)numericResult; return true; default: @@ -478,7 +487,6 @@ namespace MyTestNameSpace return false; } } -#endif /// /// Retrieves an array of the values of the members defined in diff --git a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsInGlobalNamespace.verified.txt b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsInGlobalNamespace.verified.txt index af8f252..fb8c589 100644 --- a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsInGlobalNamespace.verified.txt +++ b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsInGlobalNamespace.verified.txt @@ -103,7 +103,6 @@ }; } -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Returns a boolean telling whether an enum with the given name exists in the enumeration /// @@ -125,12 +124,11 @@ { return name switch { - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyEnum.First), global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyEnum.Second), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyEnum.First)), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyEnum.Second)), global::System.StringComparison.Ordinal) => true, _ => false, }; } -#endif /// /// Converts the string representation of the name or numeric value of @@ -308,7 +306,6 @@ } } -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Converts the string representation of the name or numeric value of /// an to the equivalent instance. @@ -437,13 +434,19 @@ { switch (name) { - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyEnum.First), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyEnum.First)), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyEnum.First; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyEnum.Second), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyEnum.Second)), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyEnum.Second; return true; - case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse( + name +#if !NETCOREAPP || NETCOREAPP2_0 || NETCOREAPP1_1 || NETCOREAPP1_0 + + .ToString() +#endif + , out var numericResult): result = (global::MyEnum)numericResult; return true; default: @@ -462,13 +465,19 @@ { switch (name) { - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyEnum.First), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyEnum.First)), global::System.StringComparison.Ordinal): result = global::MyEnum.First; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyEnum.Second), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyEnum.Second)), global::System.StringComparison.Ordinal): result = global::MyEnum.Second; return true; - case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse( + name +#if !NETCOREAPP || NETCOREAPP2_0 || NETCOREAPP1_1 || NETCOREAPP1_0 + + .ToString() +#endif + , out var numericResult): result = (global::MyEnum)numericResult; return true; default: @@ -476,7 +485,6 @@ return false; } } -#endif /// /// Retrieves an array of the values of the members defined in diff --git a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsInNestedClass.verified.txt b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsInNestedClass.verified.txt index a7fd3b4..cf4228e 100644 --- a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsInNestedClass.verified.txt +++ b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsInNestedClass.verified.txt @@ -105,7 +105,6 @@ namespace MyTestNameSpace }; } -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Returns a boolean telling whether an enum with the given name exists in the enumeration /// @@ -127,12 +126,11 @@ namespace MyTestNameSpace { return name switch { - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.InnerClass.MyEnum.First), global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.InnerClass.MyEnum.Second), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.InnerClass.MyEnum.First)), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.InnerClass.MyEnum.Second)), global::System.StringComparison.Ordinal) => true, _ => false, }; } -#endif /// /// Converts the string representation of the name or numeric value of @@ -310,7 +308,6 @@ namespace MyTestNameSpace } } -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Converts the string representation of the name or numeric value of /// an to the equivalent instance. @@ -439,13 +436,19 @@ namespace MyTestNameSpace { switch (name) { - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.InnerClass.MyEnum.First), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.InnerClass.MyEnum.First)), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyTestNameSpace.InnerClass.MyEnum.First; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.InnerClass.MyEnum.Second), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.InnerClass.MyEnum.Second)), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyTestNameSpace.InnerClass.MyEnum.Second; return true; - case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse( + name +#if !NETCOREAPP || NETCOREAPP2_0 || NETCOREAPP1_1 || NETCOREAPP1_0 + + .ToString() +#endif + , out var numericResult): result = (global::MyTestNameSpace.InnerClass.MyEnum)numericResult; return true; default: @@ -464,13 +467,19 @@ namespace MyTestNameSpace { switch (name) { - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.InnerClass.MyEnum.First), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.InnerClass.MyEnum.First)), global::System.StringComparison.Ordinal): result = global::MyTestNameSpace.InnerClass.MyEnum.First; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.InnerClass.MyEnum.Second), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.InnerClass.MyEnum.Second)), global::System.StringComparison.Ordinal): result = global::MyTestNameSpace.InnerClass.MyEnum.Second; return true; - case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse( + name +#if !NETCOREAPP || NETCOREAPP2_0 || NETCOREAPP1_1 || NETCOREAPP1_0 + + .ToString() +#endif + , out var numericResult): result = (global::MyTestNameSpace.InnerClass.MyEnum)numericResult; return true; default: @@ -478,7 +487,6 @@ namespace MyTestNameSpace return false; } } -#endif /// /// Retrieves an array of the values of the members defined in diff --git a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsWithCustomName.verified.txt b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsWithCustomName.verified.txt index 5dab336..0a0c467 100644 --- a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsWithCustomName.verified.txt +++ b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsWithCustomName.verified.txt @@ -1,4 +1,4 @@ -//------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ // // This code was generated by the NetEscapades.EnumGenerators source generator // @@ -105,7 +105,6 @@ namespace MyTestNameSpace }; } -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Returns a boolean telling whether an enum with the given name exists in the enumeration /// @@ -127,12 +126,11 @@ namespace MyTestNameSpace { return name switch { - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.First), global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Second), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.First)), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.Second)), global::System.StringComparison.Ordinal) => true, _ => false, }; } -#endif /// /// Converts the string representation of the name or numeric value of @@ -310,7 +308,6 @@ namespace MyTestNameSpace } } -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Converts the string representation of the name or numeric value of /// an to the equivalent instance. @@ -439,13 +436,19 @@ namespace MyTestNameSpace { switch (name) { - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.First), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.First)), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyTestNameSpace.MyEnum.First; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Second), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.Second)), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyTestNameSpace.MyEnum.Second; return true; - case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse( + name +#if !NETCOREAPP || NETCOREAPP2_0 || NETCOREAPP1_1 || NETCOREAPP1_0 + + .ToString() +#endif + , out var numericResult): result = (global::MyTestNameSpace.MyEnum)numericResult; return true; default: @@ -464,13 +467,19 @@ namespace MyTestNameSpace { switch (name) { - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.First), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.First)), global::System.StringComparison.Ordinal): result = global::MyTestNameSpace.MyEnum.First; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Second), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.Second)), global::System.StringComparison.Ordinal): result = global::MyTestNameSpace.MyEnum.Second; return true; - case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse( + name +#if !NETCOREAPP || NETCOREAPP2_0 || NETCOREAPP1_1 || NETCOREAPP1_0 + + .ToString() +#endif + , out var numericResult): result = (global::MyTestNameSpace.MyEnum)numericResult; return true; default: @@ -478,7 +487,6 @@ namespace MyTestNameSpace return false; } } -#endif /// /// Retrieves an array of the values of the members defined in diff --git a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsWithCustomNames.verified.txt b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsWithCustomNames.verified.txt index 79fa5fa..9f49325 100644 --- a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsWithCustomNames.verified.txt +++ b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsWithCustomNames.verified.txt @@ -134,7 +134,6 @@ namespace MyTestNameSpace }; } -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Returns a boolean telling whether an enum with the given name exists in the enumeration /// @@ -159,8 +158,8 @@ namespace MyTestNameSpace { isDefinedInDisplayAttribute = name switch { - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, "2nd", global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, "4th", global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan("2nd"), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan("4th"), global::System.StringComparison.Ordinal) => true, _ => false, }; } @@ -172,14 +171,13 @@ namespace MyTestNameSpace return name switch { - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.First), global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Second), global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Third), global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Fourth), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.First)), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.Second)), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.Third)), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.Fourth)), global::System.StringComparison.Ordinal) => true, _ => false, }; } -#endif /// /// Converts the string representation of the name or numeric value of @@ -397,7 +395,6 @@ namespace MyTestNameSpace } } -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Converts the string representation of the name or numeric value of /// an to the equivalent instance. @@ -528,10 +525,10 @@ namespace MyTestNameSpace { switch (name) { - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, "2nd", global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan("2nd"), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyTestNameSpace.MyEnum.Second; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, "4th", global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan("4th"), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyTestNameSpace.MyEnum.Fourth; return true; default: @@ -541,19 +538,25 @@ namespace MyTestNameSpace switch (name) { - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.First), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.First)), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyTestNameSpace.MyEnum.First; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Second), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.Second)), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyTestNameSpace.MyEnum.Second; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Third), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.Third)), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyTestNameSpace.MyEnum.Third; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Fourth), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.Fourth)), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyTestNameSpace.MyEnum.Fourth; return true; - case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse( + name +#if !NETCOREAPP || NETCOREAPP2_0 || NETCOREAPP1_1 || NETCOREAPP1_0 + + .ToString() +#endif + , out var numericResult): result = (global::MyTestNameSpace.MyEnum)numericResult; return true; default: @@ -574,10 +577,10 @@ namespace MyTestNameSpace { switch (name) { - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, "2nd", global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan("2nd"), global::System.StringComparison.Ordinal): result = global::MyTestNameSpace.MyEnum.Second; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, "4th", global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan("4th"), global::System.StringComparison.Ordinal): result = global::MyTestNameSpace.MyEnum.Fourth; return true; default: @@ -587,19 +590,25 @@ namespace MyTestNameSpace switch (name) { - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.First), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.First)), global::System.StringComparison.Ordinal): result = global::MyTestNameSpace.MyEnum.First; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Second), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.Second)), global::System.StringComparison.Ordinal): result = global::MyTestNameSpace.MyEnum.Second; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Third), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.Third)), global::System.StringComparison.Ordinal): result = global::MyTestNameSpace.MyEnum.Third; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Fourth), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.Fourth)), global::System.StringComparison.Ordinal): result = global::MyTestNameSpace.MyEnum.Fourth; return true; - case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse( + name +#if !NETCOREAPP || NETCOREAPP2_0 || NETCOREAPP1_1 || NETCOREAPP1_0 + + .ToString() +#endif + , out var numericResult): result = (global::MyTestNameSpace.MyEnum)numericResult; return true; default: @@ -607,7 +616,6 @@ namespace MyTestNameSpace return false; } } -#endif /// /// Retrieves an array of the values of the members defined in diff --git a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsWithCustomNamespace.verified.txt b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsWithCustomNamespace.verified.txt index f570524..a3e3ceb 100644 --- a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsWithCustomNamespace.verified.txt +++ b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsWithCustomNamespace.verified.txt @@ -1,4 +1,4 @@ -//------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ // // This code was generated by the NetEscapades.EnumGenerators source generator // @@ -105,7 +105,6 @@ namespace A.B }; } -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Returns a boolean telling whether an enum with the given name exists in the enumeration /// @@ -127,12 +126,11 @@ namespace A.B { return name switch { - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.First), global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Second), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.First)), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.Second)), global::System.StringComparison.Ordinal) => true, _ => false, }; } -#endif /// /// Converts the string representation of the name or numeric value of @@ -310,7 +308,6 @@ namespace A.B } } -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Converts the string representation of the name or numeric value of /// an to the equivalent instance. @@ -439,13 +436,19 @@ namespace A.B { switch (name) { - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.First), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.First)), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyTestNameSpace.MyEnum.First; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Second), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.Second)), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyTestNameSpace.MyEnum.Second; return true; - case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse( + name +#if !NETCOREAPP || NETCOREAPP2_0 || NETCOREAPP1_1 || NETCOREAPP1_0 + + .ToString() +#endif + , out var numericResult): result = (global::MyTestNameSpace.MyEnum)numericResult; return true; default: @@ -464,13 +467,19 @@ namespace A.B { switch (name) { - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.First), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.First)), global::System.StringComparison.Ordinal): result = global::MyTestNameSpace.MyEnum.First; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Second), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.Second)), global::System.StringComparison.Ordinal): result = global::MyTestNameSpace.MyEnum.Second; return true; - case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse( + name +#if !NETCOREAPP || NETCOREAPP2_0 || NETCOREAPP1_1 || NETCOREAPP1_0 + + .ToString() +#endif + , out var numericResult): result = (global::MyTestNameSpace.MyEnum)numericResult; return true; default: @@ -478,7 +487,6 @@ namespace A.B return false; } } -#endif /// /// Retrieves an array of the values of the members defined in diff --git a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsWithCustomNamespaceAndName.verified.txt b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsWithCustomNamespaceAndName.verified.txt index fe48913..01d2196 100644 --- a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsWithCustomNamespaceAndName.verified.txt +++ b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsWithCustomNamespaceAndName.verified.txt @@ -105,7 +105,6 @@ namespace A.B }; } -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Returns a boolean telling whether an enum with the given name exists in the enumeration /// @@ -127,12 +126,11 @@ namespace A.B { return name switch { - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.First), global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Second), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.First)), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.Second)), global::System.StringComparison.Ordinal) => true, _ => false, }; } -#endif /// /// Converts the string representation of the name or numeric value of @@ -310,7 +308,6 @@ namespace A.B } } -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Converts the string representation of the name or numeric value of /// an to the equivalent instance. @@ -439,13 +436,19 @@ namespace A.B { switch (name) { - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.First), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.First)), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyTestNameSpace.MyEnum.First; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Second), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.Second)), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyTestNameSpace.MyEnum.Second; return true; - case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse( + name +#if !NETCOREAPP || NETCOREAPP2_0 || NETCOREAPP1_1 || NETCOREAPP1_0 + + .ToString() +#endif + , out var numericResult): result = (global::MyTestNameSpace.MyEnum)numericResult; return true; default: @@ -464,13 +467,19 @@ namespace A.B { switch (name) { - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.First), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.First)), global::System.StringComparison.Ordinal): result = global::MyTestNameSpace.MyEnum.First; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Second), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.Second)), global::System.StringComparison.Ordinal): result = global::MyTestNameSpace.MyEnum.Second; return true; - case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse( + name +#if !NETCOREAPP || NETCOREAPP2_0 || NETCOREAPP1_1 || NETCOREAPP1_0 + + .ToString() +#endif + , out var numericResult): result = (global::MyTestNameSpace.MyEnum)numericResult; return true; default: @@ -478,7 +487,6 @@ namespace A.B return false; } } -#endif /// /// Retrieves an array of the values of the members defined in diff --git a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsWithSameDisplayName.verified.txt b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsWithSameDisplayName.verified.txt index 1dec877..9a2a41d 100644 --- a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsWithSameDisplayName.verified.txt +++ b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsWithSameDisplayName.verified.txt @@ -133,7 +133,6 @@ namespace MyTestNameSpace }; } -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Returns a boolean telling whether an enum with the given name exists in the enumeration /// @@ -158,7 +157,7 @@ namespace MyTestNameSpace { isDefinedInDisplayAttribute = name switch { - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, "2nd", global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan("2nd"), global::System.StringComparison.Ordinal) => true, _ => false, }; } @@ -170,14 +169,13 @@ namespace MyTestNameSpace return name switch { - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.First), global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Second), global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Third), global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Fourth), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.First)), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.Second)), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.Third)), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.Fourth)), global::System.StringComparison.Ordinal) => true, _ => false, }; } -#endif /// /// Converts the string representation of the name or numeric value of @@ -389,7 +387,6 @@ namespace MyTestNameSpace } } -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Converts the string representation of the name or numeric value of /// an to the equivalent instance. @@ -520,7 +517,7 @@ namespace MyTestNameSpace { switch (name) { - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, "2nd", global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan("2nd"), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyTestNameSpace.MyEnum.Second; return true; default: @@ -530,19 +527,25 @@ namespace MyTestNameSpace switch (name) { - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.First), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.First)), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyTestNameSpace.MyEnum.First; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Second), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.Second)), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyTestNameSpace.MyEnum.Second; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Third), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.Third)), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyTestNameSpace.MyEnum.Third; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Fourth), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.Fourth)), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyTestNameSpace.MyEnum.Fourth; return true; - case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse( + name +#if !NETCOREAPP || NETCOREAPP2_0 || NETCOREAPP1_1 || NETCOREAPP1_0 + + .ToString() +#endif + , out var numericResult): result = (global::MyTestNameSpace.MyEnum)numericResult; return true; default: @@ -563,7 +566,7 @@ namespace MyTestNameSpace { switch (name) { - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, "2nd", global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan("2nd"), global::System.StringComparison.Ordinal): result = global::MyTestNameSpace.MyEnum.Second; return true; default: @@ -573,19 +576,25 @@ namespace MyTestNameSpace switch (name) { - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.First), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.First)), global::System.StringComparison.Ordinal): result = global::MyTestNameSpace.MyEnum.First; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Second), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.Second)), global::System.StringComparison.Ordinal): result = global::MyTestNameSpace.MyEnum.Second; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Third), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.Third)), global::System.StringComparison.Ordinal): result = global::MyTestNameSpace.MyEnum.Third; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Fourth), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.Fourth)), global::System.StringComparison.Ordinal): result = global::MyTestNameSpace.MyEnum.Fourth; return true; - case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse( + name +#if !NETCOREAPP || NETCOREAPP2_0 || NETCOREAPP1_1 || NETCOREAPP1_0 + + .ToString() +#endif + , out var numericResult): result = (global::MyTestNameSpace.MyEnum)numericResult; return true; default: @@ -593,7 +602,6 @@ namespace MyTestNameSpace return false; } } -#endif /// /// Retrieves an array of the values of the members defined in diff --git a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateExternalEnumExtensionsWithCustomName.verified.txt b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateExternalEnumExtensionsWithCustomName.verified.txt index f8fe225..70b419f 100644 --- a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateExternalEnumExtensionsWithCustomName.verified.txt +++ b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateExternalEnumExtensionsWithCustomName.verified.txt @@ -108,7 +108,6 @@ namespace System }; } -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Returns a boolean telling whether an enum with the given name exists in the enumeration /// @@ -130,13 +129,12 @@ namespace System { return name switch { - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.DateTimeKind.Unspecified), global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.DateTimeKind.Utc), global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.DateTimeKind.Local), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.DateTimeKind.Unspecified)), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.DateTimeKind.Utc)), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.DateTimeKind.Local)), global::System.StringComparison.Ordinal) => true, _ => false, }; } -#endif /// /// Converts the string representation of the name or numeric value of @@ -320,7 +318,6 @@ namespace System } } -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Converts the string representation of the name or numeric value of /// an to the equivalent instance. @@ -449,16 +446,22 @@ namespace System { switch (name) { - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.DateTimeKind.Unspecified), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.DateTimeKind.Unspecified)), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.DateTimeKind.Unspecified; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.DateTimeKind.Utc), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.DateTimeKind.Utc)), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.DateTimeKind.Utc; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.DateTimeKind.Local), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.DateTimeKind.Local)), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.DateTimeKind.Local; return true; - case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse( + name +#if !NETCOREAPP || NETCOREAPP2_0 || NETCOREAPP1_1 || NETCOREAPP1_0 + + .ToString() +#endif + , out var numericResult): result = (global::System.DateTimeKind)numericResult; return true; default: @@ -477,16 +480,22 @@ namespace System { switch (name) { - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.DateTimeKind.Unspecified), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.DateTimeKind.Unspecified)), global::System.StringComparison.Ordinal): result = global::System.DateTimeKind.Unspecified; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.DateTimeKind.Utc), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.DateTimeKind.Utc)), global::System.StringComparison.Ordinal): result = global::System.DateTimeKind.Utc; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.DateTimeKind.Local), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.DateTimeKind.Local)), global::System.StringComparison.Ordinal): result = global::System.DateTimeKind.Local; return true; - case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse( + name +#if !NETCOREAPP || NETCOREAPP2_0 || NETCOREAPP1_1 || NETCOREAPP1_0 + + .ToString() +#endif + , out var numericResult): result = (global::System.DateTimeKind)numericResult; return true; default: @@ -494,7 +503,6 @@ namespace System return false; } } -#endif /// /// Retrieves an array of the values of the members defined in diff --git a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateExternalEnumExtensionsWithCustomNamespace.verified.txt b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateExternalEnumExtensionsWithCustomNamespace.verified.txt index 3d85a85..da79c43 100644 --- a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateExternalEnumExtensionsWithCustomNamespace.verified.txt +++ b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateExternalEnumExtensionsWithCustomNamespace.verified.txt @@ -108,7 +108,6 @@ namespace A.B }; } -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Returns a boolean telling whether an enum with the given name exists in the enumeration /// @@ -130,13 +129,12 @@ namespace A.B { return name switch { - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.DateTimeKind.Unspecified), global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.DateTimeKind.Utc), global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.DateTimeKind.Local), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.DateTimeKind.Unspecified)), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.DateTimeKind.Utc)), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.DateTimeKind.Local)), global::System.StringComparison.Ordinal) => true, _ => false, }; } -#endif /// /// Converts the string representation of the name or numeric value of @@ -320,7 +318,6 @@ namespace A.B } } -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Converts the string representation of the name or numeric value of /// an to the equivalent instance. @@ -449,16 +446,22 @@ namespace A.B { switch (name) { - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.DateTimeKind.Unspecified), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.DateTimeKind.Unspecified)), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.DateTimeKind.Unspecified; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.DateTimeKind.Utc), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.DateTimeKind.Utc)), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.DateTimeKind.Utc; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.DateTimeKind.Local), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.DateTimeKind.Local)), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.DateTimeKind.Local; return true; - case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse( + name +#if !NETCOREAPP || NETCOREAPP2_0 || NETCOREAPP1_1 || NETCOREAPP1_0 + + .ToString() +#endif + , out var numericResult): result = (global::System.DateTimeKind)numericResult; return true; default: @@ -477,16 +480,22 @@ namespace A.B { switch (name) { - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.DateTimeKind.Unspecified), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.DateTimeKind.Unspecified)), global::System.StringComparison.Ordinal): result = global::System.DateTimeKind.Unspecified; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.DateTimeKind.Utc), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.DateTimeKind.Utc)), global::System.StringComparison.Ordinal): result = global::System.DateTimeKind.Utc; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.DateTimeKind.Local), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.DateTimeKind.Local)), global::System.StringComparison.Ordinal): result = global::System.DateTimeKind.Local; return true; - case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse( + name +#if !NETCOREAPP || NETCOREAPP2_0 || NETCOREAPP1_1 || NETCOREAPP1_0 + + .ToString() +#endif + , out var numericResult): result = (global::System.DateTimeKind)numericResult; return true; default: @@ -494,7 +503,6 @@ namespace A.B return false; } } -#endif /// /// Retrieves an array of the values of the members defined in diff --git a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateExternalEnumExtensionsWithCustomNamespaceAndName.verified.txt b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateExternalEnumExtensionsWithCustomNamespaceAndName.verified.txt index 973e79d..59ff679 100644 --- a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateExternalEnumExtensionsWithCustomNamespaceAndName.verified.txt +++ b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateExternalEnumExtensionsWithCustomNamespaceAndName.verified.txt @@ -108,7 +108,6 @@ namespace A.B }; } -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Returns a boolean telling whether an enum with the given name exists in the enumeration /// @@ -130,13 +129,12 @@ namespace A.B { return name switch { - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.DateTimeKind.Unspecified), global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.DateTimeKind.Utc), global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.DateTimeKind.Local), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.DateTimeKind.Unspecified)), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.DateTimeKind.Utc)), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.DateTimeKind.Local)), global::System.StringComparison.Ordinal) => true, _ => false, }; } -#endif /// /// Converts the string representation of the name or numeric value of @@ -320,7 +318,6 @@ namespace A.B } } -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Converts the string representation of the name or numeric value of /// an to the equivalent instance. @@ -449,16 +446,22 @@ namespace A.B { switch (name) { - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.DateTimeKind.Unspecified), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.DateTimeKind.Unspecified)), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.DateTimeKind.Unspecified; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.DateTimeKind.Utc), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.DateTimeKind.Utc)), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.DateTimeKind.Utc; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.DateTimeKind.Local), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.DateTimeKind.Local)), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.DateTimeKind.Local; return true; - case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse( + name +#if !NETCOREAPP || NETCOREAPP2_0 || NETCOREAPP1_1 || NETCOREAPP1_0 + + .ToString() +#endif + , out var numericResult): result = (global::System.DateTimeKind)numericResult; return true; default: @@ -477,16 +480,22 @@ namespace A.B { switch (name) { - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.DateTimeKind.Unspecified), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.DateTimeKind.Unspecified)), global::System.StringComparison.Ordinal): result = global::System.DateTimeKind.Unspecified; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.DateTimeKind.Utc), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.DateTimeKind.Utc)), global::System.StringComparison.Ordinal): result = global::System.DateTimeKind.Utc; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.DateTimeKind.Local), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.DateTimeKind.Local)), global::System.StringComparison.Ordinal): result = global::System.DateTimeKind.Local; return true; - case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse( + name +#if !NETCOREAPP || NETCOREAPP2_0 || NETCOREAPP1_1 || NETCOREAPP1_0 + + .ToString() +#endif + , out var numericResult): result = (global::System.DateTimeKind)numericResult; return true; default: @@ -494,7 +503,6 @@ namespace A.B return false; } } -#endif /// /// Retrieves an array of the values of the members defined in diff --git a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateForExternalEnum.verified.txt b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateForExternalEnum.verified.txt index 6b27c51..cc2684e 100644 --- a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateForExternalEnum.verified.txt +++ b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateForExternalEnum.verified.txt @@ -117,7 +117,6 @@ namespace System }; } -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Returns a boolean telling whether an enum with the given name exists in the enumeration /// @@ -139,16 +138,15 @@ namespace System { return name switch { - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.CurrentCulture), global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.CurrentCultureIgnoreCase), global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.InvariantCulture), global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.InvariantCultureIgnoreCase), global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.Ordinal), global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.OrdinalIgnoreCase), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.StringComparison.CurrentCulture)), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.StringComparison.CurrentCultureIgnoreCase)), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.StringComparison.InvariantCulture)), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.StringComparison.InvariantCultureIgnoreCase)), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.StringComparison.Ordinal)), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.StringComparison.OrdinalIgnoreCase)), global::System.StringComparison.Ordinal) => true, _ => false, }; } -#endif /// /// Converts the string representation of the name or numeric value of @@ -350,7 +348,6 @@ namespace System } } -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Converts the string representation of the name or numeric value of /// an to the equivalent instance. @@ -479,25 +476,31 @@ namespace System { switch (name) { - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.CurrentCulture), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.StringComparison.CurrentCulture)), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.StringComparison.CurrentCulture; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.CurrentCultureIgnoreCase), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.StringComparison.CurrentCultureIgnoreCase)), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.StringComparison.CurrentCultureIgnoreCase; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.InvariantCulture), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.StringComparison.InvariantCulture)), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.StringComparison.InvariantCulture; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.InvariantCultureIgnoreCase), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.StringComparison.InvariantCultureIgnoreCase)), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.StringComparison.InvariantCultureIgnoreCase; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.Ordinal), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.StringComparison.Ordinal)), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.StringComparison.Ordinal; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.OrdinalIgnoreCase), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.StringComparison.OrdinalIgnoreCase)), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.StringComparison.OrdinalIgnoreCase; return true; - case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse( + name +#if !NETCOREAPP || NETCOREAPP2_0 || NETCOREAPP1_1 || NETCOREAPP1_0 + + .ToString() +#endif + , out var numericResult): result = (global::System.StringComparison)numericResult; return true; default: @@ -516,25 +519,31 @@ namespace System { switch (name) { - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.CurrentCulture), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.StringComparison.CurrentCulture)), global::System.StringComparison.Ordinal): result = global::System.StringComparison.CurrentCulture; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.CurrentCultureIgnoreCase), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.StringComparison.CurrentCultureIgnoreCase)), global::System.StringComparison.Ordinal): result = global::System.StringComparison.CurrentCultureIgnoreCase; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.InvariantCulture), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.StringComparison.InvariantCulture)), global::System.StringComparison.Ordinal): result = global::System.StringComparison.InvariantCulture; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.InvariantCultureIgnoreCase), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.StringComparison.InvariantCultureIgnoreCase)), global::System.StringComparison.Ordinal): result = global::System.StringComparison.InvariantCultureIgnoreCase; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.Ordinal), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.StringComparison.Ordinal)), global::System.StringComparison.Ordinal): result = global::System.StringComparison.Ordinal; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.OrdinalIgnoreCase), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.StringComparison.OrdinalIgnoreCase)), global::System.StringComparison.Ordinal): result = global::System.StringComparison.OrdinalIgnoreCase; return true; - case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse( + name +#if !NETCOREAPP || NETCOREAPP2_0 || NETCOREAPP1_1 || NETCOREAPP1_0 + + .ToString() +#endif + , out var numericResult): result = (global::System.StringComparison)numericResult; return true; default: @@ -542,7 +551,6 @@ namespace System return false; } } -#endif /// /// Retrieves an array of the values of the members defined in diff --git a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateForExternalFlagsEnum.verified.txt b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateForExternalFlagsEnum.verified.txt index f778f85..5f75abc 100644 --- a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateForExternalFlagsEnum.verified.txt +++ b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateForExternalFlagsEnum.verified.txt @@ -129,7 +129,6 @@ namespace System.IO }; } -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Returns a boolean telling whether an enum with the given name exists in the enumeration /// @@ -151,16 +150,15 @@ namespace System.IO { return name switch { - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.IO.FileShare.None), global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.IO.FileShare.Read), global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.IO.FileShare.Write), global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.IO.FileShare.ReadWrite), global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.IO.FileShare.Delete), global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.IO.FileShare.Inheritable), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.IO.FileShare.None)), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.IO.FileShare.Read)), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.IO.FileShare.Write)), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.IO.FileShare.ReadWrite)), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.IO.FileShare.Delete)), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.IO.FileShare.Inheritable)), global::System.StringComparison.Ordinal) => true, _ => false, }; } -#endif /// /// Converts the string representation of the name or numeric value of @@ -362,7 +360,6 @@ namespace System.IO } } -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Converts the string representation of the name or numeric value of /// an to the equivalent instance. @@ -491,25 +488,31 @@ namespace System.IO { switch (name) { - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.IO.FileShare.None), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.IO.FileShare.None)), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.IO.FileShare.None; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.IO.FileShare.Read), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.IO.FileShare.Read)), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.IO.FileShare.Read; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.IO.FileShare.Write), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.IO.FileShare.Write)), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.IO.FileShare.Write; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.IO.FileShare.ReadWrite), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.IO.FileShare.ReadWrite)), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.IO.FileShare.ReadWrite; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.IO.FileShare.Delete), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.IO.FileShare.Delete)), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.IO.FileShare.Delete; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.IO.FileShare.Inheritable), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.IO.FileShare.Inheritable)), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.IO.FileShare.Inheritable; return true; - case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse( + name +#if !NETCOREAPP || NETCOREAPP2_0 || NETCOREAPP1_1 || NETCOREAPP1_0 + + .ToString() +#endif + , out var numericResult): result = (global::System.IO.FileShare)numericResult; return true; default: @@ -528,25 +531,31 @@ namespace System.IO { switch (name) { - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.IO.FileShare.None), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.IO.FileShare.None)), global::System.StringComparison.Ordinal): result = global::System.IO.FileShare.None; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.IO.FileShare.Read), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.IO.FileShare.Read)), global::System.StringComparison.Ordinal): result = global::System.IO.FileShare.Read; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.IO.FileShare.Write), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.IO.FileShare.Write)), global::System.StringComparison.Ordinal): result = global::System.IO.FileShare.Write; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.IO.FileShare.ReadWrite), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.IO.FileShare.ReadWrite)), global::System.StringComparison.Ordinal): result = global::System.IO.FileShare.ReadWrite; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.IO.FileShare.Delete), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.IO.FileShare.Delete)), global::System.StringComparison.Ordinal): result = global::System.IO.FileShare.Delete; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.IO.FileShare.Inheritable), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.IO.FileShare.Inheritable)), global::System.StringComparison.Ordinal): result = global::System.IO.FileShare.Inheritable; return true; - case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse( + name +#if !NETCOREAPP || NETCOREAPP2_0 || NETCOREAPP1_1 || NETCOREAPP1_0 + + .ToString() +#endif + , out var numericResult): result = (global::System.IO.FileShare)numericResult; return true; default: @@ -554,7 +563,6 @@ namespace System.IO return false; } } -#endif /// /// Retrieves an array of the values of the members defined in diff --git a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateForMultipleExternalEnums.verified.txt b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateForMultipleExternalEnums.verified.txt index 577e496..bef57e8 100644 --- a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateForMultipleExternalEnums.verified.txt +++ b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateForMultipleExternalEnums.verified.txt @@ -148,7 +148,6 @@ namespace System }; } -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Returns a boolean telling whether an enum with the given name exists in the enumeration /// @@ -170,26 +169,25 @@ namespace System { return name switch { - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.ConsoleColor.Black), global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.ConsoleColor.DarkBlue), global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.ConsoleColor.DarkGreen), global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.ConsoleColor.DarkCyan), global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.ConsoleColor.DarkRed), global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.ConsoleColor.DarkMagenta), global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.ConsoleColor.DarkYellow), global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.ConsoleColor.Gray), global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.ConsoleColor.DarkGray), global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.ConsoleColor.Blue), global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.ConsoleColor.Green), global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.ConsoleColor.Cyan), global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.ConsoleColor.Red), global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.ConsoleColor.Magenta), global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.ConsoleColor.Yellow), global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.ConsoleColor.White), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.ConsoleColor.Black)), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.ConsoleColor.DarkBlue)), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.ConsoleColor.DarkGreen)), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.ConsoleColor.DarkCyan)), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.ConsoleColor.DarkRed)), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.ConsoleColor.DarkMagenta)), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.ConsoleColor.DarkYellow)), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.ConsoleColor.Gray)), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.ConsoleColor.DarkGray)), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.ConsoleColor.Blue)), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.ConsoleColor.Green)), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.ConsoleColor.Cyan)), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.ConsoleColor.Red)), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.ConsoleColor.Magenta)), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.ConsoleColor.Yellow)), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.ConsoleColor.White)), global::System.StringComparison.Ordinal) => true, _ => false, }; } -#endif /// /// Converts the string representation of the name or numeric value of @@ -451,7 +449,6 @@ namespace System } } -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Converts the string representation of the name or numeric value of /// an to the equivalent instance. @@ -580,55 +577,61 @@ namespace System { switch (name) { - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.ConsoleColor.Black), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.ConsoleColor.Black)), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.ConsoleColor.Black; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.ConsoleColor.DarkBlue), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.ConsoleColor.DarkBlue)), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.ConsoleColor.DarkBlue; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.ConsoleColor.DarkGreen), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.ConsoleColor.DarkGreen)), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.ConsoleColor.DarkGreen; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.ConsoleColor.DarkCyan), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.ConsoleColor.DarkCyan)), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.ConsoleColor.DarkCyan; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.ConsoleColor.DarkRed), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.ConsoleColor.DarkRed)), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.ConsoleColor.DarkRed; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.ConsoleColor.DarkMagenta), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.ConsoleColor.DarkMagenta)), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.ConsoleColor.DarkMagenta; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.ConsoleColor.DarkYellow), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.ConsoleColor.DarkYellow)), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.ConsoleColor.DarkYellow; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.ConsoleColor.Gray), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.ConsoleColor.Gray)), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.ConsoleColor.Gray; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.ConsoleColor.DarkGray), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.ConsoleColor.DarkGray)), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.ConsoleColor.DarkGray; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.ConsoleColor.Blue), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.ConsoleColor.Blue)), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.ConsoleColor.Blue; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.ConsoleColor.Green), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.ConsoleColor.Green)), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.ConsoleColor.Green; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.ConsoleColor.Cyan), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.ConsoleColor.Cyan)), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.ConsoleColor.Cyan; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.ConsoleColor.Red), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.ConsoleColor.Red)), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.ConsoleColor.Red; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.ConsoleColor.Magenta), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.ConsoleColor.Magenta)), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.ConsoleColor.Magenta; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.ConsoleColor.Yellow), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.ConsoleColor.Yellow)), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.ConsoleColor.Yellow; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.ConsoleColor.White), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.ConsoleColor.White)), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.ConsoleColor.White; return true; - case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse( + name +#if !NETCOREAPP || NETCOREAPP2_0 || NETCOREAPP1_1 || NETCOREAPP1_0 + + .ToString() +#endif + , out var numericResult): result = (global::System.ConsoleColor)numericResult; return true; default: @@ -647,55 +650,61 @@ namespace System { switch (name) { - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.ConsoleColor.Black), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.ConsoleColor.Black)), global::System.StringComparison.Ordinal): result = global::System.ConsoleColor.Black; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.ConsoleColor.DarkBlue), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.ConsoleColor.DarkBlue)), global::System.StringComparison.Ordinal): result = global::System.ConsoleColor.DarkBlue; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.ConsoleColor.DarkGreen), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.ConsoleColor.DarkGreen)), global::System.StringComparison.Ordinal): result = global::System.ConsoleColor.DarkGreen; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.ConsoleColor.DarkCyan), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.ConsoleColor.DarkCyan)), global::System.StringComparison.Ordinal): result = global::System.ConsoleColor.DarkCyan; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.ConsoleColor.DarkRed), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.ConsoleColor.DarkRed)), global::System.StringComparison.Ordinal): result = global::System.ConsoleColor.DarkRed; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.ConsoleColor.DarkMagenta), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.ConsoleColor.DarkMagenta)), global::System.StringComparison.Ordinal): result = global::System.ConsoleColor.DarkMagenta; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.ConsoleColor.DarkYellow), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.ConsoleColor.DarkYellow)), global::System.StringComparison.Ordinal): result = global::System.ConsoleColor.DarkYellow; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.ConsoleColor.Gray), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.ConsoleColor.Gray)), global::System.StringComparison.Ordinal): result = global::System.ConsoleColor.Gray; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.ConsoleColor.DarkGray), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.ConsoleColor.DarkGray)), global::System.StringComparison.Ordinal): result = global::System.ConsoleColor.DarkGray; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.ConsoleColor.Blue), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.ConsoleColor.Blue)), global::System.StringComparison.Ordinal): result = global::System.ConsoleColor.Blue; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.ConsoleColor.Green), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.ConsoleColor.Green)), global::System.StringComparison.Ordinal): result = global::System.ConsoleColor.Green; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.ConsoleColor.Cyan), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.ConsoleColor.Cyan)), global::System.StringComparison.Ordinal): result = global::System.ConsoleColor.Cyan; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.ConsoleColor.Red), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.ConsoleColor.Red)), global::System.StringComparison.Ordinal): result = global::System.ConsoleColor.Red; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.ConsoleColor.Magenta), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.ConsoleColor.Magenta)), global::System.StringComparison.Ordinal): result = global::System.ConsoleColor.Magenta; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.ConsoleColor.Yellow), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.ConsoleColor.Yellow)), global::System.StringComparison.Ordinal): result = global::System.ConsoleColor.Yellow; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.ConsoleColor.White), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.ConsoleColor.White)), global::System.StringComparison.Ordinal): result = global::System.ConsoleColor.White; return true; - case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse( + name +#if !NETCOREAPP || NETCOREAPP2_0 || NETCOREAPP1_1 || NETCOREAPP1_0 + + .ToString() +#endif + , out var numericResult): result = (global::System.ConsoleColor)numericResult; return true; default: @@ -703,7 +712,6 @@ namespace System return false; } } -#endif /// /// Retrieves an array of the values of the members defined in @@ -909,7 +917,6 @@ namespace System }; } -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Returns a boolean telling whether an enum with the given name exists in the enumeration /// @@ -931,13 +938,12 @@ namespace System { return name switch { - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.DateTimeKind.Unspecified), global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.DateTimeKind.Utc), global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.DateTimeKind.Local), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.DateTimeKind.Unspecified)), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.DateTimeKind.Utc)), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.DateTimeKind.Local)), global::System.StringComparison.Ordinal) => true, _ => false, }; } -#endif /// /// Converts the string representation of the name or numeric value of @@ -1121,7 +1127,6 @@ namespace System } } -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Converts the string representation of the name or numeric value of /// an to the equivalent instance. @@ -1250,16 +1255,22 @@ namespace System { switch (name) { - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.DateTimeKind.Unspecified), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.DateTimeKind.Unspecified)), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.DateTimeKind.Unspecified; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.DateTimeKind.Utc), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.DateTimeKind.Utc)), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.DateTimeKind.Utc; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.DateTimeKind.Local), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.DateTimeKind.Local)), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.DateTimeKind.Local; return true; - case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse( + name +#if !NETCOREAPP || NETCOREAPP2_0 || NETCOREAPP1_1 || NETCOREAPP1_0 + + .ToString() +#endif + , out var numericResult): result = (global::System.DateTimeKind)numericResult; return true; default: @@ -1278,16 +1289,22 @@ namespace System { switch (name) { - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.DateTimeKind.Unspecified), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.DateTimeKind.Unspecified)), global::System.StringComparison.Ordinal): result = global::System.DateTimeKind.Unspecified; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.DateTimeKind.Utc), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.DateTimeKind.Utc)), global::System.StringComparison.Ordinal): result = global::System.DateTimeKind.Utc; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.DateTimeKind.Local), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.DateTimeKind.Local)), global::System.StringComparison.Ordinal): result = global::System.DateTimeKind.Local; return true; - case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse( + name +#if !NETCOREAPP || NETCOREAPP2_0 || NETCOREAPP1_1 || NETCOREAPP1_0 + + .ToString() +#endif + , out var numericResult): result = (global::System.DateTimeKind)numericResult; return true; default: @@ -1295,7 +1312,6 @@ namespace System return false; } } -#endif /// /// Retrieves an array of the values of the members defined in diff --git a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanHandleNamespaceAndClassNameAreTheSame.verified.txt b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanHandleNamespaceAndClassNameAreTheSame.verified.txt index 825f89c..014745d 100644 --- a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanHandleNamespaceAndClassNameAreTheSame.verified.txt +++ b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanHandleNamespaceAndClassNameAreTheSame.verified.txt @@ -1,4 +1,4 @@ -//------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ // // This code was generated by the NetEscapades.EnumGenerators source generator // @@ -102,7 +102,6 @@ namespace Foo }; } -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Returns a boolean telling whether an enum with the given name exists in the enumeration /// @@ -124,11 +123,10 @@ namespace Foo { return name switch { - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::Foo.TestEnum.Value1), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::Foo.TestEnum.Value1)), global::System.StringComparison.Ordinal) => true, _ => false, }; } -#endif /// /// Converts the string representation of the name or numeric value of @@ -300,7 +298,6 @@ namespace Foo } } -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Converts the string representation of the name or numeric value of /// an to the equivalent instance. @@ -429,10 +426,16 @@ namespace Foo { switch (name) { - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::Foo.TestEnum.Value1), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::Foo.TestEnum.Value1)), global::System.StringComparison.OrdinalIgnoreCase): result = global::Foo.TestEnum.Value1; return true; - case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse( + name +#if !NETCOREAPP || NETCOREAPP2_0 || NETCOREAPP1_1 || NETCOREAPP1_0 + + .ToString() +#endif + , out var numericResult): result = (global::Foo.TestEnum)numericResult; return true; default: @@ -451,10 +454,16 @@ namespace Foo { switch (name) { - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::Foo.TestEnum.Value1), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::Foo.TestEnum.Value1)), global::System.StringComparison.Ordinal): result = global::Foo.TestEnum.Value1; return true; - case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse( + name +#if !NETCOREAPP || NETCOREAPP2_0 || NETCOREAPP1_1 || NETCOREAPP1_0 + + .ToString() +#endif + , out var numericResult): result = (global::Foo.TestEnum)numericResult; return true; default: @@ -462,7 +471,6 @@ namespace Foo return false; } } -#endif /// /// Retrieves an array of the values of the members defined in diff --git a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.DoesNotGenerateWarningsForObsoleteEnums_CS0612_Issue97.verified.txt b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.DoesNotGenerateWarningsForObsoleteEnums_CS0612_Issue97.verified.txt index 0be1be2..8c49eac 100644 --- a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.DoesNotGenerateWarningsForObsoleteEnums_CS0612_Issue97.verified.txt +++ b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.DoesNotGenerateWarningsForObsoleteEnums_CS0612_Issue97.verified.txt @@ -103,7 +103,6 @@ }; } -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Returns a boolean telling whether an enum with the given name exists in the enumeration /// @@ -125,12 +124,11 @@ { return name switch { - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyEnum.First), global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyEnum.Second), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyEnum.First)), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyEnum.Second)), global::System.StringComparison.Ordinal) => true, _ => false, }; } -#endif /// /// Converts the string representation of the name or numeric value of @@ -308,7 +306,6 @@ } } -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Converts the string representation of the name or numeric value of /// an to the equivalent instance. @@ -437,13 +434,19 @@ { switch (name) { - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyEnum.First), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyEnum.First)), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyEnum.First; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyEnum.Second), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyEnum.Second)), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyEnum.Second; return true; - case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse( + name +#if !NETCOREAPP || NETCOREAPP2_0 || NETCOREAPP1_1 || NETCOREAPP1_0 + + .ToString() +#endif + , out var numericResult): result = (global::MyEnum)numericResult; return true; default: @@ -462,13 +465,19 @@ { switch (name) { - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyEnum.First), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyEnum.First)), global::System.StringComparison.Ordinal): result = global::MyEnum.First; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyEnum.Second), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyEnum.Second)), global::System.StringComparison.Ordinal): result = global::MyEnum.Second; return true; - case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse( + name +#if !NETCOREAPP || NETCOREAPP2_0 || NETCOREAPP1_1 || NETCOREAPP1_0 + + .ToString() +#endif + , out var numericResult): result = (global::MyEnum)numericResult; return true; default: @@ -476,7 +485,6 @@ return false; } } -#endif /// /// Retrieves an array of the values of the members defined in diff --git a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.DoesNotGenerateWarningsForObsoleteEnums_CS0618_Issue97.verified.txt b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.DoesNotGenerateWarningsForObsoleteEnums_CS0618_Issue97.verified.txt index 0be1be2..8c49eac 100644 --- a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.DoesNotGenerateWarningsForObsoleteEnums_CS0618_Issue97.verified.txt +++ b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.DoesNotGenerateWarningsForObsoleteEnums_CS0618_Issue97.verified.txt @@ -103,7 +103,6 @@ }; } -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Returns a boolean telling whether an enum with the given name exists in the enumeration /// @@ -125,12 +124,11 @@ { return name switch { - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyEnum.First), global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyEnum.Second), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyEnum.First)), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyEnum.Second)), global::System.StringComparison.Ordinal) => true, _ => false, }; } -#endif /// /// Converts the string representation of the name or numeric value of @@ -308,7 +306,6 @@ } } -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Converts the string representation of the name or numeric value of /// an to the equivalent instance. @@ -437,13 +434,19 @@ { switch (name) { - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyEnum.First), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyEnum.First)), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyEnum.First; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyEnum.Second), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyEnum.Second)), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyEnum.Second; return true; - case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse( + name +#if !NETCOREAPP || NETCOREAPP2_0 || NETCOREAPP1_1 || NETCOREAPP1_0 + + .ToString() +#endif + , out var numericResult): result = (global::MyEnum)numericResult; return true; default: @@ -462,13 +465,19 @@ { switch (name) { - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyEnum.First), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyEnum.First)), global::System.StringComparison.Ordinal): result = global::MyEnum.First; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyEnum.Second), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyEnum.Second)), global::System.StringComparison.Ordinal): result = global::MyEnum.Second; return true; - case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse( + name +#if !NETCOREAPP || NETCOREAPP2_0 || NETCOREAPP1_1 || NETCOREAPP1_0 + + .ToString() +#endif + , out var numericResult): result = (global::MyEnum)numericResult; return true; default: @@ -476,7 +485,6 @@ return false; } } -#endif /// /// Retrieves an array of the values of the members defined in diff --git a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.DoesNotGenerateWarningsForObsoleteMembers_CS0612_Issue97.verified.txt b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.DoesNotGenerateWarningsForObsoleteMembers_CS0612_Issue97.verified.txt index 0be1be2..8c49eac 100644 --- a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.DoesNotGenerateWarningsForObsoleteMembers_CS0612_Issue97.verified.txt +++ b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.DoesNotGenerateWarningsForObsoleteMembers_CS0612_Issue97.verified.txt @@ -103,7 +103,6 @@ }; } -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Returns a boolean telling whether an enum with the given name exists in the enumeration /// @@ -125,12 +124,11 @@ { return name switch { - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyEnum.First), global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyEnum.Second), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyEnum.First)), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyEnum.Second)), global::System.StringComparison.Ordinal) => true, _ => false, }; } -#endif /// /// Converts the string representation of the name or numeric value of @@ -308,7 +306,6 @@ } } -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Converts the string representation of the name or numeric value of /// an to the equivalent instance. @@ -437,13 +434,19 @@ { switch (name) { - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyEnum.First), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyEnum.First)), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyEnum.First; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyEnum.Second), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyEnum.Second)), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyEnum.Second; return true; - case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse( + name +#if !NETCOREAPP || NETCOREAPP2_0 || NETCOREAPP1_1 || NETCOREAPP1_0 + + .ToString() +#endif + , out var numericResult): result = (global::MyEnum)numericResult; return true; default: @@ -462,13 +465,19 @@ { switch (name) { - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyEnum.First), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyEnum.First)), global::System.StringComparison.Ordinal): result = global::MyEnum.First; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyEnum.Second), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyEnum.Second)), global::System.StringComparison.Ordinal): result = global::MyEnum.Second; return true; - case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse( + name +#if !NETCOREAPP || NETCOREAPP2_0 || NETCOREAPP1_1 || NETCOREAPP1_0 + + .ToString() +#endif + , out var numericResult): result = (global::MyEnum)numericResult; return true; default: @@ -476,7 +485,6 @@ return false; } } -#endif /// /// Retrieves an array of the values of the members defined in diff --git a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.DoesNotGenerateWarningsForObsoleteMembers_CS0618_Issue97.verified.txt b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.DoesNotGenerateWarningsForObsoleteMembers_CS0618_Issue97.verified.txt index 0be1be2..8c49eac 100644 --- a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.DoesNotGenerateWarningsForObsoleteMembers_CS0618_Issue97.verified.txt +++ b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.DoesNotGenerateWarningsForObsoleteMembers_CS0618_Issue97.verified.txt @@ -103,7 +103,6 @@ }; } -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Returns a boolean telling whether an enum with the given name exists in the enumeration /// @@ -125,12 +124,11 @@ { return name switch { - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyEnum.First), global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyEnum.Second), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyEnum.First)), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyEnum.Second)), global::System.StringComparison.Ordinal) => true, _ => false, }; } -#endif /// /// Converts the string representation of the name or numeric value of @@ -308,7 +306,6 @@ } } -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Converts the string representation of the name or numeric value of /// an to the equivalent instance. @@ -437,13 +434,19 @@ { switch (name) { - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyEnum.First), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyEnum.First)), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyEnum.First; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyEnum.Second), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyEnum.Second)), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyEnum.Second; return true; - case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse( + name +#if !NETCOREAPP || NETCOREAPP2_0 || NETCOREAPP1_1 || NETCOREAPP1_0 + + .ToString() +#endif + , out var numericResult): result = (global::MyEnum)numericResult; return true; default: @@ -462,13 +465,19 @@ { switch (name) { - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyEnum.First), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyEnum.First)), global::System.StringComparison.Ordinal): result = global::MyEnum.First; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyEnum.Second), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyEnum.Second)), global::System.StringComparison.Ordinal): result = global::MyEnum.Second; return true; - case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse( + name +#if !NETCOREAPP || NETCOREAPP2_0 || NETCOREAPP1_1 || NETCOREAPP1_0 + + .ToString() +#endif + , out var numericResult): result = (global::MyEnum)numericResult; return true; default: @@ -476,7 +485,6 @@ return false; } } -#endif /// /// Retrieves an array of the values of the members defined in diff --git a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.HandlesStringsWithQuotesAndSlashesInDescription.verified.txt b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.HandlesStringsWithQuotesAndSlashesInDescription.verified.txt index ae8e383..ec231cc 100644 --- a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.HandlesStringsWithQuotesAndSlashesInDescription.verified.txt +++ b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.HandlesStringsWithQuotesAndSlashesInDescription.verified.txt @@ -1,4 +1,4 @@ -//------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ // // This code was generated by the NetEscapades.EnumGenerators source generator // @@ -141,7 +141,6 @@ namespace Test }; } -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Returns a boolean telling whether an enum with the given name exists in the enumeration /// @@ -166,11 +165,11 @@ namespace Test { isDefinedInDisplayAttribute = name switch { - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, "Quotes \"", global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, "Literal Quotes \"", global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, "Backslash \\", global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, "LiteralBackslash \\", global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, "New\nLine", global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan("Quotes \""), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan("Literal Quotes \""), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan("Backslash \\"), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan("LiteralBackslash \\"), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan("New\nLine"), global::System.StringComparison.Ordinal) => true, _ => false, }; } @@ -182,15 +181,14 @@ namespace Test return name switch { - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::Test.StringTesting.Quotes), global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::Test.StringTesting.LiteralQuotes), global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::Test.StringTesting.Backslash), global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::Test.StringTesting.BackslashLiteral), global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::Test.StringTesting.NewLine), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::Test.StringTesting.Quotes)), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::Test.StringTesting.LiteralQuotes)), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::Test.StringTesting.Backslash)), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::Test.StringTesting.BackslashLiteral)), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::Test.StringTesting.NewLine)), global::System.StringComparison.Ordinal) => true, _ => false, }; } -#endif /// /// Converts the string representation of the name or numeric value of @@ -432,7 +430,6 @@ namespace Test } } -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Converts the string representation of the name or numeric value of /// an to the equivalent instance. @@ -563,19 +560,19 @@ namespace Test { switch (name) { - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, "Quotes \"", global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan("Quotes \""), global::System.StringComparison.OrdinalIgnoreCase): result = global::Test.StringTesting.Quotes; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, "Literal Quotes \"", global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan("Literal Quotes \""), global::System.StringComparison.OrdinalIgnoreCase): result = global::Test.StringTesting.LiteralQuotes; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, "Backslash \\", global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan("Backslash \\"), global::System.StringComparison.OrdinalIgnoreCase): result = global::Test.StringTesting.Backslash; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, "LiteralBackslash \\", global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan("LiteralBackslash \\"), global::System.StringComparison.OrdinalIgnoreCase): result = global::Test.StringTesting.BackslashLiteral; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, "New\nLine", global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan("New\nLine"), global::System.StringComparison.OrdinalIgnoreCase): result = global::Test.StringTesting.NewLine; return true; default: @@ -585,22 +582,28 @@ namespace Test switch (name) { - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::Test.StringTesting.Quotes), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::Test.StringTesting.Quotes)), global::System.StringComparison.OrdinalIgnoreCase): result = global::Test.StringTesting.Quotes; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::Test.StringTesting.LiteralQuotes), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::Test.StringTesting.LiteralQuotes)), global::System.StringComparison.OrdinalIgnoreCase): result = global::Test.StringTesting.LiteralQuotes; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::Test.StringTesting.Backslash), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::Test.StringTesting.Backslash)), global::System.StringComparison.OrdinalIgnoreCase): result = global::Test.StringTesting.Backslash; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::Test.StringTesting.BackslashLiteral), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::Test.StringTesting.BackslashLiteral)), global::System.StringComparison.OrdinalIgnoreCase): result = global::Test.StringTesting.BackslashLiteral; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::Test.StringTesting.NewLine), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::Test.StringTesting.NewLine)), global::System.StringComparison.OrdinalIgnoreCase): result = global::Test.StringTesting.NewLine; return true; - case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse( + name +#if !NETCOREAPP || NETCOREAPP2_0 || NETCOREAPP1_1 || NETCOREAPP1_0 + + .ToString() +#endif + , out var numericResult): result = (global::Test.StringTesting)numericResult; return true; default: @@ -621,19 +624,19 @@ namespace Test { switch (name) { - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, "Quotes \"", global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan("Quotes \""), global::System.StringComparison.Ordinal): result = global::Test.StringTesting.Quotes; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, "Literal Quotes \"", global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan("Literal Quotes \""), global::System.StringComparison.Ordinal): result = global::Test.StringTesting.LiteralQuotes; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, "Backslash \\", global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan("Backslash \\"), global::System.StringComparison.Ordinal): result = global::Test.StringTesting.Backslash; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, "LiteralBackslash \\", global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan("LiteralBackslash \\"), global::System.StringComparison.Ordinal): result = global::Test.StringTesting.BackslashLiteral; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, "New\nLine", global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan("New\nLine"), global::System.StringComparison.Ordinal): result = global::Test.StringTesting.NewLine; return true; default: @@ -643,22 +646,28 @@ namespace Test switch (name) { - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::Test.StringTesting.Quotes), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::Test.StringTesting.Quotes)), global::System.StringComparison.Ordinal): result = global::Test.StringTesting.Quotes; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::Test.StringTesting.LiteralQuotes), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::Test.StringTesting.LiteralQuotes)), global::System.StringComparison.Ordinal): result = global::Test.StringTesting.LiteralQuotes; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::Test.StringTesting.Backslash), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::Test.StringTesting.Backslash)), global::System.StringComparison.Ordinal): result = global::Test.StringTesting.Backslash; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::Test.StringTesting.BackslashLiteral), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::Test.StringTesting.BackslashLiteral)), global::System.StringComparison.Ordinal): result = global::Test.StringTesting.BackslashLiteral; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::Test.StringTesting.NewLine), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::Test.StringTesting.NewLine)), global::System.StringComparison.Ordinal): result = global::Test.StringTesting.NewLine; return true; - case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse( + name +#if !NETCOREAPP || NETCOREAPP2_0 || NETCOREAPP1_1 || NETCOREAPP1_0 + + .ToString() +#endif + , out var numericResult): result = (global::Test.StringTesting)numericResult; return true; default: @@ -666,7 +675,6 @@ namespace Test return false; } } -#endif /// /// Retrieves an array of the values of the members defined in diff --git a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.CanHandleEnumsWithSameNameInDifferentNamespaces.verified.txt b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.CanHandleEnumsWithSameNameInDifferentNamespaces.verified.txt index 7e08c84..a12d826 100644 --- a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.CanHandleEnumsWithSameNameInDifferentNamespaces.verified.txt +++ b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.CanHandleEnumsWithSameNameInDifferentNamespaces.verified.txt @@ -209,7 +209,6 @@ namespace Foo }; } -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Returns a boolean telling whether an enum with the given name exists in the enumeration /// @@ -231,13 +230,12 @@ namespace Foo { return name switch { - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::Foo.MyEnum.First), global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::Foo.MyEnum.Second), global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::Foo.MyEnum.Third), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::Foo.MyEnum.First)), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::Foo.MyEnum.Second)), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::Foo.MyEnum.Third)), global::System.StringComparison.Ordinal) => true, _ => false, }; } -#endif /// /// Converts the string representation of the name or numeric value of @@ -421,7 +419,6 @@ namespace Foo } } -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Converts the string representation of the name or numeric value of /// an to the equivalent instance. @@ -550,16 +547,22 @@ namespace Foo { switch (name) { - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::Foo.MyEnum.First), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::Foo.MyEnum.First)), global::System.StringComparison.OrdinalIgnoreCase): result = global::Foo.MyEnum.First; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::Foo.MyEnum.Second), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::Foo.MyEnum.Second)), global::System.StringComparison.OrdinalIgnoreCase): result = global::Foo.MyEnum.Second; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::Foo.MyEnum.Third), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::Foo.MyEnum.Third)), global::System.StringComparison.OrdinalIgnoreCase): result = global::Foo.MyEnum.Third; return true; - case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse( + name +#if !NETCOREAPP || NETCOREAPP2_0 || NETCOREAPP1_1 || NETCOREAPP1_0 + + .ToString() +#endif + , out var numericResult): result = (global::Foo.MyEnum)numericResult; return true; default: @@ -578,16 +581,22 @@ namespace Foo { switch (name) { - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::Foo.MyEnum.First), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::Foo.MyEnum.First)), global::System.StringComparison.Ordinal): result = global::Foo.MyEnum.First; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::Foo.MyEnum.Second), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::Foo.MyEnum.Second)), global::System.StringComparison.Ordinal): result = global::Foo.MyEnum.Second; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::Foo.MyEnum.Third), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::Foo.MyEnum.Third)), global::System.StringComparison.Ordinal): result = global::Foo.MyEnum.Third; return true; - case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse( + name +#if !NETCOREAPP || NETCOREAPP2_0 || NETCOREAPP1_1 || NETCOREAPP1_0 + + .ToString() +#endif + , out var numericResult): result = (global::Foo.MyEnum)numericResult; return true; default: @@ -595,7 +604,6 @@ namespace Foo return false; } } -#endif /// /// Retrieves an array of the values of the members defined in @@ -774,7 +782,6 @@ namespace Bar }; } -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Returns a boolean telling whether an enum with the given name exists in the enumeration /// @@ -796,13 +803,12 @@ namespace Bar { return name switch { - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::Bar.MyEnum.First), global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::Bar.MyEnum.Second), global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::Bar.MyEnum.Third), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::Bar.MyEnum.First)), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::Bar.MyEnum.Second)), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::Bar.MyEnum.Third)), global::System.StringComparison.Ordinal) => true, _ => false, }; } -#endif /// /// Converts the string representation of the name or numeric value of @@ -986,7 +992,6 @@ namespace Bar } } -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Converts the string representation of the name or numeric value of /// an to the equivalent instance. @@ -1115,16 +1120,22 @@ namespace Bar { switch (name) { - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::Bar.MyEnum.First), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::Bar.MyEnum.First)), global::System.StringComparison.OrdinalIgnoreCase): result = global::Bar.MyEnum.First; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::Bar.MyEnum.Second), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::Bar.MyEnum.Second)), global::System.StringComparison.OrdinalIgnoreCase): result = global::Bar.MyEnum.Second; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::Bar.MyEnum.Third), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::Bar.MyEnum.Third)), global::System.StringComparison.OrdinalIgnoreCase): result = global::Bar.MyEnum.Third; return true; - case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse( + name +#if !NETCOREAPP || NETCOREAPP2_0 || NETCOREAPP1_1 || NETCOREAPP1_0 + + .ToString() +#endif + , out var numericResult): result = (global::Bar.MyEnum)numericResult; return true; default: @@ -1143,16 +1154,22 @@ namespace Bar { switch (name) { - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::Bar.MyEnum.First), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::Bar.MyEnum.First)), global::System.StringComparison.Ordinal): result = global::Bar.MyEnum.First; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::Bar.MyEnum.Second), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::Bar.MyEnum.Second)), global::System.StringComparison.Ordinal): result = global::Bar.MyEnum.Second; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::Bar.MyEnum.Third), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::Bar.MyEnum.Third)), global::System.StringComparison.Ordinal): result = global::Bar.MyEnum.Third; return true; - case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse( + name +#if !NETCOREAPP || NETCOREAPP2_0 || NETCOREAPP1_1 || NETCOREAPP1_0 + + .ToString() +#endif + , out var numericResult): result = (global::Bar.MyEnum)numericResult; return true; default: @@ -1160,7 +1177,6 @@ namespace Bar return false; } } -#endif /// /// Retrieves an array of the values of the members defined in diff --git a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.CanInterceptEnumInDifferentNamespace.verified.txt b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.CanInterceptEnumInDifferentNamespace.verified.txt index 499d03c..f4a6512 100644 --- a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.CanInterceptEnumInDifferentNamespace.verified.txt +++ b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.CanInterceptEnumInDifferentNamespace.verified.txt @@ -1,4 +1,4 @@ -[ +[ //------------------------------------------------------------------------------ // // This code was generated by the NetEscapades.EnumGenerators source generator @@ -209,7 +209,6 @@ namespace Bar }; } -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Returns a boolean telling whether an enum with the given name exists in the enumeration /// @@ -231,13 +230,12 @@ namespace Bar { return name switch { - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::Foo.MyEnum.First), global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::Foo.MyEnum.Second), global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::Foo.MyEnum.Third), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::Foo.MyEnum.First)), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::Foo.MyEnum.Second)), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::Foo.MyEnum.Third)), global::System.StringComparison.Ordinal) => true, _ => false, }; } -#endif /// /// Converts the string representation of the name or numeric value of @@ -421,7 +419,6 @@ namespace Bar } } -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Converts the string representation of the name or numeric value of /// an to the equivalent instance. @@ -550,16 +547,22 @@ namespace Bar { switch (name) { - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::Foo.MyEnum.First), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::Foo.MyEnum.First)), global::System.StringComparison.OrdinalIgnoreCase): result = global::Foo.MyEnum.First; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::Foo.MyEnum.Second), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::Foo.MyEnum.Second)), global::System.StringComparison.OrdinalIgnoreCase): result = global::Foo.MyEnum.Second; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::Foo.MyEnum.Third), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::Foo.MyEnum.Third)), global::System.StringComparison.OrdinalIgnoreCase): result = global::Foo.MyEnum.Third; return true; - case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse( + name +#if !NETCOREAPP || NETCOREAPP2_0 || NETCOREAPP1_1 || NETCOREAPP1_0 + + .ToString() +#endif + , out var numericResult): result = (global::Foo.MyEnum)numericResult; return true; default: @@ -578,16 +581,22 @@ namespace Bar { switch (name) { - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::Foo.MyEnum.First), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::Foo.MyEnum.First)), global::System.StringComparison.Ordinal): result = global::Foo.MyEnum.First; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::Foo.MyEnum.Second), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::Foo.MyEnum.Second)), global::System.StringComparison.Ordinal): result = global::Foo.MyEnum.Second; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::Foo.MyEnum.Third), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::Foo.MyEnum.Third)), global::System.StringComparison.Ordinal): result = global::Foo.MyEnum.Third; return true; - case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse( + name +#if !NETCOREAPP || NETCOREAPP2_0 || NETCOREAPP1_1 || NETCOREAPP1_0 + + .ToString() +#endif + , out var numericResult): result = (global::Foo.MyEnum)numericResult; return true; default: @@ -595,7 +604,6 @@ namespace Bar return false; } } -#endif /// /// Retrieves an array of the values of the members defined in diff --git a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.CanInterceptEnumInGlobalNamespace.verified.txt b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.CanInterceptEnumInGlobalNamespace.verified.txt index efd643c..a16b5ac 100644 --- a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.CanInterceptEnumInGlobalNamespace.verified.txt +++ b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.CanInterceptEnumInGlobalNamespace.verified.txt @@ -207,7 +207,6 @@ namespace NetEscapades.EnumGenerators }; } -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Returns a boolean telling whether an enum with the given name exists in the enumeration /// @@ -229,13 +228,12 @@ namespace NetEscapades.EnumGenerators { return name switch { - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyEnum.First), global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyEnum.Second), global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyEnum.Third), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyEnum.First)), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyEnum.Second)), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyEnum.Third)), global::System.StringComparison.Ordinal) => true, _ => false, }; } -#endif /// /// Converts the string representation of the name or numeric value of @@ -419,7 +417,6 @@ namespace NetEscapades.EnumGenerators } } -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Converts the string representation of the name or numeric value of /// an to the equivalent instance. @@ -548,16 +545,22 @@ namespace NetEscapades.EnumGenerators { switch (name) { - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyEnum.First), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyEnum.First)), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyEnum.First; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyEnum.Second), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyEnum.Second)), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyEnum.Second; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyEnum.Third), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyEnum.Third)), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyEnum.Third; return true; - case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse( + name +#if !NETCOREAPP || NETCOREAPP2_0 || NETCOREAPP1_1 || NETCOREAPP1_0 + + .ToString() +#endif + , out var numericResult): result = (global::MyEnum)numericResult; return true; default: @@ -576,16 +579,22 @@ namespace NetEscapades.EnumGenerators { switch (name) { - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyEnum.First), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyEnum.First)), global::System.StringComparison.Ordinal): result = global::MyEnum.First; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyEnum.Second), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyEnum.Second)), global::System.StringComparison.Ordinal): result = global::MyEnum.Second; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyEnum.Third), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyEnum.Third)), global::System.StringComparison.Ordinal): result = global::MyEnum.Third; return true; - case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse( + name +#if !NETCOREAPP || NETCOREAPP2_0 || NETCOREAPP1_1 || NETCOREAPP1_0 + + .ToString() +#endif + , out var numericResult): result = (global::MyEnum)numericResult; return true; default: @@ -593,7 +602,6 @@ namespace NetEscapades.EnumGenerators return false; } } -#endif /// /// Retrieves an array of the values of the members defined in diff --git a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.CanInterceptExternalEnumToString.verified.txt b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.CanInterceptExternalEnumToString.verified.txt index f582def..7257528 100644 --- a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.CanInterceptExternalEnumToString.verified.txt +++ b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.CanInterceptExternalEnumToString.verified.txt @@ -206,7 +206,6 @@ namespace System }; } -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Returns a boolean telling whether an enum with the given name exists in the enumeration /// @@ -228,16 +227,15 @@ namespace System { return name switch { - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.CurrentCulture), global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.CurrentCultureIgnoreCase), global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.InvariantCulture), global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.InvariantCultureIgnoreCase), global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.Ordinal), global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.OrdinalIgnoreCase), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.StringComparison.CurrentCulture)), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.StringComparison.CurrentCultureIgnoreCase)), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.StringComparison.InvariantCulture)), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.StringComparison.InvariantCultureIgnoreCase)), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.StringComparison.Ordinal)), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.StringComparison.OrdinalIgnoreCase)), global::System.StringComparison.Ordinal) => true, _ => false, }; } -#endif /// /// Converts the string representation of the name or numeric value of @@ -439,7 +437,6 @@ namespace System } } -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Converts the string representation of the name or numeric value of /// an to the equivalent instance. @@ -568,25 +565,31 @@ namespace System { switch (name) { - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.CurrentCulture), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.StringComparison.CurrentCulture)), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.StringComparison.CurrentCulture; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.CurrentCultureIgnoreCase), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.StringComparison.CurrentCultureIgnoreCase)), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.StringComparison.CurrentCultureIgnoreCase; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.InvariantCulture), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.StringComparison.InvariantCulture)), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.StringComparison.InvariantCulture; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.InvariantCultureIgnoreCase), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.StringComparison.InvariantCultureIgnoreCase)), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.StringComparison.InvariantCultureIgnoreCase; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.Ordinal), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.StringComparison.Ordinal)), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.StringComparison.Ordinal; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.OrdinalIgnoreCase), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.StringComparison.OrdinalIgnoreCase)), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.StringComparison.OrdinalIgnoreCase; return true; - case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse( + name +#if !NETCOREAPP || NETCOREAPP2_0 || NETCOREAPP1_1 || NETCOREAPP1_0 + + .ToString() +#endif + , out var numericResult): result = (global::System.StringComparison)numericResult; return true; default: @@ -605,25 +608,31 @@ namespace System { switch (name) { - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.CurrentCulture), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.StringComparison.CurrentCulture)), global::System.StringComparison.Ordinal): result = global::System.StringComparison.CurrentCulture; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.CurrentCultureIgnoreCase), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.StringComparison.CurrentCultureIgnoreCase)), global::System.StringComparison.Ordinal): result = global::System.StringComparison.CurrentCultureIgnoreCase; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.InvariantCulture), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.StringComparison.InvariantCulture)), global::System.StringComparison.Ordinal): result = global::System.StringComparison.InvariantCulture; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.InvariantCultureIgnoreCase), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.StringComparison.InvariantCultureIgnoreCase)), global::System.StringComparison.Ordinal): result = global::System.StringComparison.InvariantCultureIgnoreCase; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.Ordinal), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.StringComparison.Ordinal)), global::System.StringComparison.Ordinal): result = global::System.StringComparison.Ordinal; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.OrdinalIgnoreCase), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.StringComparison.OrdinalIgnoreCase)), global::System.StringComparison.Ordinal): result = global::System.StringComparison.OrdinalIgnoreCase; return true; - case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse( + name +#if !NETCOREAPP || NETCOREAPP2_0 || NETCOREAPP1_1 || NETCOREAPP1_0 + + .ToString() +#endif + , out var numericResult): result = (global::System.StringComparison)numericResult; return true; default: @@ -631,7 +640,6 @@ namespace System return false; } } -#endif /// /// Retrieves an array of the values of the members defined in diff --git a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.CanInterceptHasFlag.verified.txt b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.CanInterceptHasFlag.verified.txt index d8058a9..ceeb014 100644 --- a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.CanInterceptHasFlag.verified.txt +++ b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.CanInterceptHasFlag.verified.txt @@ -209,7 +209,6 @@ namespace MyTestNameSpace }; } -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Returns a boolean telling whether an enum with the given name exists in the enumeration /// @@ -231,13 +230,12 @@ namespace MyTestNameSpace { return name switch { - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.First), global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Second), global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Third), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.First)), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.Second)), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.Third)), global::System.StringComparison.Ordinal) => true, _ => false, }; } -#endif /// /// Converts the string representation of the name or numeric value of @@ -421,7 +419,6 @@ namespace MyTestNameSpace } } -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Converts the string representation of the name or numeric value of /// an to the equivalent instance. @@ -550,16 +547,22 @@ namespace MyTestNameSpace { switch (name) { - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.First), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.First)), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyTestNameSpace.MyEnum.First; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Second), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.Second)), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyTestNameSpace.MyEnum.Second; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Third), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.Third)), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyTestNameSpace.MyEnum.Third; return true; - case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse( + name +#if !NETCOREAPP || NETCOREAPP2_0 || NETCOREAPP1_1 || NETCOREAPP1_0 + + .ToString() +#endif + , out var numericResult): result = (global::MyTestNameSpace.MyEnum)numericResult; return true; default: @@ -578,16 +581,22 @@ namespace MyTestNameSpace { switch (name) { - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.First), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.First)), global::System.StringComparison.Ordinal): result = global::MyTestNameSpace.MyEnum.First; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Second), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.Second)), global::System.StringComparison.Ordinal): result = global::MyTestNameSpace.MyEnum.Second; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Third), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.Third)), global::System.StringComparison.Ordinal): result = global::MyTestNameSpace.MyEnum.Third; return true; - case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse( + name +#if !NETCOREAPP || NETCOREAPP2_0 || NETCOREAPP1_1 || NETCOREAPP1_0 + + .ToString() +#endif + , out var numericResult): result = (global::MyTestNameSpace.MyEnum)numericResult; return true; default: @@ -595,7 +604,6 @@ namespace MyTestNameSpace return false; } } -#endif /// /// Retrieves an array of the values of the members defined in diff --git a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.CanInterceptMultipleEnumsToString.verified.txt b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.CanInterceptMultipleEnumsToString.verified.txt index 3122daf..713b6c3 100644 --- a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.CanInterceptMultipleEnumsToString.verified.txt +++ b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.CanInterceptMultipleEnumsToString.verified.txt @@ -197,7 +197,6 @@ namespace MyTestNameSpace }; } -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Returns a boolean telling whether an enum with the given name exists in the enumeration /// @@ -219,13 +218,12 @@ namespace MyTestNameSpace { return name switch { - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.First), global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Second), global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Third), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.First)), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.Second)), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.Third)), global::System.StringComparison.Ordinal) => true, _ => false, }; } -#endif /// /// Converts the string representation of the name or numeric value of @@ -409,7 +407,6 @@ namespace MyTestNameSpace } } -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Converts the string representation of the name or numeric value of /// an to the equivalent instance. @@ -538,16 +535,22 @@ namespace MyTestNameSpace { switch (name) { - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.First), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.First)), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyTestNameSpace.MyEnum.First; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Second), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.Second)), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyTestNameSpace.MyEnum.Second; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Third), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.Third)), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyTestNameSpace.MyEnum.Third; return true; - case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse( + name +#if !NETCOREAPP || NETCOREAPP2_0 || NETCOREAPP1_1 || NETCOREAPP1_0 + + .ToString() +#endif + , out var numericResult): result = (global::MyTestNameSpace.MyEnum)numericResult; return true; default: @@ -566,16 +569,22 @@ namespace MyTestNameSpace { switch (name) { - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.First), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.First)), global::System.StringComparison.Ordinal): result = global::MyTestNameSpace.MyEnum.First; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Second), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.Second)), global::System.StringComparison.Ordinal): result = global::MyTestNameSpace.MyEnum.Second; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Third), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.Third)), global::System.StringComparison.Ordinal): result = global::MyTestNameSpace.MyEnum.Third; return true; - case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse( + name +#if !NETCOREAPP || NETCOREAPP2_0 || NETCOREAPP1_1 || NETCOREAPP1_0 + + .ToString() +#endif + , out var numericResult): result = (global::MyTestNameSpace.MyEnum)numericResult; return true; default: @@ -583,7 +592,6 @@ namespace MyTestNameSpace return false; } } -#endif /// /// Retrieves an array of the values of the members defined in @@ -750,7 +758,6 @@ namespace MyTestNameSpace }; } -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Returns a boolean telling whether an enum with the given name exists in the enumeration /// @@ -772,13 +779,12 @@ namespace MyTestNameSpace { return name switch { - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.AnotherEnum.First), global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.AnotherEnum.Second), global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.AnotherEnum.Third), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.AnotherEnum.First)), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.AnotherEnum.Second)), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.AnotherEnum.Third)), global::System.StringComparison.Ordinal) => true, _ => false, }; } -#endif /// /// Converts the string representation of the name or numeric value of @@ -962,7 +968,6 @@ namespace MyTestNameSpace } } -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Converts the string representation of the name or numeric value of /// an to the equivalent instance. @@ -1091,16 +1096,22 @@ namespace MyTestNameSpace { switch (name) { - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.AnotherEnum.First), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.AnotherEnum.First)), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyTestNameSpace.AnotherEnum.First; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.AnotherEnum.Second), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.AnotherEnum.Second)), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyTestNameSpace.AnotherEnum.Second; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.AnotherEnum.Third), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.AnotherEnum.Third)), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyTestNameSpace.AnotherEnum.Third; return true; - case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse( + name +#if !NETCOREAPP || NETCOREAPP2_0 || NETCOREAPP1_1 || NETCOREAPP1_0 + + .ToString() +#endif + , out var numericResult): result = (global::MyTestNameSpace.AnotherEnum)numericResult; return true; default: @@ -1119,16 +1130,22 @@ namespace MyTestNameSpace { switch (name) { - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.AnotherEnum.First), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.AnotherEnum.First)), global::System.StringComparison.Ordinal): result = global::MyTestNameSpace.AnotherEnum.First; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.AnotherEnum.Second), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.AnotherEnum.Second)), global::System.StringComparison.Ordinal): result = global::MyTestNameSpace.AnotherEnum.Second; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.AnotherEnum.Third), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.AnotherEnum.Third)), global::System.StringComparison.Ordinal): result = global::MyTestNameSpace.AnotherEnum.Third; return true; - case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse( + name +#if !NETCOREAPP || NETCOREAPP2_0 || NETCOREAPP1_1 || NETCOREAPP1_0 + + .ToString() +#endif + , out var numericResult): result = (global::MyTestNameSpace.AnotherEnum)numericResult; return true; default: @@ -1136,7 +1153,6 @@ namespace MyTestNameSpace return false; } } -#endif /// /// Retrieves an array of the values of the members defined in diff --git a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.CanInterceptToString.verified.txt b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.CanInterceptToString.verified.txt index da44079..250102a 100644 --- a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.CanInterceptToString.verified.txt +++ b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.CanInterceptToString.verified.txt @@ -194,7 +194,6 @@ namespace MyTestNameSpace }; } -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Returns a boolean telling whether an enum with the given name exists in the enumeration /// @@ -216,12 +215,11 @@ namespace MyTestNameSpace { return name switch { - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.First), global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Second), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.First)), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.Second)), global::System.StringComparison.Ordinal) => true, _ => false, }; } -#endif /// /// Converts the string representation of the name or numeric value of @@ -399,7 +397,6 @@ namespace MyTestNameSpace } } -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Converts the string representation of the name or numeric value of /// an to the equivalent instance. @@ -528,13 +525,19 @@ namespace MyTestNameSpace { switch (name) { - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.First), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.First)), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyTestNameSpace.MyEnum.First; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Second), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.Second)), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyTestNameSpace.MyEnum.Second; return true; - case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse( + name +#if !NETCOREAPP || NETCOREAPP2_0 || NETCOREAPP1_1 || NETCOREAPP1_0 + + .ToString() +#endif + , out var numericResult): result = (global::MyTestNameSpace.MyEnum)numericResult; return true; default: @@ -553,13 +556,19 @@ namespace MyTestNameSpace { switch (name) { - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.First), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.First)), global::System.StringComparison.Ordinal): result = global::MyTestNameSpace.MyEnum.First; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Second), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.Second)), global::System.StringComparison.Ordinal): result = global::MyTestNameSpace.MyEnum.Second; return true; - case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse( + name +#if !NETCOREAPP || NETCOREAPP2_0 || NETCOREAPP1_1 || NETCOREAPP1_0 + + .ToString() +#endif + , out var numericResult): result = (global::MyTestNameSpace.MyEnum)numericResult; return true; default: @@ -567,7 +576,6 @@ namespace MyTestNameSpace return false; } } -#endif /// /// Retrieves an array of the values of the members defined in diff --git a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.CanInterceptToStringWhenCsharp11.verified.txt b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.CanInterceptToStringWhenCsharp11.verified.txt index da44079..250102a 100644 --- a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.CanInterceptToStringWhenCsharp11.verified.txt +++ b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.CanInterceptToStringWhenCsharp11.verified.txt @@ -194,7 +194,6 @@ namespace MyTestNameSpace }; } -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Returns a boolean telling whether an enum with the given name exists in the enumeration /// @@ -216,12 +215,11 @@ namespace MyTestNameSpace { return name switch { - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.First), global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Second), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.First)), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.Second)), global::System.StringComparison.Ordinal) => true, _ => false, }; } -#endif /// /// Converts the string representation of the name or numeric value of @@ -399,7 +397,6 @@ namespace MyTestNameSpace } } -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Converts the string representation of the name or numeric value of /// an to the equivalent instance. @@ -528,13 +525,19 @@ namespace MyTestNameSpace { switch (name) { - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.First), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.First)), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyTestNameSpace.MyEnum.First; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Second), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.Second)), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyTestNameSpace.MyEnum.Second; return true; - case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse( + name +#if !NETCOREAPP || NETCOREAPP2_0 || NETCOREAPP1_1 || NETCOREAPP1_0 + + .ToString() +#endif + , out var numericResult): result = (global::MyTestNameSpace.MyEnum)numericResult; return true; default: @@ -553,13 +556,19 @@ namespace MyTestNameSpace { switch (name) { - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.First), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.First)), global::System.StringComparison.Ordinal): result = global::MyTestNameSpace.MyEnum.First; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Second), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.Second)), global::System.StringComparison.Ordinal): result = global::MyTestNameSpace.MyEnum.Second; return true; - case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse( + name +#if !NETCOREAPP || NETCOREAPP2_0 || NETCOREAPP1_1 || NETCOREAPP1_0 + + .ToString() +#endif + , out var numericResult): result = (global::MyTestNameSpace.MyEnum)numericResult; return true; default: @@ -567,7 +576,6 @@ namespace MyTestNameSpace return false; } } -#endif /// /// Retrieves an array of the values of the members defined in diff --git a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.CanInterceptUsingInterceptableAttributeToString.verified.txt b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.CanInterceptUsingInterceptableAttributeToString.verified.txt index 2ffc391..d0cde50 100644 --- a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.CanInterceptUsingInterceptableAttributeToString.verified.txt +++ b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.CanInterceptUsingInterceptableAttributeToString.verified.txt @@ -206,7 +206,6 @@ namespace System }; } -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Returns a boolean telling whether an enum with the given name exists in the enumeration /// @@ -228,16 +227,15 @@ namespace System { return name switch { - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.CurrentCulture), global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.CurrentCultureIgnoreCase), global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.InvariantCulture), global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.InvariantCultureIgnoreCase), global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.Ordinal), global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.OrdinalIgnoreCase), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.StringComparison.CurrentCulture)), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.StringComparison.CurrentCultureIgnoreCase)), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.StringComparison.InvariantCulture)), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.StringComparison.InvariantCultureIgnoreCase)), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.StringComparison.Ordinal)), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.StringComparison.OrdinalIgnoreCase)), global::System.StringComparison.Ordinal) => true, _ => false, }; } -#endif /// /// Converts the string representation of the name or numeric value of @@ -439,7 +437,6 @@ namespace System } } -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Converts the string representation of the name or numeric value of /// an to the equivalent instance. @@ -568,25 +565,31 @@ namespace System { switch (name) { - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.CurrentCulture), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.StringComparison.CurrentCulture)), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.StringComparison.CurrentCulture; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.CurrentCultureIgnoreCase), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.StringComparison.CurrentCultureIgnoreCase)), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.StringComparison.CurrentCultureIgnoreCase; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.InvariantCulture), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.StringComparison.InvariantCulture)), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.StringComparison.InvariantCulture; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.InvariantCultureIgnoreCase), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.StringComparison.InvariantCultureIgnoreCase)), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.StringComparison.InvariantCultureIgnoreCase; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.Ordinal), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.StringComparison.Ordinal)), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.StringComparison.Ordinal; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.OrdinalIgnoreCase), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.StringComparison.OrdinalIgnoreCase)), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.StringComparison.OrdinalIgnoreCase; return true; - case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse( + name +#if !NETCOREAPP || NETCOREAPP2_0 || NETCOREAPP1_1 || NETCOREAPP1_0 + + .ToString() +#endif + , out var numericResult): result = (global::System.StringComparison)numericResult; return true; default: @@ -605,25 +608,31 @@ namespace System { switch (name) { - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.CurrentCulture), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.StringComparison.CurrentCulture)), global::System.StringComparison.Ordinal): result = global::System.StringComparison.CurrentCulture; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.CurrentCultureIgnoreCase), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.StringComparison.CurrentCultureIgnoreCase)), global::System.StringComparison.Ordinal): result = global::System.StringComparison.CurrentCultureIgnoreCase; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.InvariantCulture), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.StringComparison.InvariantCulture)), global::System.StringComparison.Ordinal): result = global::System.StringComparison.InvariantCulture; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.InvariantCultureIgnoreCase), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.StringComparison.InvariantCultureIgnoreCase)), global::System.StringComparison.Ordinal): result = global::System.StringComparison.InvariantCultureIgnoreCase; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.Ordinal), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.StringComparison.Ordinal)), global::System.StringComparison.Ordinal): result = global::System.StringComparison.Ordinal; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.OrdinalIgnoreCase), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.StringComparison.OrdinalIgnoreCase)), global::System.StringComparison.Ordinal): result = global::System.StringComparison.OrdinalIgnoreCase; return true; - case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse( + name +#if !NETCOREAPP || NETCOREAPP2_0 || NETCOREAPP1_1 || NETCOREAPP1_0 + + .ToString() +#endif + , out var numericResult): result = (global::System.StringComparison)numericResult; return true; default: @@ -631,7 +640,6 @@ namespace System return false; } } -#endif /// /// Retrieves an array of the values of the members defined in diff --git a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.CanNotInterceptEnumWithoutInterceptorPackage.verified.txt b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.CanNotInterceptEnumWithoutInterceptorPackage.verified.txt index 4a7e7a4..3107e9e 100644 --- a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.CanNotInterceptEnumWithoutInterceptorPackage.verified.txt +++ b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.CanNotInterceptEnumWithoutInterceptorPackage.verified.txt @@ -194,7 +194,6 @@ namespace MyTestNameSpace }; } -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Returns a boolean telling whether an enum with the given name exists in the enumeration /// @@ -216,12 +215,11 @@ namespace MyTestNameSpace { return name switch { - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.First), global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Second), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.First)), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.Second)), global::System.StringComparison.Ordinal) => true, _ => false, }; } -#endif /// /// Converts the string representation of the name or numeric value of @@ -399,7 +397,6 @@ namespace MyTestNameSpace } } -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Converts the string representation of the name or numeric value of /// an to the equivalent instance. @@ -528,13 +525,19 @@ namespace MyTestNameSpace { switch (name) { - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.First), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.First)), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyTestNameSpace.MyEnum.First; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Second), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.Second)), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyTestNameSpace.MyEnum.Second; return true; - case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse( + name +#if !NETCOREAPP || NETCOREAPP2_0 || NETCOREAPP1_1 || NETCOREAPP1_0 + + .ToString() +#endif + , out var numericResult): result = (global::MyTestNameSpace.MyEnum)numericResult; return true; default: @@ -553,13 +556,19 @@ namespace MyTestNameSpace { switch (name) { - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.First), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.First)), global::System.StringComparison.Ordinal): result = global::MyTestNameSpace.MyEnum.First; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Second), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.Second)), global::System.StringComparison.Ordinal): result = global::MyTestNameSpace.MyEnum.Second; return true; - case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse( + name +#if !NETCOREAPP || NETCOREAPP2_0 || NETCOREAPP1_1 || NETCOREAPP1_0 + + .ToString() +#endif + , out var numericResult): result = (global::MyTestNameSpace.MyEnum)numericResult; return true; default: @@ -567,7 +576,6 @@ namespace MyTestNameSpace return false; } } -#endif /// /// Retrieves an array of the values of the members defined in diff --git a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.CanNotInterceptUsageInStringInterpolation.verified.txt b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.CanNotInterceptUsageInStringInterpolation.verified.txt index 758c8c6..465dcc7 100644 --- a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.CanNotInterceptUsageInStringInterpolation.verified.txt +++ b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.CanNotInterceptUsageInStringInterpolation.verified.txt @@ -194,7 +194,6 @@ namespace MyTestNameSpace }; } -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Returns a boolean telling whether an enum with the given name exists in the enumeration /// @@ -216,12 +215,11 @@ namespace MyTestNameSpace { return name switch { - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.First), global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Second), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.First)), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.Second)), global::System.StringComparison.Ordinal) => true, _ => false, }; } -#endif /// /// Converts the string representation of the name or numeric value of @@ -399,7 +397,6 @@ namespace MyTestNameSpace } } -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Converts the string representation of the name or numeric value of /// an to the equivalent instance. @@ -528,13 +525,19 @@ namespace MyTestNameSpace { switch (name) { - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.First), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.First)), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyTestNameSpace.MyEnum.First; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Second), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.Second)), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyTestNameSpace.MyEnum.Second; return true; - case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse( + name +#if !NETCOREAPP || NETCOREAPP2_0 || NETCOREAPP1_1 || NETCOREAPP1_0 + + .ToString() +#endif + , out var numericResult): result = (global::MyTestNameSpace.MyEnum)numericResult; return true; default: @@ -553,13 +556,19 @@ namespace MyTestNameSpace { switch (name) { - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.First), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.First)), global::System.StringComparison.Ordinal): result = global::MyTestNameSpace.MyEnum.First; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Second), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.Second)), global::System.StringComparison.Ordinal): result = global::MyTestNameSpace.MyEnum.Second; return true; - case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse( + name +#if !NETCOREAPP || NETCOREAPP2_0 || NETCOREAPP1_1 || NETCOREAPP1_0 + + .ToString() +#endif + , out var numericResult): result = (global::MyTestNameSpace.MyEnum)numericResult; return true; default: @@ -567,7 +576,6 @@ namespace MyTestNameSpace return false; } } -#endif /// /// Retrieves an array of the values of the members defined in diff --git a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.CanNotInterceptUsageWithEnumDirectly.verified.txt b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.CanNotInterceptUsageWithEnumDirectly.verified.txt index 758c8c6..465dcc7 100644 --- a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.CanNotInterceptUsageWithEnumDirectly.verified.txt +++ b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.CanNotInterceptUsageWithEnumDirectly.verified.txt @@ -194,7 +194,6 @@ namespace MyTestNameSpace }; } -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Returns a boolean telling whether an enum with the given name exists in the enumeration /// @@ -216,12 +215,11 @@ namespace MyTestNameSpace { return name switch { - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.First), global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Second), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.First)), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.Second)), global::System.StringComparison.Ordinal) => true, _ => false, }; } -#endif /// /// Converts the string representation of the name or numeric value of @@ -399,7 +397,6 @@ namespace MyTestNameSpace } } -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Converts the string representation of the name or numeric value of /// an to the equivalent instance. @@ -528,13 +525,19 @@ namespace MyTestNameSpace { switch (name) { - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.First), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.First)), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyTestNameSpace.MyEnum.First; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Second), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.Second)), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyTestNameSpace.MyEnum.Second; return true; - case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse( + name +#if !NETCOREAPP || NETCOREAPP2_0 || NETCOREAPP1_1 || NETCOREAPP1_0 + + .ToString() +#endif + , out var numericResult): result = (global::MyTestNameSpace.MyEnum)numericResult; return true; default: @@ -553,13 +556,19 @@ namespace MyTestNameSpace { switch (name) { - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.First), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.First)), global::System.StringComparison.Ordinal): result = global::MyTestNameSpace.MyEnum.First; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Second), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.Second)), global::System.StringComparison.Ordinal): result = global::MyTestNameSpace.MyEnum.Second; return true; - case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse( + name +#if !NETCOREAPP || NETCOREAPP2_0 || NETCOREAPP1_1 || NETCOREAPP1_0 + + .ToString() +#endif + , out var numericResult): result = (global::MyTestNameSpace.MyEnum)numericResult; return true; default: @@ -567,7 +576,6 @@ namespace MyTestNameSpace return false; } } -#endif /// /// Retrieves an array of the values of the members defined in diff --git a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.DoesNotGenerateWarningsForUseOfObsoleteEnums_CS0612_Issue97.verified.txt b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.DoesNotGenerateWarningsForUseOfObsoleteEnums_CS0612_Issue97.verified.txt index b973781..f9f3814 100644 --- a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.DoesNotGenerateWarningsForUseOfObsoleteEnums_CS0612_Issue97.verified.txt +++ b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.DoesNotGenerateWarningsForUseOfObsoleteEnums_CS0612_Issue97.verified.txt @@ -1,4 +1,4 @@ -//------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ // // This code was generated by the NetEscapades.EnumGenerators source generator // @@ -103,7 +103,6 @@ }; } -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Returns a boolean telling whether an enum with the given name exists in the enumeration /// @@ -125,12 +124,11 @@ { return name switch { - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::OtherEnum.First), global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::OtherEnum.Second), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::OtherEnum.First)), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::OtherEnum.Second)), global::System.StringComparison.Ordinal) => true, _ => false, }; } -#endif /// /// Converts the string representation of the name or numeric value of @@ -308,7 +306,6 @@ } } -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Converts the string representation of the name or numeric value of /// an to the equivalent instance. @@ -437,13 +434,19 @@ { switch (name) { - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::OtherEnum.First), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::OtherEnum.First)), global::System.StringComparison.OrdinalIgnoreCase): result = global::OtherEnum.First; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::OtherEnum.Second), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::OtherEnum.Second)), global::System.StringComparison.OrdinalIgnoreCase): result = global::OtherEnum.Second; return true; - case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse( + name +#if !NETCOREAPP || NETCOREAPP2_0 || NETCOREAPP1_1 || NETCOREAPP1_0 + + .ToString() +#endif + , out var numericResult): result = (global::OtherEnum)numericResult; return true; default: @@ -462,13 +465,19 @@ { switch (name) { - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::OtherEnum.First), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::OtherEnum.First)), global::System.StringComparison.Ordinal): result = global::OtherEnum.First; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::OtherEnum.Second), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::OtherEnum.Second)), global::System.StringComparison.Ordinal): result = global::OtherEnum.Second; return true; - case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse( + name +#if !NETCOREAPP || NETCOREAPP2_0 || NETCOREAPP1_1 || NETCOREAPP1_0 + + .ToString() +#endif + , out var numericResult): result = (global::OtherEnum)numericResult; return true; default: @@ -476,7 +485,6 @@ return false; } } -#endif /// /// Retrieves an array of the values of the members defined in diff --git a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.DoesNotGenerateWarningsForUseOfObsoleteEnums_CS0618_Issue97.verified.txt b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.DoesNotGenerateWarningsForUseOfObsoleteEnums_CS0618_Issue97.verified.txt index 4fe0e50..f9f3814 100644 --- a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.DoesNotGenerateWarningsForUseOfObsoleteEnums_CS0618_Issue97.verified.txt +++ b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.DoesNotGenerateWarningsForUseOfObsoleteEnums_CS0618_Issue97.verified.txt @@ -103,7 +103,6 @@ }; } -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Returns a boolean telling whether an enum with the given name exists in the enumeration /// @@ -125,12 +124,11 @@ { return name switch { - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::OtherEnum.First), global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::OtherEnum.Second), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::OtherEnum.First)), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::OtherEnum.Second)), global::System.StringComparison.Ordinal) => true, _ => false, }; } -#endif /// /// Converts the string representation of the name or numeric value of @@ -308,7 +306,6 @@ } } -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Converts the string representation of the name or numeric value of /// an to the equivalent instance. @@ -437,13 +434,19 @@ { switch (name) { - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::OtherEnum.First), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::OtherEnum.First)), global::System.StringComparison.OrdinalIgnoreCase): result = global::OtherEnum.First; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::OtherEnum.Second), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::OtherEnum.Second)), global::System.StringComparison.OrdinalIgnoreCase): result = global::OtherEnum.Second; return true; - case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse( + name +#if !NETCOREAPP || NETCOREAPP2_0 || NETCOREAPP1_1 || NETCOREAPP1_0 + + .ToString() +#endif + , out var numericResult): result = (global::OtherEnum)numericResult; return true; default: @@ -462,13 +465,19 @@ { switch (name) { - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::OtherEnum.First), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::OtherEnum.First)), global::System.StringComparison.Ordinal): result = global::OtherEnum.First; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::OtherEnum.Second), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::OtherEnum.Second)), global::System.StringComparison.Ordinal): result = global::OtherEnum.Second; return true; - case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse( + name +#if !NETCOREAPP || NETCOREAPP2_0 || NETCOREAPP1_1 || NETCOREAPP1_0 + + .ToString() +#endif + , out var numericResult): result = (global::OtherEnum)numericResult; return true; default: @@ -476,7 +485,6 @@ return false; } } -#endif /// /// Retrieves an array of the values of the members defined in diff --git a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.DoesNotInterceptEnumMarkedAsNotInterceptable.verified.txt b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.DoesNotInterceptEnumMarkedAsNotInterceptable.verified.txt index 8d33b0e..f3ee14b 100644 --- a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.DoesNotInterceptEnumMarkedAsNotInterceptable.verified.txt +++ b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.DoesNotInterceptEnumMarkedAsNotInterceptable.verified.txt @@ -197,7 +197,6 @@ namespace MyTestNameSpace }; } -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Returns a boolean telling whether an enum with the given name exists in the enumeration /// @@ -219,13 +218,12 @@ namespace MyTestNameSpace { return name switch { - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.First), global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Second), global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Third), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.First)), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.Second)), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.Third)), global::System.StringComparison.Ordinal) => true, _ => false, }; } -#endif /// /// Converts the string representation of the name or numeric value of @@ -409,7 +407,6 @@ namespace MyTestNameSpace } } -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Converts the string representation of the name or numeric value of /// an to the equivalent instance. @@ -538,16 +535,22 @@ namespace MyTestNameSpace { switch (name) { - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.First), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.First)), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyTestNameSpace.MyEnum.First; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Second), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.Second)), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyTestNameSpace.MyEnum.Second; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Third), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.Third)), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyTestNameSpace.MyEnum.Third; return true; - case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse( + name +#if !NETCOREAPP || NETCOREAPP2_0 || NETCOREAPP1_1 || NETCOREAPP1_0 + + .ToString() +#endif + , out var numericResult): result = (global::MyTestNameSpace.MyEnum)numericResult; return true; default: @@ -566,16 +569,22 @@ namespace MyTestNameSpace { switch (name) { - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.First), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.First)), global::System.StringComparison.Ordinal): result = global::MyTestNameSpace.MyEnum.First; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Second), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.Second)), global::System.StringComparison.Ordinal): result = global::MyTestNameSpace.MyEnum.Second; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Third), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.Third)), global::System.StringComparison.Ordinal): result = global::MyTestNameSpace.MyEnum.Third; return true; - case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse( + name +#if !NETCOREAPP || NETCOREAPP2_0 || NETCOREAPP1_1 || NETCOREAPP1_0 + + .ToString() +#endif + , out var numericResult): result = (global::MyTestNameSpace.MyEnum)numericResult; return true; default: @@ -583,7 +592,6 @@ namespace MyTestNameSpace return false; } } -#endif /// /// Retrieves an array of the values of the members defined in @@ -762,7 +770,6 @@ namespace MyTestNameSpace }; } -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Returns a boolean telling whether an enum with the given name exists in the enumeration /// @@ -784,13 +791,12 @@ namespace MyTestNameSpace { return name switch { - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.AnotherEnum.First), global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.AnotherEnum.Second), global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.AnotherEnum.Third), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.AnotherEnum.First)), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.AnotherEnum.Second)), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.AnotherEnum.Third)), global::System.StringComparison.Ordinal) => true, _ => false, }; } -#endif /// /// Converts the string representation of the name or numeric value of @@ -974,7 +980,6 @@ namespace MyTestNameSpace } } -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Converts the string representation of the name or numeric value of /// an to the equivalent instance. @@ -1103,16 +1108,22 @@ namespace MyTestNameSpace { switch (name) { - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.AnotherEnum.First), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.AnotherEnum.First)), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyTestNameSpace.AnotherEnum.First; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.AnotherEnum.Second), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.AnotherEnum.Second)), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyTestNameSpace.AnotherEnum.Second; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.AnotherEnum.Third), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.AnotherEnum.Third)), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyTestNameSpace.AnotherEnum.Third; return true; - case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse( + name +#if !NETCOREAPP || NETCOREAPP2_0 || NETCOREAPP1_1 || NETCOREAPP1_0 + + .ToString() +#endif + , out var numericResult): result = (global::MyTestNameSpace.AnotherEnum)numericResult; return true; default: @@ -1131,16 +1142,22 @@ namespace MyTestNameSpace { switch (name) { - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.AnotherEnum.First), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.AnotherEnum.First)), global::System.StringComparison.Ordinal): result = global::MyTestNameSpace.AnotherEnum.First; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.AnotherEnum.Second), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.AnotherEnum.Second)), global::System.StringComparison.Ordinal): result = global::MyTestNameSpace.AnotherEnum.Second; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.AnotherEnum.Third), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.AnotherEnum.Third)), global::System.StringComparison.Ordinal): result = global::MyTestNameSpace.AnotherEnum.Third; return true; - case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse( + name +#if !NETCOREAPP || NETCOREAPP2_0 || NETCOREAPP1_1 || NETCOREAPP1_0 + + .ToString() +#endif + , out var numericResult): result = (global::MyTestNameSpace.AnotherEnum)numericResult; return true; default: @@ -1148,7 +1165,6 @@ namespace MyTestNameSpace return false; } } -#endif /// /// Retrieves an array of the values of the members defined in diff --git a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.DoesNotInterceptExternalEnumMarkedAsNotInterceptable.verified.txt b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.DoesNotInterceptExternalEnumMarkedAsNotInterceptable.verified.txt index beef768..d47d166 100644 --- a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.DoesNotInterceptExternalEnumMarkedAsNotInterceptable.verified.txt +++ b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.DoesNotInterceptExternalEnumMarkedAsNotInterceptable.verified.txt @@ -206,7 +206,6 @@ namespace System }; } -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Returns a boolean telling whether an enum with the given name exists in the enumeration /// @@ -228,16 +227,15 @@ namespace System { return name switch { - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.CurrentCulture), global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.CurrentCultureIgnoreCase), global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.InvariantCulture), global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.InvariantCultureIgnoreCase), global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.Ordinal), global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.OrdinalIgnoreCase), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.StringComparison.CurrentCulture)), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.StringComparison.CurrentCultureIgnoreCase)), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.StringComparison.InvariantCulture)), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.StringComparison.InvariantCultureIgnoreCase)), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.StringComparison.Ordinal)), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.StringComparison.OrdinalIgnoreCase)), global::System.StringComparison.Ordinal) => true, _ => false, }; } -#endif /// /// Converts the string representation of the name or numeric value of @@ -439,7 +437,6 @@ namespace System } } -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Converts the string representation of the name or numeric value of /// an to the equivalent instance. @@ -568,25 +565,31 @@ namespace System { switch (name) { - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.CurrentCulture), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.StringComparison.CurrentCulture)), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.StringComparison.CurrentCulture; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.CurrentCultureIgnoreCase), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.StringComparison.CurrentCultureIgnoreCase)), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.StringComparison.CurrentCultureIgnoreCase; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.InvariantCulture), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.StringComparison.InvariantCulture)), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.StringComparison.InvariantCulture; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.InvariantCultureIgnoreCase), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.StringComparison.InvariantCultureIgnoreCase)), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.StringComparison.InvariantCultureIgnoreCase; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.Ordinal), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.StringComparison.Ordinal)), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.StringComparison.Ordinal; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.OrdinalIgnoreCase), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.StringComparison.OrdinalIgnoreCase)), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.StringComparison.OrdinalIgnoreCase; return true; - case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse( + name +#if !NETCOREAPP || NETCOREAPP2_0 || NETCOREAPP1_1 || NETCOREAPP1_0 + + .ToString() +#endif + , out var numericResult): result = (global::System.StringComparison)numericResult; return true; default: @@ -605,25 +608,31 @@ namespace System { switch (name) { - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.CurrentCulture), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.StringComparison.CurrentCulture)), global::System.StringComparison.Ordinal): result = global::System.StringComparison.CurrentCulture; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.CurrentCultureIgnoreCase), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.StringComparison.CurrentCultureIgnoreCase)), global::System.StringComparison.Ordinal): result = global::System.StringComparison.CurrentCultureIgnoreCase; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.InvariantCulture), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.StringComparison.InvariantCulture)), global::System.StringComparison.Ordinal): result = global::System.StringComparison.InvariantCulture; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.InvariantCultureIgnoreCase), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.StringComparison.InvariantCultureIgnoreCase)), global::System.StringComparison.Ordinal): result = global::System.StringComparison.InvariantCultureIgnoreCase; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.Ordinal), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.StringComparison.Ordinal)), global::System.StringComparison.Ordinal): result = global::System.StringComparison.Ordinal; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.OrdinalIgnoreCase), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.StringComparison.OrdinalIgnoreCase)), global::System.StringComparison.Ordinal): result = global::System.StringComparison.OrdinalIgnoreCase; return true; - case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse( + name +#if !NETCOREAPP || NETCOREAPP2_0 || NETCOREAPP1_1 || NETCOREAPP1_0 + + .ToString() +#endif + , out var numericResult): result = (global::System.StringComparison)numericResult; return true; default: @@ -631,7 +640,6 @@ namespace System return false; } } -#endif /// /// Retrieves an array of the values of the members defined in @@ -807,7 +815,6 @@ namespace System }; } -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Returns a boolean telling whether an enum with the given name exists in the enumeration /// @@ -829,13 +836,12 @@ namespace System { return name switch { - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.DateTimeKind.Unspecified), global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.DateTimeKind.Utc), global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.DateTimeKind.Local), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.DateTimeKind.Unspecified)), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.DateTimeKind.Utc)), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.DateTimeKind.Local)), global::System.StringComparison.Ordinal) => true, _ => false, }; } -#endif /// /// Converts the string representation of the name or numeric value of @@ -1019,7 +1025,6 @@ namespace System } } -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Converts the string representation of the name or numeric value of /// an to the equivalent instance. @@ -1148,16 +1153,22 @@ namespace System { switch (name) { - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.DateTimeKind.Unspecified), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.DateTimeKind.Unspecified)), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.DateTimeKind.Unspecified; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.DateTimeKind.Utc), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.DateTimeKind.Utc)), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.DateTimeKind.Utc; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.DateTimeKind.Local), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.DateTimeKind.Local)), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.DateTimeKind.Local; return true; - case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse( + name +#if !NETCOREAPP || NETCOREAPP2_0 || NETCOREAPP1_1 || NETCOREAPP1_0 + + .ToString() +#endif + , out var numericResult): result = (global::System.DateTimeKind)numericResult; return true; default: @@ -1176,16 +1187,22 @@ namespace System { switch (name) { - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.DateTimeKind.Unspecified), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.DateTimeKind.Unspecified)), global::System.StringComparison.Ordinal): result = global::System.DateTimeKind.Unspecified; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.DateTimeKind.Utc), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.DateTimeKind.Utc)), global::System.StringComparison.Ordinal): result = global::System.DateTimeKind.Utc; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.DateTimeKind.Local), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::System.DateTimeKind.Local)), global::System.StringComparison.Ordinal): result = global::System.DateTimeKind.Local; return true; - case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse( + name +#if !NETCOREAPP || NETCOREAPP2_0 || NETCOREAPP1_1 || NETCOREAPP1_0 + + .ToString() +#endif + , out var numericResult): result = (global::System.DateTimeKind)numericResult; return true; default: @@ -1193,7 +1210,6 @@ namespace System return false; } } -#endif /// /// Retrieves an array of the values of the members defined in diff --git a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.DoesNotInterceptToStringWhenDisabled.verified.txt b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.DoesNotInterceptToStringWhenDisabled.verified.txt index 758c8c6..465dcc7 100644 --- a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.DoesNotInterceptToStringWhenDisabled.verified.txt +++ b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.DoesNotInterceptToStringWhenDisabled.verified.txt @@ -194,7 +194,6 @@ namespace MyTestNameSpace }; } -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Returns a boolean telling whether an enum with the given name exists in the enumeration /// @@ -216,12 +215,11 @@ namespace MyTestNameSpace { return name switch { - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.First), global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Second), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.First)), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.Second)), global::System.StringComparison.Ordinal) => true, _ => false, }; } -#endif /// /// Converts the string representation of the name or numeric value of @@ -399,7 +397,6 @@ namespace MyTestNameSpace } } -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Converts the string representation of the name or numeric value of /// an to the equivalent instance. @@ -528,13 +525,19 @@ namespace MyTestNameSpace { switch (name) { - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.First), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.First)), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyTestNameSpace.MyEnum.First; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Second), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.Second)), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyTestNameSpace.MyEnum.Second; return true; - case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse( + name +#if !NETCOREAPP || NETCOREAPP2_0 || NETCOREAPP1_1 || NETCOREAPP1_0 + + .ToString() +#endif + , out var numericResult): result = (global::MyTestNameSpace.MyEnum)numericResult; return true; default: @@ -553,13 +556,19 @@ namespace MyTestNameSpace { switch (name) { - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.First), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.First)), global::System.StringComparison.Ordinal): result = global::MyTestNameSpace.MyEnum.First; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Second), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.Second)), global::System.StringComparison.Ordinal): result = global::MyTestNameSpace.MyEnum.Second; return true; - case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse( + name +#if !NETCOREAPP || NETCOREAPP2_0 || NETCOREAPP1_1 || NETCOREAPP1_0 + + .ToString() +#endif + , out var numericResult): result = (global::MyTestNameSpace.MyEnum)numericResult; return true; default: @@ -567,7 +576,6 @@ namespace MyTestNameSpace return false; } } -#endif /// /// Retrieves an array of the values of the members defined in diff --git a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.DoesNotInterceptToStringWhenOldCsharp.verified.txt b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.DoesNotInterceptToStringWhenOldCsharp.verified.txt index 758c8c6..465dcc7 100644 --- a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.DoesNotInterceptToStringWhenOldCsharp.verified.txt +++ b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.DoesNotInterceptToStringWhenOldCsharp.verified.txt @@ -194,7 +194,6 @@ namespace MyTestNameSpace }; } -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Returns a boolean telling whether an enum with the given name exists in the enumeration /// @@ -216,12 +215,11 @@ namespace MyTestNameSpace { return name switch { - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.First), global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Second), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.First)), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.Second)), global::System.StringComparison.Ordinal) => true, _ => false, }; } -#endif /// /// Converts the string representation of the name or numeric value of @@ -399,7 +397,6 @@ namespace MyTestNameSpace } } -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Converts the string representation of the name or numeric value of /// an to the equivalent instance. @@ -528,13 +525,19 @@ namespace MyTestNameSpace { switch (name) { - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.First), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.First)), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyTestNameSpace.MyEnum.First; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Second), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.Second)), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyTestNameSpace.MyEnum.Second; return true; - case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse( + name +#if !NETCOREAPP || NETCOREAPP2_0 || NETCOREAPP1_1 || NETCOREAPP1_0 + + .ToString() +#endif + , out var numericResult): result = (global::MyTestNameSpace.MyEnum)numericResult; return true; default: @@ -553,13 +556,19 @@ namespace MyTestNameSpace { switch (name) { - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.First), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.First)), global::System.StringComparison.Ordinal): result = global::MyTestNameSpace.MyEnum.First; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Second), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::MyTestNameSpace.MyEnum.Second)), global::System.StringComparison.Ordinal): result = global::MyTestNameSpace.MyEnum.Second; return true; - case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse( + name +#if !NETCOREAPP || NETCOREAPP2_0 || NETCOREAPP1_1 || NETCOREAPP1_0 + + .ToString() +#endif + , out var numericResult): result = (global::MyTestNameSpace.MyEnum)numericResult; return true; default: @@ -567,7 +576,6 @@ namespace MyTestNameSpace return false; } } -#endif /// /// Retrieves an array of the values of the members defined in diff --git a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesEnumCorrectly.verified.txt b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesEnumCorrectly.verified.txt index 8e8fd53..fe51f62 100644 --- a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesEnumCorrectly.verified.txt +++ b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesEnumCorrectly.verified.txt @@ -105,7 +105,6 @@ namespace Something.Blah }; } -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Returns a boolean telling whether an enum with the given name exists in the enumeration /// @@ -127,12 +126,11 @@ namespace Something.Blah { return name switch { - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::Something.Blah.ShortName.First), global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::Something.Blah.ShortName.Second), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::Something.Blah.ShortName.First)), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::Something.Blah.ShortName.Second)), global::System.StringComparison.Ordinal) => true, _ => false, }; } -#endif /// /// Converts the string representation of the name or numeric value of @@ -310,7 +308,6 @@ namespace Something.Blah } } -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Converts the string representation of the name or numeric value of /// an to the equivalent instance. @@ -439,13 +436,19 @@ namespace Something.Blah { switch (name) { - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::Something.Blah.ShortName.First), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::Something.Blah.ShortName.First)), global::System.StringComparison.OrdinalIgnoreCase): result = global::Something.Blah.ShortName.First; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::Something.Blah.ShortName.Second), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::Something.Blah.ShortName.Second)), global::System.StringComparison.OrdinalIgnoreCase): result = global::Something.Blah.ShortName.Second; return true; - case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse( + name +#if !NETCOREAPP || NETCOREAPP2_0 || NETCOREAPP1_1 || NETCOREAPP1_0 + + .ToString() +#endif + , out var numericResult): result = (global::Something.Blah.ShortName)numericResult; return true; default: @@ -464,13 +467,19 @@ namespace Something.Blah { switch (name) { - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::Something.Blah.ShortName.First), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::Something.Blah.ShortName.First)), global::System.StringComparison.Ordinal): result = global::Something.Blah.ShortName.First; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::Something.Blah.ShortName.Second), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::Something.Blah.ShortName.Second)), global::System.StringComparison.Ordinal): result = global::Something.Blah.ShortName.Second; return true; - case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse( + name +#if !NETCOREAPP || NETCOREAPP2_0 || NETCOREAPP1_1 || NETCOREAPP1_0 + + .ToString() +#endif + , out var numericResult): result = (global::Something.Blah.ShortName)numericResult; return true; default: @@ -478,7 +487,6 @@ namespace Something.Blah return false; } } -#endif /// /// Retrieves an array of the values of the members defined in diff --git a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesEnumWithRepeatedValuesCorrectly.verified.txt b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesEnumWithRepeatedValuesCorrectly.verified.txt index 1e59f08..86a0d0a 100644 --- a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesEnumWithRepeatedValuesCorrectly.verified.txt +++ b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesEnumWithRepeatedValuesCorrectly.verified.txt @@ -1,4 +1,4 @@ -//------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ // // This code was generated by the NetEscapades.EnumGenerators source generator // @@ -106,7 +106,6 @@ namespace Something.Blah }; } -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Returns a boolean telling whether an enum with the given name exists in the enumeration /// @@ -128,13 +127,12 @@ namespace Something.Blah { return name switch { - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::Something.Blah.ShortName.First), global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::Something.Blah.ShortName.Second), global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::Something.Blah.ShortName.Third), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::Something.Blah.ShortName.First)), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::Something.Blah.ShortName.Second)), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::Something.Blah.ShortName.Third)), global::System.StringComparison.Ordinal) => true, _ => false, }; } -#endif /// /// Converts the string representation of the name or numeric value of @@ -318,7 +316,6 @@ namespace Something.Blah } } -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Converts the string representation of the name or numeric value of /// an to the equivalent instance. @@ -447,16 +444,22 @@ namespace Something.Blah { switch (name) { - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::Something.Blah.ShortName.First), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::Something.Blah.ShortName.First)), global::System.StringComparison.OrdinalIgnoreCase): result = global::Something.Blah.ShortName.First; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::Something.Blah.ShortName.Second), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::Something.Blah.ShortName.Second)), global::System.StringComparison.OrdinalIgnoreCase): result = global::Something.Blah.ShortName.Second; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::Something.Blah.ShortName.Third), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::Something.Blah.ShortName.Third)), global::System.StringComparison.OrdinalIgnoreCase): result = global::Something.Blah.ShortName.Third; return true; - case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse( + name +#if !NETCOREAPP || NETCOREAPP2_0 || NETCOREAPP1_1 || NETCOREAPP1_0 + + .ToString() +#endif + , out var numericResult): result = (global::Something.Blah.ShortName)numericResult; return true; default: @@ -475,16 +478,22 @@ namespace Something.Blah { switch (name) { - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::Something.Blah.ShortName.First), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::Something.Blah.ShortName.First)), global::System.StringComparison.Ordinal): result = global::Something.Blah.ShortName.First; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::Something.Blah.ShortName.Second), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::Something.Blah.ShortName.Second)), global::System.StringComparison.Ordinal): result = global::Something.Blah.ShortName.Second; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::Something.Blah.ShortName.Third), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::Something.Blah.ShortName.Third)), global::System.StringComparison.Ordinal): result = global::Something.Blah.ShortName.Third; return true; - case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse( + name +#if !NETCOREAPP || NETCOREAPP2_0 || NETCOREAPP1_1 || NETCOREAPP1_0 + + .ToString() +#endif + , out var numericResult): result = (global::Something.Blah.ShortName)numericResult; return true; default: @@ -492,7 +501,6 @@ namespace Something.Blah return false; } } -#endif /// /// Retrieves an array of the values of the members defined in diff --git a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFlagsEnumCorrectly.verified.txt b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFlagsEnumCorrectly.verified.txt index 477d5bf..d510ef8 100644 --- a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFlagsEnumCorrectly.verified.txt +++ b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFlagsEnumCorrectly.verified.txt @@ -117,7 +117,6 @@ namespace Something.Blah }; } -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Returns a boolean telling whether an enum with the given name exists in the enumeration /// @@ -139,12 +138,11 @@ namespace Something.Blah { return name switch { - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::Something.Blah.ShortName.First), global::System.StringComparison.Ordinal) => true, - global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::Something.Blah.ShortName.Second), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::Something.Blah.ShortName.First)), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::Something.Blah.ShortName.Second)), global::System.StringComparison.Ordinal) => true, _ => false, }; } -#endif /// /// Converts the string representation of the name or numeric value of @@ -322,7 +320,6 @@ namespace Something.Blah } } -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Converts the string representation of the name or numeric value of /// an to the equivalent instance. @@ -451,13 +448,19 @@ namespace Something.Blah { switch (name) { - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::Something.Blah.ShortName.First), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::Something.Blah.ShortName.First)), global::System.StringComparison.OrdinalIgnoreCase): result = global::Something.Blah.ShortName.First; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::Something.Blah.ShortName.Second), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::Something.Blah.ShortName.Second)), global::System.StringComparison.OrdinalIgnoreCase): result = global::Something.Blah.ShortName.Second; return true; - case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse( + name +#if !NETCOREAPP || NETCOREAPP2_0 || NETCOREAPP1_1 || NETCOREAPP1_0 + + .ToString() +#endif + , out var numericResult): result = (global::Something.Blah.ShortName)numericResult; return true; default: @@ -476,13 +479,19 @@ namespace Something.Blah { switch (name) { - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::Something.Blah.ShortName.First), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::Something.Blah.ShortName.First)), global::System.StringComparison.Ordinal): result = global::Something.Blah.ShortName.First; return true; - case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::Something.Blah.ShortName.Second), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, global::System.MemoryExtensions.AsSpan(nameof(global::Something.Blah.ShortName.Second)), global::System.StringComparison.Ordinal): result = global::Something.Blah.ShortName.Second; return true; - case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse( + name +#if !NETCOREAPP || NETCOREAPP2_0 || NETCOREAPP1_1 || NETCOREAPP1_0 + + .ToString() +#endif + , out var numericResult): result = (global::Something.Blah.ShortName)numericResult; return true; default: @@ -490,7 +499,6 @@ namespace Something.Blah return false; } } -#endif /// /// Retrieves an array of the values of the members defined in