From 941ca0b626a1309367a7a2ffda708390c9e8b11f Mon Sep 17 00:00:00 2001 From: Andrew Lock Date: Sun, 26 Jan 2025 19:06:53 +0000 Subject: [PATCH] Fix: Don't use `using` in generated code (#129) * Remove usage of using System and replace with Global * Update snapshots * Test 2.1 just in case --- .github/workflows/BuildAndPack.yml | 1 + .../SourceGenerationHelper.cs | 56 +++--- tests/Directory.Build.props | 2 +- ...ExtensionsForFlagsEnum_Params.verified.txt | 45 +++-- ...numExtensionsInChildNamespace.verified.txt | 39 ++-- ...umExtensionsInGlobalNamespace.verified.txt | 39 ++-- ...teEnumExtensionsInNestedClass.verified.txt | 39 ++-- ...eEnumExtensionsWithCustomName.verified.txt | 39 ++-- ...EnumExtensionsWithCustomNames.verified.txt | 63 ++++--- ...ExtensionsWithCustomNamespace.verified.txt | 39 ++-- ...onsWithCustomNamespaceAndName.verified.txt | 39 ++-- ...ExtensionsWithSameDisplayName.verified.txt | 57 +++--- ...lEnumExtensionsWithCustomName.verified.txt | 45 +++-- ...ExtensionsWithCustomNamespace.verified.txt | 45 +++-- ...onsWithCustomNamespaceAndName.verified.txt | 45 +++-- ...ts.CanGenerateForExternalEnum.verified.txt | 63 ++++--- ...nGenerateForExternalFlagsEnum.verified.txt | 63 ++++--- ...erateForMultipleExternalEnums.verified.txt | 168 +++++++++--------- ...mespaceAndClassNameAreTheSame.verified.txt | 33 ++-- ...rObsoleteEnums_CS0612_Issue97.verified.txt | 39 ++-- ...rObsoleteEnums_CS0618_Issue97.verified.txt | 39 ++-- ...bsoleteMembers_CS0612_Issue97.verified.txt | 39 ++-- ...bsoleteMembers_CS0618_Issue97.verified.txt | 39 ++-- ...QuotesAndSlashesInDescription.verified.txt | 87 +++++---- ...SameNameInDifferentNamespaces.verified.txt | 90 +++++----- ...rceptEnumInDifferentNamespace.verified.txt | 45 +++-- ...nterceptEnumInGlobalNamespace.verified.txt | 45 +++-- ...InterceptExternalEnumToString.verified.txt | 63 ++++--- ...ptorTests.CanInterceptHasFlag.verified.txt | 45 +++-- ...nterceptMultipleEnumsToString.verified.txt | 90 +++++----- ...torTests.CanInterceptToString.verified.txt | 39 ++-- ...InterceptToStringWhenCsharp11.verified.txt | 39 ++-- ...nterceptableAttributeToString.verified.txt | 63 ++++--- ...EnumWithoutInterceptorPackage.verified.txt | 39 ++-- ...eptUsageInStringInterpolation.verified.txt | 41 ++--- ...nterceptUsageWithEnumDirectly.verified.txt | 41 ++--- ...fObsoleteEnums_CS0612_Issue97.verified.txt | 39 ++-- ...fObsoleteEnums_CS0618_Issue97.verified.txt | 39 ++-- ...tEnumMarkedAsNotInterceptable.verified.txt | 90 +++++----- ...lEnumMarkedAsNotInterceptable.verified.txt | 108 ++++++----- ...InterceptToStringWhenDisabled.verified.txt | 39 ++-- ...nterceptToStringWhenOldCsharp.verified.txt | 39 ++-- ...tTests.GeneratesEnumCorrectly.verified.txt | 39 ++-- ...s.GeneratesFlagsEnumCorrectly.verified.txt | 39 ++-- 44 files changed, 1046 insertions(+), 1189 deletions(-) diff --git a/.github/workflows/BuildAndPack.yml b/.github/workflows/BuildAndPack.yml index e084853..5291ac1 100644 --- a/.github/workflows/BuildAndPack.yml +++ b/.github/workflows/BuildAndPack.yml @@ -53,6 +53,7 @@ jobs: 7.0.x 6.0.x 3.1.x + 2.1.x - run: dotnet new globaljson --sdk-version "8.0.402" --force - name: Cache .nuke/temp, ~/.nuget/packages diff --git a/src/NetEscapades.EnumGenerators/SourceGenerationHelper.cs b/src/NetEscapades.EnumGenerators/SourceGenerationHelper.cs index 3c7a720..33e64f4 100644 --- a/src/NetEscapades.EnumGenerators/SourceGenerationHelper.cs +++ b/src/NetEscapades.EnumGenerators/SourceGenerationHelper.cs @@ -99,13 +99,7 @@ public class EnumExtensionsAttribute : System.Attribute public static (string Content, string HintName) GenerateExtensionClass(in EnumToGenerate enumToGenerate) { var sb = new StringBuilder(); - sb - .Append(Header) - .Append(@" -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 -using System; -#endif -"); + sb.AppendLine(Header); if (!string.IsNullOrEmpty(enumToGenerate.Namespace)) { sb.Append(@" @@ -312,7 +306,7 @@ public static bool IsDefined(string name, bool allowMatchingMetadataAttribute) /// /// The name to check if it's defined /// true if a member with the name exists in the enumeration, false otherwise - public static bool IsDefined(in ReadOnlySpan name) => IsDefined(name, allowMatchingMetadataAttribute: false); + public static bool IsDefined(in global::System.ReadOnlySpan name) => IsDefined(name, allowMatchingMetadataAttribute: false); /// /// Returns a boolean telling whether an enum with the given name exists in the enumeration, @@ -324,7 +318,7 @@ public static bool IsDefined(string name, bool allowMatchingMetadataAttribute) /// If true, considers the value of metadata attributes,otherwise ignores them /// true if a member with the name exists in the enumeration, or a member is decorated /// with a [Display] attribute with the name, false otherwise - public static bool IsDefined(in ReadOnlySpan name, bool allowMatchingMetadataAttribute) + public static bool IsDefined(in global::System.ReadOnlySpan name, bool allowMatchingMetadataAttribute) {"); if (enumToGenerate.IsDisplayAttributeUsed) @@ -340,9 +334,9 @@ public static bool IsDefined(in ReadOnlySpan name, bool allowMatchingMetad if (member.Value is { DisplayName: { } dn, IsDisplayNameTheFirstPresence: true }) { sb.Append(@" - ReadOnlySpan current when current.Equals(") + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, ") .Append(SymbolDisplay.FormatLiteral(dn, quote: true)) - .Append(@".AsSpan(), global::System.StringComparison.Ordinal) => true,"); + .Append(@", global::System.StringComparison.Ordinal) => true,"); } } @@ -364,9 +358,9 @@ ReadOnlySpan current when current.Equals(") foreach (var member in enumToGenerate.Names) { sb.Append(@" - ReadOnlySpan current when current.Equals(nameof(").Append(fullyQualifiedName).Append('.') + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(").Append(fullyQualifiedName).Append('.') .Append(member.Key) - .Append(@").AsSpan(), global::System.StringComparison.Ordinal) => true,"); + .Append(@"), global::System.StringComparison.Ordinal) => true,"); } sb.Append(@" @@ -630,7 +624,7 @@ private static bool TryParseWithCase( #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name) + in global::System.ReadOnlySpan name) => TryParse(name, out var value, false, false) ? value : ThrowValueNotFound(name.ToString()); /// @@ -645,7 +639,7 @@ private static bool TryParseWithCase( #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, bool ignoreCase) => TryParse(name, out var value, ignoreCase, false) ? value : ThrowValueNotFound(name.ToString()); @@ -663,7 +657,7 @@ private static bool TryParseWithCase( #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, bool ignoreCase, bool allowMatchingMetadataAttribute) => TryParse(name, out var value, ignoreCase, allowMatchingMetadataAttribute) ? value : ThrowValueNotFound(name.ToString()); @@ -684,7 +678,7 @@ public static bool TryParse( #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out ").Append(fullyQualifiedName).Append(@" value) => TryParse(name, out value, false, false);"); sb.Append(@" @@ -706,7 +700,7 @@ public static bool TryParse( #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out ").Append(fullyQualifiedName).Append(@" value, bool ignoreCase) => TryParse(name, out value, ignoreCase, false);"); @@ -732,7 +726,7 @@ public static bool TryParse( #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out ").Append(fullyQualifiedName).Append(@" result, bool ignoreCase, bool allowMatchingMetadataAttribute) @@ -744,7 +738,7 @@ private static bool TryParseIgnoreCase( #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out ").Append(fullyQualifiedName).Append(@" result, bool allowMatchingMetadataAttribute) {"); @@ -761,9 +755,9 @@ private static bool TryParseIgnoreCase( if (member.Value is { DisplayName: { } dn, IsDisplayNameTheFirstPresence: true }) { sb.Append(@" - case ReadOnlySpan current when current.Equals(") + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, ") .Append(SymbolDisplay.FormatLiteral(dn, quote: true)).Append( - @".AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + @", global::System.StringComparison.OrdinalIgnoreCase): result = ").Append(fullyQualifiedName).Append('.').Append(member.Key).Append(@"; return true;"); } @@ -783,15 +777,15 @@ private static bool TryParseIgnoreCase( foreach (var member in enumToGenerate.Names) { sb.Append(@" - case ReadOnlySpan current when current.Equals(nameof(").Append(fullyQualifiedName).Append('.') + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(").Append(fullyQualifiedName).Append('.') .Append(member.Key).Append( - @").AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + @"), global::System.StringComparison.OrdinalIgnoreCase): result = ").Append(fullyQualifiedName).Append('.').Append(member.Key).Append(@"; return true;"); } sb.Append(@" - case ReadOnlySpan current when ").Append(enumToGenerate.UnderlyingType).Append( + case global::System.ReadOnlySpan current when ").Append(enumToGenerate.UnderlyingType).Append( @".TryParse(name, out var numericResult): result = (").Append(fullyQualifiedName).Append(@")numericResult; return true; @@ -805,7 +799,7 @@ private static bool TryParseWithCase( #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out ").Append(fullyQualifiedName).Append(@" result, bool allowMatchingMetadataAttribute) {"); @@ -822,9 +816,9 @@ private static bool TryParseWithCase( if (member.Value is { DisplayName: { } dn, IsDisplayNameTheFirstPresence: true }) { sb.Append(@" - case ReadOnlySpan current when current.Equals(") + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, ") .Append(SymbolDisplay.FormatLiteral(dn, quote: true)).Append( - @".AsSpan(), global::System.StringComparison.Ordinal): + @", global::System.StringComparison.Ordinal): result = ").Append(fullyQualifiedName).Append('.').Append(member.Key).Append(@"; return true;"); } @@ -844,15 +838,15 @@ private static bool TryParseWithCase( foreach (var member in enumToGenerate.Names) { sb.Append(@" - case ReadOnlySpan current when current.Equals(nameof(").Append(fullyQualifiedName).Append('.') + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(").Append(fullyQualifiedName).Append('.') .Append(member.Key).Append( - @").AsSpan(), global::System.StringComparison.Ordinal): + @"), global::System.StringComparison.Ordinal): result = ").Append(fullyQualifiedName).Append('.').Append(member.Key).Append(@"; return true;"); } sb.Append(@" - case ReadOnlySpan current when ").Append(enumToGenerate.UnderlyingType).Append( + case global::System.ReadOnlySpan current when ").Append(enumToGenerate.UnderlyingType).Append( @".TryParse(name, out var numericResult): result = (").Append(fullyQualifiedName).Append(@")numericResult; return true; diff --git a/tests/Directory.Build.props b/tests/Directory.Build.props index 1ad6d66..9a25cb7 100644 --- a/tests/Directory.Build.props +++ b/tests/Directory.Build.props @@ -7,7 +7,7 @@ true NU1901;NU1902;NU1903;NU1904 net6.0;net7.0;net8.0 - net48;netcoreapp3.1;$(TargetFrameworks) + net48;netcoreapp2.1;netcoreapp3.1;$(TargetFrameworks) 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 a9d24e9..5415d9f 100644 --- a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsForFlagsEnum_Params.verified.txt +++ b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsForFlagsEnum_Params.verified.txt @@ -8,9 +8,6 @@ //------------------------------------------------------------------------------ #nullable enable -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 -using System; -#endif namespace MyTestNameSpace { @@ -119,7 +116,7 @@ namespace MyTestNameSpace /// /// The name to check if it's defined /// true if a member with the name exists in the enumeration, false otherwise - public static bool IsDefined(in ReadOnlySpan name) => IsDefined(name, allowMatchingMetadataAttribute: false); + public static bool IsDefined(in global::System.ReadOnlySpan name) => IsDefined(name, allowMatchingMetadataAttribute: false); /// /// Returns a boolean telling whether an enum with the given name exists in the enumeration, @@ -131,13 +128,13 @@ namespace MyTestNameSpace /// If true, considers the value of metadata attributes,otherwise ignores them /// true if a member with the name exists in the enumeration, or a member is decorated /// with a [Display] attribute with the name, false otherwise - public static bool IsDefined(in ReadOnlySpan name, bool allowMatchingMetadataAttribute) + public static bool IsDefined(in global::System.ReadOnlySpan name, bool allowMatchingMetadataAttribute) { return name switch { - ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.First).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.Second).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.Third).AsSpan(), global::System.StringComparison.Ordinal) => true, + 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, _ => false, }; } @@ -337,7 +334,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name) + in global::System.ReadOnlySpan name) => TryParse(name, out var value, false, false) ? value : ThrowValueNotFound(name.ToString()); /// @@ -352,7 +349,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, bool ignoreCase) => TryParse(name, out var value, ignoreCase, false) ? value : ThrowValueNotFound(name.ToString()); @@ -370,7 +367,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, bool ignoreCase, bool allowMatchingMetadataAttribute) => TryParse(name, out var value, ignoreCase, allowMatchingMetadataAttribute) ? value : ThrowValueNotFound(name.ToString()); @@ -391,7 +388,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyTestNameSpace.MyEnum value) => TryParse(name, out value, false, false); @@ -412,7 +409,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyTestNameSpace.MyEnum value, bool ignoreCase) => TryParse(name, out value, ignoreCase, false); @@ -436,7 +433,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyTestNameSpace.MyEnum result, bool ignoreCase, bool allowMatchingMetadataAttribute) @@ -448,22 +445,22 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyTestNameSpace.MyEnum result, bool allowMatchingMetadataAttribute) { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.First).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.First), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyTestNameSpace.MyEnum.First; return true; - case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.Second).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Second), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyTestNameSpace.MyEnum.Second; return true; - case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.Third).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Third), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyTestNameSpace.MyEnum.Third; return true; - case ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): result = (global::MyTestNameSpace.MyEnum)numericResult; return true; default: @@ -476,22 +473,22 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyTestNameSpace.MyEnum result, bool allowMatchingMetadataAttribute) { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.First).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.First), global::System.StringComparison.Ordinal): result = global::MyTestNameSpace.MyEnum.First; return true; - case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.Second).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Second), global::System.StringComparison.Ordinal): result = global::MyTestNameSpace.MyEnum.Second; return true; - case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.Third).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Third), global::System.StringComparison.Ordinal): result = global::MyTestNameSpace.MyEnum.Third; return true; - case ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): result = (global::MyTestNameSpace.MyEnum)numericResult; return true; default: diff --git a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsInChildNamespace.verified.txt b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsInChildNamespace.verified.txt index e7d0103..df1cd12 100644 --- a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsInChildNamespace.verified.txt +++ b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsInChildNamespace.verified.txt @@ -8,9 +8,6 @@ //------------------------------------------------------------------------------ #nullable enable -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 -using System; -#endif namespace MyTestNameSpace { @@ -104,7 +101,7 @@ namespace MyTestNameSpace /// /// The name to check if it's defined /// true if a member with the name exists in the enumeration, false otherwise - public static bool IsDefined(in ReadOnlySpan name) => IsDefined(name, allowMatchingMetadataAttribute: false); + public static bool IsDefined(in global::System.ReadOnlySpan name) => IsDefined(name, allowMatchingMetadataAttribute: false); /// /// Returns a boolean telling whether an enum with the given name exists in the enumeration, @@ -116,12 +113,12 @@ namespace MyTestNameSpace /// If true, considers the value of metadata attributes,otherwise ignores them /// true if a member with the name exists in the enumeration, or a member is decorated /// with a [Display] attribute with the name, false otherwise - public static bool IsDefined(in ReadOnlySpan name, bool allowMatchingMetadataAttribute) + public static bool IsDefined(in global::System.ReadOnlySpan name, bool allowMatchingMetadataAttribute) { return name switch { - ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.First).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.Second).AsSpan(), global::System.StringComparison.Ordinal) => true, + 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, _ => false, }; } @@ -315,7 +312,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name) + in global::System.ReadOnlySpan name) => TryParse(name, out var value, false, false) ? value : ThrowValueNotFound(name.ToString()); /// @@ -330,7 +327,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, bool ignoreCase) => TryParse(name, out var value, ignoreCase, false) ? value : ThrowValueNotFound(name.ToString()); @@ -348,7 +345,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, bool ignoreCase, bool allowMatchingMetadataAttribute) => TryParse(name, out var value, ignoreCase, allowMatchingMetadataAttribute) ? value : ThrowValueNotFound(name.ToString()); @@ -369,7 +366,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyTestNameSpace.MyEnum value) => TryParse(name, out value, false, false); @@ -390,7 +387,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyTestNameSpace.MyEnum value, bool ignoreCase) => TryParse(name, out value, ignoreCase, false); @@ -414,7 +411,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyTestNameSpace.MyEnum result, bool ignoreCase, bool allowMatchingMetadataAttribute) @@ -426,19 +423,19 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyTestNameSpace.MyEnum result, bool allowMatchingMetadataAttribute) { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.First).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.First), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyTestNameSpace.MyEnum.First; return true; - case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.Second).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Second), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyTestNameSpace.MyEnum.Second; return true; - case ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): result = (global::MyTestNameSpace.MyEnum)numericResult; return true; default: @@ -451,19 +448,19 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyTestNameSpace.MyEnum result, bool allowMatchingMetadataAttribute) { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.First).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.First), global::System.StringComparison.Ordinal): result = global::MyTestNameSpace.MyEnum.First; return true; - case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.Second).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Second), global::System.StringComparison.Ordinal): result = global::MyTestNameSpace.MyEnum.Second; return true; - case ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): result = (global::MyTestNameSpace.MyEnum)numericResult; return true; default: diff --git a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsInGlobalNamespace.verified.txt b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsInGlobalNamespace.verified.txt index 0e104bc..3237afb 100644 --- a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsInGlobalNamespace.verified.txt +++ b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsInGlobalNamespace.verified.txt @@ -8,9 +8,6 @@ //------------------------------------------------------------------------------ #nullable enable -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 -using System; -#endif #pragma warning disable CS0612 // Ignore usages of obsolete members or enums #pragma warning disable CS0618 // Ignore usages of obsolete members or enums @@ -102,7 +99,7 @@ using System; /// /// The name to check if it's defined /// true if a member with the name exists in the enumeration, false otherwise - public static bool IsDefined(in ReadOnlySpan name) => IsDefined(name, allowMatchingMetadataAttribute: false); + public static bool IsDefined(in global::System.ReadOnlySpan name) => IsDefined(name, allowMatchingMetadataAttribute: false); /// /// Returns a boolean telling whether an enum with the given name exists in the enumeration, @@ -114,12 +111,12 @@ using System; /// If true, considers the value of metadata attributes,otherwise ignores them /// true if a member with the name exists in the enumeration, or a member is decorated /// with a [Display] attribute with the name, false otherwise - public static bool IsDefined(in ReadOnlySpan name, bool allowMatchingMetadataAttribute) + public static bool IsDefined(in global::System.ReadOnlySpan name, bool allowMatchingMetadataAttribute) { return name switch { - ReadOnlySpan current when current.Equals(nameof(global::MyEnum.First).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(global::MyEnum.Second).AsSpan(), global::System.StringComparison.Ordinal) => true, + 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, _ => false, }; } @@ -313,7 +310,7 @@ using System; #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name) + in global::System.ReadOnlySpan name) => TryParse(name, out var value, false, false) ? value : ThrowValueNotFound(name.ToString()); /// @@ -328,7 +325,7 @@ using System; #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, bool ignoreCase) => TryParse(name, out var value, ignoreCase, false) ? value : ThrowValueNotFound(name.ToString()); @@ -346,7 +343,7 @@ using System; #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, bool ignoreCase, bool allowMatchingMetadataAttribute) => TryParse(name, out var value, ignoreCase, allowMatchingMetadataAttribute) ? value : ThrowValueNotFound(name.ToString()); @@ -367,7 +364,7 @@ using System; #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyEnum value) => TryParse(name, out value, false, false); @@ -388,7 +385,7 @@ using System; #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyEnum value, bool ignoreCase) => TryParse(name, out value, ignoreCase, false); @@ -412,7 +409,7 @@ using System; #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyEnum result, bool ignoreCase, bool allowMatchingMetadataAttribute) @@ -424,19 +421,19 @@ using System; #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyEnum result, bool allowMatchingMetadataAttribute) { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(global::MyEnum.First).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyEnum.First), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyEnum.First; return true; - case ReadOnlySpan current when current.Equals(nameof(global::MyEnum.Second).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyEnum.Second), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyEnum.Second; return true; - case ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): result = (global::MyEnum)numericResult; return true; default: @@ -449,19 +446,19 @@ using System; #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyEnum result, bool allowMatchingMetadataAttribute) { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(global::MyEnum.First).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyEnum.First), global::System.StringComparison.Ordinal): result = global::MyEnum.First; return true; - case ReadOnlySpan current when current.Equals(nameof(global::MyEnum.Second).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyEnum.Second), global::System.StringComparison.Ordinal): result = global::MyEnum.Second; return true; - case ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): result = (global::MyEnum)numericResult; return true; default: diff --git a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsInNestedClass.verified.txt b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsInNestedClass.verified.txt index 00747e2..6a34af1 100644 --- a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsInNestedClass.verified.txt +++ b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsInNestedClass.verified.txt @@ -8,9 +8,6 @@ //------------------------------------------------------------------------------ #nullable enable -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 -using System; -#endif namespace MyTestNameSpace { @@ -104,7 +101,7 @@ namespace MyTestNameSpace /// /// The name to check if it's defined /// true if a member with the name exists in the enumeration, false otherwise - public static bool IsDefined(in ReadOnlySpan name) => IsDefined(name, allowMatchingMetadataAttribute: false); + public static bool IsDefined(in global::System.ReadOnlySpan name) => IsDefined(name, allowMatchingMetadataAttribute: false); /// /// Returns a boolean telling whether an enum with the given name exists in the enumeration, @@ -116,12 +113,12 @@ namespace MyTestNameSpace /// If true, considers the value of metadata attributes,otherwise ignores them /// true if a member with the name exists in the enumeration, or a member is decorated /// with a [Display] attribute with the name, false otherwise - public static bool IsDefined(in ReadOnlySpan name, bool allowMatchingMetadataAttribute) + public static bool IsDefined(in global::System.ReadOnlySpan name, bool allowMatchingMetadataAttribute) { return name switch { - ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.InnerClass.MyEnum.First).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.InnerClass.MyEnum.Second).AsSpan(), global::System.StringComparison.Ordinal) => true, + 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, _ => false, }; } @@ -315,7 +312,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name) + in global::System.ReadOnlySpan name) => TryParse(name, out var value, false, false) ? value : ThrowValueNotFound(name.ToString()); /// @@ -330,7 +327,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, bool ignoreCase) => TryParse(name, out var value, ignoreCase, false) ? value : ThrowValueNotFound(name.ToString()); @@ -348,7 +345,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, bool ignoreCase, bool allowMatchingMetadataAttribute) => TryParse(name, out var value, ignoreCase, allowMatchingMetadataAttribute) ? value : ThrowValueNotFound(name.ToString()); @@ -369,7 +366,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyTestNameSpace.InnerClass.MyEnum value) => TryParse(name, out value, false, false); @@ -390,7 +387,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyTestNameSpace.InnerClass.MyEnum value, bool ignoreCase) => TryParse(name, out value, ignoreCase, false); @@ -414,7 +411,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyTestNameSpace.InnerClass.MyEnum result, bool ignoreCase, bool allowMatchingMetadataAttribute) @@ -426,19 +423,19 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyTestNameSpace.InnerClass.MyEnum result, bool allowMatchingMetadataAttribute) { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.InnerClass.MyEnum.First).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.InnerClass.MyEnum.First), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyTestNameSpace.InnerClass.MyEnum.First; return true; - case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.InnerClass.MyEnum.Second).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.InnerClass.MyEnum.Second), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyTestNameSpace.InnerClass.MyEnum.Second; return true; - case ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): result = (global::MyTestNameSpace.InnerClass.MyEnum)numericResult; return true; default: @@ -451,19 +448,19 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyTestNameSpace.InnerClass.MyEnum result, bool allowMatchingMetadataAttribute) { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.InnerClass.MyEnum.First).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.InnerClass.MyEnum.First), global::System.StringComparison.Ordinal): result = global::MyTestNameSpace.InnerClass.MyEnum.First; return true; - case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.InnerClass.MyEnum.Second).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.InnerClass.MyEnum.Second), global::System.StringComparison.Ordinal): result = global::MyTestNameSpace.InnerClass.MyEnum.Second; return true; - case ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): result = (global::MyTestNameSpace.InnerClass.MyEnum)numericResult; return true; default: diff --git a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsWithCustomName.verified.txt b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsWithCustomName.verified.txt index b72a756..8621d6b 100644 --- a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsWithCustomName.verified.txt +++ b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsWithCustomName.verified.txt @@ -8,9 +8,6 @@ //------------------------------------------------------------------------------ #nullable enable -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 -using System; -#endif namespace MyTestNameSpace { @@ -104,7 +101,7 @@ namespace MyTestNameSpace /// /// The name to check if it's defined /// true if a member with the name exists in the enumeration, false otherwise - public static bool IsDefined(in ReadOnlySpan name) => IsDefined(name, allowMatchingMetadataAttribute: false); + public static bool IsDefined(in global::System.ReadOnlySpan name) => IsDefined(name, allowMatchingMetadataAttribute: false); /// /// Returns a boolean telling whether an enum with the given name exists in the enumeration, @@ -116,12 +113,12 @@ namespace MyTestNameSpace /// If true, considers the value of metadata attributes,otherwise ignores them /// true if a member with the name exists in the enumeration, or a member is decorated /// with a [Display] attribute with the name, false otherwise - public static bool IsDefined(in ReadOnlySpan name, bool allowMatchingMetadataAttribute) + public static bool IsDefined(in global::System.ReadOnlySpan name, bool allowMatchingMetadataAttribute) { return name switch { - ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.First).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.Second).AsSpan(), global::System.StringComparison.Ordinal) => true, + 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, _ => false, }; } @@ -315,7 +312,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name) + in global::System.ReadOnlySpan name) => TryParse(name, out var value, false, false) ? value : ThrowValueNotFound(name.ToString()); /// @@ -330,7 +327,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, bool ignoreCase) => TryParse(name, out var value, ignoreCase, false) ? value : ThrowValueNotFound(name.ToString()); @@ -348,7 +345,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, bool ignoreCase, bool allowMatchingMetadataAttribute) => TryParse(name, out var value, ignoreCase, allowMatchingMetadataAttribute) ? value : ThrowValueNotFound(name.ToString()); @@ -369,7 +366,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyTestNameSpace.MyEnum value) => TryParse(name, out value, false, false); @@ -390,7 +387,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyTestNameSpace.MyEnum value, bool ignoreCase) => TryParse(name, out value, ignoreCase, false); @@ -414,7 +411,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyTestNameSpace.MyEnum result, bool ignoreCase, bool allowMatchingMetadataAttribute) @@ -426,19 +423,19 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyTestNameSpace.MyEnum result, bool allowMatchingMetadataAttribute) { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.First).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.First), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyTestNameSpace.MyEnum.First; return true; - case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.Second).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Second), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyTestNameSpace.MyEnum.Second; return true; - case ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): result = (global::MyTestNameSpace.MyEnum)numericResult; return true; default: @@ -451,19 +448,19 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyTestNameSpace.MyEnum result, bool allowMatchingMetadataAttribute) { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.First).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.First), global::System.StringComparison.Ordinal): result = global::MyTestNameSpace.MyEnum.First; return true; - case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.Second).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Second), global::System.StringComparison.Ordinal): result = global::MyTestNameSpace.MyEnum.Second; return true; - case ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): result = (global::MyTestNameSpace.MyEnum)numericResult; return true; default: diff --git a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsWithCustomNames.verified.txt b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsWithCustomNames.verified.txt index 0c06111..bfdb0c7 100644 --- a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsWithCustomNames.verified.txt +++ b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsWithCustomNames.verified.txt @@ -8,9 +8,6 @@ //------------------------------------------------------------------------------ #nullable enable -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 -using System; -#endif namespace MyTestNameSpace { @@ -134,7 +131,7 @@ namespace MyTestNameSpace /// /// The name to check if it's defined /// true if a member with the name exists in the enumeration, false otherwise - public static bool IsDefined(in ReadOnlySpan name) => IsDefined(name, allowMatchingMetadataAttribute: false); + public static bool IsDefined(in global::System.ReadOnlySpan name) => IsDefined(name, allowMatchingMetadataAttribute: false); /// /// Returns a boolean telling whether an enum with the given name exists in the enumeration, @@ -146,15 +143,15 @@ namespace MyTestNameSpace /// If true, considers the value of metadata attributes,otherwise ignores them /// true if a member with the name exists in the enumeration, or a member is decorated /// with a [Display] attribute with the name, false otherwise - public static bool IsDefined(in ReadOnlySpan name, bool allowMatchingMetadataAttribute) + public static bool IsDefined(in global::System.ReadOnlySpan name, bool allowMatchingMetadataAttribute) { var isDefinedInDisplayAttribute = false; if (allowMatchingMetadataAttribute) { isDefinedInDisplayAttribute = name switch { - ReadOnlySpan current when current.Equals("2nd".AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals("4th".AsSpan(), global::System.StringComparison.Ordinal) => true, + 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, _ => false, }; } @@ -166,10 +163,10 @@ namespace MyTestNameSpace return name switch { - ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.First).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.Second).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.Third).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.Fourth).AsSpan(), global::System.StringComparison.Ordinal) => true, + 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, _ => false, }; } @@ -403,7 +400,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name) + in global::System.ReadOnlySpan name) => TryParse(name, out var value, false, false) ? value : ThrowValueNotFound(name.ToString()); /// @@ -418,7 +415,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, bool ignoreCase) => TryParse(name, out var value, ignoreCase, false) ? value : ThrowValueNotFound(name.ToString()); @@ -436,7 +433,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, bool ignoreCase, bool allowMatchingMetadataAttribute) => TryParse(name, out var value, ignoreCase, allowMatchingMetadataAttribute) ? value : ThrowValueNotFound(name.ToString()); @@ -457,7 +454,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyTestNameSpace.MyEnum value) => TryParse(name, out value, false, false); @@ -478,7 +475,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyTestNameSpace.MyEnum value, bool ignoreCase) => TryParse(name, out value, ignoreCase, false); @@ -502,7 +499,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyTestNameSpace.MyEnum result, bool ignoreCase, bool allowMatchingMetadataAttribute) @@ -514,7 +511,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyTestNameSpace.MyEnum result, bool allowMatchingMetadataAttribute) { @@ -522,10 +519,10 @@ namespace MyTestNameSpace { switch (name) { - case ReadOnlySpan current when current.Equals("2nd".AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, "2nd", global::System.StringComparison.OrdinalIgnoreCase): result = global::MyTestNameSpace.MyEnum.Second; return true; - case ReadOnlySpan current when current.Equals("4th".AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, "4th", global::System.StringComparison.OrdinalIgnoreCase): result = global::MyTestNameSpace.MyEnum.Fourth; return true; default: @@ -535,19 +532,19 @@ namespace MyTestNameSpace switch (name) { - case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.First).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.First), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyTestNameSpace.MyEnum.First; return true; - case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.Second).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Second), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyTestNameSpace.MyEnum.Second; return true; - case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.Third).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Third), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyTestNameSpace.MyEnum.Third; return true; - case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.Fourth).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Fourth), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyTestNameSpace.MyEnum.Fourth; return true; - case ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): result = (global::MyTestNameSpace.MyEnum)numericResult; return true; default: @@ -560,7 +557,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyTestNameSpace.MyEnum result, bool allowMatchingMetadataAttribute) { @@ -568,10 +565,10 @@ namespace MyTestNameSpace { switch (name) { - case ReadOnlySpan current when current.Equals("2nd".AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, "2nd", global::System.StringComparison.Ordinal): result = global::MyTestNameSpace.MyEnum.Second; return true; - case ReadOnlySpan current when current.Equals("4th".AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, "4th", global::System.StringComparison.Ordinal): result = global::MyTestNameSpace.MyEnum.Fourth; return true; default: @@ -581,19 +578,19 @@ namespace MyTestNameSpace switch (name) { - case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.First).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.First), global::System.StringComparison.Ordinal): result = global::MyTestNameSpace.MyEnum.First; return true; - case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.Second).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Second), global::System.StringComparison.Ordinal): result = global::MyTestNameSpace.MyEnum.Second; return true; - case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.Third).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Third), global::System.StringComparison.Ordinal): result = global::MyTestNameSpace.MyEnum.Third; return true; - case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.Fourth).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Fourth), global::System.StringComparison.Ordinal): result = global::MyTestNameSpace.MyEnum.Fourth; return true; - case ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): result = (global::MyTestNameSpace.MyEnum)numericResult; return true; default: diff --git a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsWithCustomNamespace.verified.txt b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsWithCustomNamespace.verified.txt index 632762d..eeb44b2 100644 --- a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsWithCustomNamespace.verified.txt +++ b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsWithCustomNamespace.verified.txt @@ -8,9 +8,6 @@ //------------------------------------------------------------------------------ #nullable enable -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 -using System; -#endif namespace A.B { @@ -104,7 +101,7 @@ namespace A.B /// /// The name to check if it's defined /// true if a member with the name exists in the enumeration, false otherwise - public static bool IsDefined(in ReadOnlySpan name) => IsDefined(name, allowMatchingMetadataAttribute: false); + public static bool IsDefined(in global::System.ReadOnlySpan name) => IsDefined(name, allowMatchingMetadataAttribute: false); /// /// Returns a boolean telling whether an enum with the given name exists in the enumeration, @@ -116,12 +113,12 @@ namespace A.B /// If true, considers the value of metadata attributes,otherwise ignores them /// true if a member with the name exists in the enumeration, or a member is decorated /// with a [Display] attribute with the name, false otherwise - public static bool IsDefined(in ReadOnlySpan name, bool allowMatchingMetadataAttribute) + public static bool IsDefined(in global::System.ReadOnlySpan name, bool allowMatchingMetadataAttribute) { return name switch { - ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.First).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.Second).AsSpan(), global::System.StringComparison.Ordinal) => true, + 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, _ => false, }; } @@ -315,7 +312,7 @@ namespace A.B #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name) + in global::System.ReadOnlySpan name) => TryParse(name, out var value, false, false) ? value : ThrowValueNotFound(name.ToString()); /// @@ -330,7 +327,7 @@ namespace A.B #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, bool ignoreCase) => TryParse(name, out var value, ignoreCase, false) ? value : ThrowValueNotFound(name.ToString()); @@ -348,7 +345,7 @@ namespace A.B #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, bool ignoreCase, bool allowMatchingMetadataAttribute) => TryParse(name, out var value, ignoreCase, allowMatchingMetadataAttribute) ? value : ThrowValueNotFound(name.ToString()); @@ -369,7 +366,7 @@ namespace A.B #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyTestNameSpace.MyEnum value) => TryParse(name, out value, false, false); @@ -390,7 +387,7 @@ namespace A.B #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyTestNameSpace.MyEnum value, bool ignoreCase) => TryParse(name, out value, ignoreCase, false); @@ -414,7 +411,7 @@ namespace A.B #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyTestNameSpace.MyEnum result, bool ignoreCase, bool allowMatchingMetadataAttribute) @@ -426,19 +423,19 @@ namespace A.B #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyTestNameSpace.MyEnum result, bool allowMatchingMetadataAttribute) { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.First).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.First), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyTestNameSpace.MyEnum.First; return true; - case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.Second).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Second), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyTestNameSpace.MyEnum.Second; return true; - case ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): result = (global::MyTestNameSpace.MyEnum)numericResult; return true; default: @@ -451,19 +448,19 @@ namespace A.B #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyTestNameSpace.MyEnum result, bool allowMatchingMetadataAttribute) { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.First).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.First), global::System.StringComparison.Ordinal): result = global::MyTestNameSpace.MyEnum.First; return true; - case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.Second).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Second), global::System.StringComparison.Ordinal): result = global::MyTestNameSpace.MyEnum.Second; return true; - case ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): result = (global::MyTestNameSpace.MyEnum)numericResult; return true; default: diff --git a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsWithCustomNamespaceAndName.verified.txt b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsWithCustomNamespaceAndName.verified.txt index c0758f6..c48194e 100644 --- a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsWithCustomNamespaceAndName.verified.txt +++ b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsWithCustomNamespaceAndName.verified.txt @@ -8,9 +8,6 @@ //------------------------------------------------------------------------------ #nullable enable -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 -using System; -#endif namespace A.B { @@ -104,7 +101,7 @@ namespace A.B /// /// The name to check if it's defined /// true if a member with the name exists in the enumeration, false otherwise - public static bool IsDefined(in ReadOnlySpan name) => IsDefined(name, allowMatchingMetadataAttribute: false); + public static bool IsDefined(in global::System.ReadOnlySpan name) => IsDefined(name, allowMatchingMetadataAttribute: false); /// /// Returns a boolean telling whether an enum with the given name exists in the enumeration, @@ -116,12 +113,12 @@ namespace A.B /// If true, considers the value of metadata attributes,otherwise ignores them /// true if a member with the name exists in the enumeration, or a member is decorated /// with a [Display] attribute with the name, false otherwise - public static bool IsDefined(in ReadOnlySpan name, bool allowMatchingMetadataAttribute) + public static bool IsDefined(in global::System.ReadOnlySpan name, bool allowMatchingMetadataAttribute) { return name switch { - ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.First).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.Second).AsSpan(), global::System.StringComparison.Ordinal) => true, + 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, _ => false, }; } @@ -315,7 +312,7 @@ namespace A.B #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name) + in global::System.ReadOnlySpan name) => TryParse(name, out var value, false, false) ? value : ThrowValueNotFound(name.ToString()); /// @@ -330,7 +327,7 @@ namespace A.B #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, bool ignoreCase) => TryParse(name, out var value, ignoreCase, false) ? value : ThrowValueNotFound(name.ToString()); @@ -348,7 +345,7 @@ namespace A.B #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, bool ignoreCase, bool allowMatchingMetadataAttribute) => TryParse(name, out var value, ignoreCase, allowMatchingMetadataAttribute) ? value : ThrowValueNotFound(name.ToString()); @@ -369,7 +366,7 @@ namespace A.B #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyTestNameSpace.MyEnum value) => TryParse(name, out value, false, false); @@ -390,7 +387,7 @@ namespace A.B #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyTestNameSpace.MyEnum value, bool ignoreCase) => TryParse(name, out value, ignoreCase, false); @@ -414,7 +411,7 @@ namespace A.B #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyTestNameSpace.MyEnum result, bool ignoreCase, bool allowMatchingMetadataAttribute) @@ -426,19 +423,19 @@ namespace A.B #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyTestNameSpace.MyEnum result, bool allowMatchingMetadataAttribute) { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.First).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.First), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyTestNameSpace.MyEnum.First; return true; - case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.Second).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Second), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyTestNameSpace.MyEnum.Second; return true; - case ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): result = (global::MyTestNameSpace.MyEnum)numericResult; return true; default: @@ -451,19 +448,19 @@ namespace A.B #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyTestNameSpace.MyEnum result, bool allowMatchingMetadataAttribute) { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.First).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.First), global::System.StringComparison.Ordinal): result = global::MyTestNameSpace.MyEnum.First; return true; - case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.Second).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Second), global::System.StringComparison.Ordinal): result = global::MyTestNameSpace.MyEnum.Second; return true; - case ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): result = (global::MyTestNameSpace.MyEnum)numericResult; return true; default: diff --git a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsWithSameDisplayName.verified.txt b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsWithSameDisplayName.verified.txt index 8d2e794..d515f8a 100644 --- a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsWithSameDisplayName.verified.txt +++ b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsWithSameDisplayName.verified.txt @@ -8,9 +8,6 @@ //------------------------------------------------------------------------------ #nullable enable -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 -using System; -#endif namespace MyTestNameSpace { @@ -133,7 +130,7 @@ namespace MyTestNameSpace /// /// The name to check if it's defined /// true if a member with the name exists in the enumeration, false otherwise - public static bool IsDefined(in ReadOnlySpan name) => IsDefined(name, allowMatchingMetadataAttribute: false); + public static bool IsDefined(in global::System.ReadOnlySpan name) => IsDefined(name, allowMatchingMetadataAttribute: false); /// /// Returns a boolean telling whether an enum with the given name exists in the enumeration, @@ -145,14 +142,14 @@ namespace MyTestNameSpace /// If true, considers the value of metadata attributes,otherwise ignores them /// true if a member with the name exists in the enumeration, or a member is decorated /// with a [Display] attribute with the name, false otherwise - public static bool IsDefined(in ReadOnlySpan name, bool allowMatchingMetadataAttribute) + public static bool IsDefined(in global::System.ReadOnlySpan name, bool allowMatchingMetadataAttribute) { var isDefinedInDisplayAttribute = false; if (allowMatchingMetadataAttribute) { isDefinedInDisplayAttribute = name switch { - ReadOnlySpan current when current.Equals("2nd".AsSpan(), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, "2nd", global::System.StringComparison.Ordinal) => true, _ => false, }; } @@ -164,10 +161,10 @@ namespace MyTestNameSpace return name switch { - ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.First).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.Second).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.Third).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.Fourth).AsSpan(), global::System.StringComparison.Ordinal) => true, + 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, _ => false, }; } @@ -395,7 +392,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name) + in global::System.ReadOnlySpan name) => TryParse(name, out var value, false, false) ? value : ThrowValueNotFound(name.ToString()); /// @@ -410,7 +407,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, bool ignoreCase) => TryParse(name, out var value, ignoreCase, false) ? value : ThrowValueNotFound(name.ToString()); @@ -428,7 +425,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, bool ignoreCase, bool allowMatchingMetadataAttribute) => TryParse(name, out var value, ignoreCase, allowMatchingMetadataAttribute) ? value : ThrowValueNotFound(name.ToString()); @@ -449,7 +446,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyTestNameSpace.MyEnum value) => TryParse(name, out value, false, false); @@ -470,7 +467,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyTestNameSpace.MyEnum value, bool ignoreCase) => TryParse(name, out value, ignoreCase, false); @@ -494,7 +491,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyTestNameSpace.MyEnum result, bool ignoreCase, bool allowMatchingMetadataAttribute) @@ -506,7 +503,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyTestNameSpace.MyEnum result, bool allowMatchingMetadataAttribute) { @@ -514,7 +511,7 @@ namespace MyTestNameSpace { switch (name) { - case ReadOnlySpan current when current.Equals("2nd".AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, "2nd", global::System.StringComparison.OrdinalIgnoreCase): result = global::MyTestNameSpace.MyEnum.Second; return true; default: @@ -524,19 +521,19 @@ namespace MyTestNameSpace switch (name) { - case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.First).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.First), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyTestNameSpace.MyEnum.First; return true; - case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.Second).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Second), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyTestNameSpace.MyEnum.Second; return true; - case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.Third).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Third), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyTestNameSpace.MyEnum.Third; return true; - case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.Fourth).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Fourth), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyTestNameSpace.MyEnum.Fourth; return true; - case ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): result = (global::MyTestNameSpace.MyEnum)numericResult; return true; default: @@ -549,7 +546,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyTestNameSpace.MyEnum result, bool allowMatchingMetadataAttribute) { @@ -557,7 +554,7 @@ namespace MyTestNameSpace { switch (name) { - case ReadOnlySpan current when current.Equals("2nd".AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, "2nd", global::System.StringComparison.Ordinal): result = global::MyTestNameSpace.MyEnum.Second; return true; default: @@ -567,19 +564,19 @@ namespace MyTestNameSpace switch (name) { - case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.First).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.First), global::System.StringComparison.Ordinal): result = global::MyTestNameSpace.MyEnum.First; return true; - case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.Second).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Second), global::System.StringComparison.Ordinal): result = global::MyTestNameSpace.MyEnum.Second; return true; - case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.Third).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Third), global::System.StringComparison.Ordinal): result = global::MyTestNameSpace.MyEnum.Third; return true; - case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.Fourth).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Fourth), global::System.StringComparison.Ordinal): result = global::MyTestNameSpace.MyEnum.Fourth; return true; - case ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): result = (global::MyTestNameSpace.MyEnum)numericResult; return true; default: diff --git a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateExternalEnumExtensionsWithCustomName.verified.txt b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateExternalEnumExtensionsWithCustomName.verified.txt index ae2ca4b..b7180e8 100644 --- a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateExternalEnumExtensionsWithCustomName.verified.txt +++ b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateExternalEnumExtensionsWithCustomName.verified.txt @@ -8,9 +8,6 @@ //------------------------------------------------------------------------------ #nullable enable -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 -using System; -#endif namespace System { @@ -107,7 +104,7 @@ namespace System /// /// The name to check if it's defined /// true if a member with the name exists in the enumeration, false otherwise - public static bool IsDefined(in ReadOnlySpan name) => IsDefined(name, allowMatchingMetadataAttribute: false); + public static bool IsDefined(in global::System.ReadOnlySpan name) => IsDefined(name, allowMatchingMetadataAttribute: false); /// /// Returns a boolean telling whether an enum with the given name exists in the enumeration, @@ -119,13 +116,13 @@ namespace System /// If true, considers the value of metadata attributes,otherwise ignores them /// true if a member with the name exists in the enumeration, or a member is decorated /// with a [Display] attribute with the name, false otherwise - public static bool IsDefined(in ReadOnlySpan name, bool allowMatchingMetadataAttribute) + public static bool IsDefined(in global::System.ReadOnlySpan name, bool allowMatchingMetadataAttribute) { return name switch { - ReadOnlySpan current when current.Equals(nameof(global::System.DateTimeKind.Unspecified).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(global::System.DateTimeKind.Utc).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(global::System.DateTimeKind.Local).AsSpan(), global::System.StringComparison.Ordinal) => true, + 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, _ => false, }; } @@ -325,7 +322,7 @@ namespace System #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name) + in global::System.ReadOnlySpan name) => TryParse(name, out var value, false, false) ? value : ThrowValueNotFound(name.ToString()); /// @@ -340,7 +337,7 @@ namespace System #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, bool ignoreCase) => TryParse(name, out var value, ignoreCase, false) ? value : ThrowValueNotFound(name.ToString()); @@ -358,7 +355,7 @@ namespace System #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, bool ignoreCase, bool allowMatchingMetadataAttribute) => TryParse(name, out var value, ignoreCase, allowMatchingMetadataAttribute) ? value : ThrowValueNotFound(name.ToString()); @@ -379,7 +376,7 @@ namespace System #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::System.DateTimeKind value) => TryParse(name, out value, false, false); @@ -400,7 +397,7 @@ namespace System #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::System.DateTimeKind value, bool ignoreCase) => TryParse(name, out value, ignoreCase, false); @@ -424,7 +421,7 @@ namespace System #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::System.DateTimeKind result, bool ignoreCase, bool allowMatchingMetadataAttribute) @@ -436,22 +433,22 @@ namespace System #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::System.DateTimeKind result, bool allowMatchingMetadataAttribute) { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(global::System.DateTimeKind.Unspecified).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.DateTimeKind.Unspecified), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.DateTimeKind.Unspecified; return true; - case ReadOnlySpan current when current.Equals(nameof(global::System.DateTimeKind.Utc).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.DateTimeKind.Utc), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.DateTimeKind.Utc; return true; - case ReadOnlySpan current when current.Equals(nameof(global::System.DateTimeKind.Local).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.DateTimeKind.Local), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.DateTimeKind.Local; return true; - case ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): result = (global::System.DateTimeKind)numericResult; return true; default: @@ -464,22 +461,22 @@ namespace System #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::System.DateTimeKind result, bool allowMatchingMetadataAttribute) { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(global::System.DateTimeKind.Unspecified).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.DateTimeKind.Unspecified), global::System.StringComparison.Ordinal): result = global::System.DateTimeKind.Unspecified; return true; - case ReadOnlySpan current when current.Equals(nameof(global::System.DateTimeKind.Utc).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.DateTimeKind.Utc), global::System.StringComparison.Ordinal): result = global::System.DateTimeKind.Utc; return true; - case ReadOnlySpan current when current.Equals(nameof(global::System.DateTimeKind.Local).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.DateTimeKind.Local), global::System.StringComparison.Ordinal): result = global::System.DateTimeKind.Local; return true; - case ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): result = (global::System.DateTimeKind)numericResult; return true; default: diff --git a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateExternalEnumExtensionsWithCustomNamespace.verified.txt b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateExternalEnumExtensionsWithCustomNamespace.verified.txt index e243d13..b2982ab 100644 --- a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateExternalEnumExtensionsWithCustomNamespace.verified.txt +++ b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateExternalEnumExtensionsWithCustomNamespace.verified.txt @@ -8,9 +8,6 @@ //------------------------------------------------------------------------------ #nullable enable -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 -using System; -#endif namespace A.B { @@ -107,7 +104,7 @@ namespace A.B /// /// The name to check if it's defined /// true if a member with the name exists in the enumeration, false otherwise - public static bool IsDefined(in ReadOnlySpan name) => IsDefined(name, allowMatchingMetadataAttribute: false); + public static bool IsDefined(in global::System.ReadOnlySpan name) => IsDefined(name, allowMatchingMetadataAttribute: false); /// /// Returns a boolean telling whether an enum with the given name exists in the enumeration, @@ -119,13 +116,13 @@ namespace A.B /// If true, considers the value of metadata attributes,otherwise ignores them /// true if a member with the name exists in the enumeration, or a member is decorated /// with a [Display] attribute with the name, false otherwise - public static bool IsDefined(in ReadOnlySpan name, bool allowMatchingMetadataAttribute) + public static bool IsDefined(in global::System.ReadOnlySpan name, bool allowMatchingMetadataAttribute) { return name switch { - ReadOnlySpan current when current.Equals(nameof(global::System.DateTimeKind.Unspecified).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(global::System.DateTimeKind.Utc).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(global::System.DateTimeKind.Local).AsSpan(), global::System.StringComparison.Ordinal) => true, + 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, _ => false, }; } @@ -325,7 +322,7 @@ namespace A.B #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name) + in global::System.ReadOnlySpan name) => TryParse(name, out var value, false, false) ? value : ThrowValueNotFound(name.ToString()); /// @@ -340,7 +337,7 @@ namespace A.B #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, bool ignoreCase) => TryParse(name, out var value, ignoreCase, false) ? value : ThrowValueNotFound(name.ToString()); @@ -358,7 +355,7 @@ namespace A.B #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, bool ignoreCase, bool allowMatchingMetadataAttribute) => TryParse(name, out var value, ignoreCase, allowMatchingMetadataAttribute) ? value : ThrowValueNotFound(name.ToString()); @@ -379,7 +376,7 @@ namespace A.B #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::System.DateTimeKind value) => TryParse(name, out value, false, false); @@ -400,7 +397,7 @@ namespace A.B #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::System.DateTimeKind value, bool ignoreCase) => TryParse(name, out value, ignoreCase, false); @@ -424,7 +421,7 @@ namespace A.B #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::System.DateTimeKind result, bool ignoreCase, bool allowMatchingMetadataAttribute) @@ -436,22 +433,22 @@ namespace A.B #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::System.DateTimeKind result, bool allowMatchingMetadataAttribute) { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(global::System.DateTimeKind.Unspecified).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.DateTimeKind.Unspecified), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.DateTimeKind.Unspecified; return true; - case ReadOnlySpan current when current.Equals(nameof(global::System.DateTimeKind.Utc).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.DateTimeKind.Utc), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.DateTimeKind.Utc; return true; - case ReadOnlySpan current when current.Equals(nameof(global::System.DateTimeKind.Local).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.DateTimeKind.Local), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.DateTimeKind.Local; return true; - case ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): result = (global::System.DateTimeKind)numericResult; return true; default: @@ -464,22 +461,22 @@ namespace A.B #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::System.DateTimeKind result, bool allowMatchingMetadataAttribute) { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(global::System.DateTimeKind.Unspecified).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.DateTimeKind.Unspecified), global::System.StringComparison.Ordinal): result = global::System.DateTimeKind.Unspecified; return true; - case ReadOnlySpan current when current.Equals(nameof(global::System.DateTimeKind.Utc).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.DateTimeKind.Utc), global::System.StringComparison.Ordinal): result = global::System.DateTimeKind.Utc; return true; - case ReadOnlySpan current when current.Equals(nameof(global::System.DateTimeKind.Local).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.DateTimeKind.Local), global::System.StringComparison.Ordinal): result = global::System.DateTimeKind.Local; return true; - case ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): result = (global::System.DateTimeKind)numericResult; return true; default: diff --git a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateExternalEnumExtensionsWithCustomNamespaceAndName.verified.txt b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateExternalEnumExtensionsWithCustomNamespaceAndName.verified.txt index b1878d8..5e5025f 100644 --- a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateExternalEnumExtensionsWithCustomNamespaceAndName.verified.txt +++ b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateExternalEnumExtensionsWithCustomNamespaceAndName.verified.txt @@ -8,9 +8,6 @@ //------------------------------------------------------------------------------ #nullable enable -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 -using System; -#endif namespace A.B { @@ -107,7 +104,7 @@ namespace A.B /// /// The name to check if it's defined /// true if a member with the name exists in the enumeration, false otherwise - public static bool IsDefined(in ReadOnlySpan name) => IsDefined(name, allowMatchingMetadataAttribute: false); + public static bool IsDefined(in global::System.ReadOnlySpan name) => IsDefined(name, allowMatchingMetadataAttribute: false); /// /// Returns a boolean telling whether an enum with the given name exists in the enumeration, @@ -119,13 +116,13 @@ namespace A.B /// If true, considers the value of metadata attributes,otherwise ignores them /// true if a member with the name exists in the enumeration, or a member is decorated /// with a [Display] attribute with the name, false otherwise - public static bool IsDefined(in ReadOnlySpan name, bool allowMatchingMetadataAttribute) + public static bool IsDefined(in global::System.ReadOnlySpan name, bool allowMatchingMetadataAttribute) { return name switch { - ReadOnlySpan current when current.Equals(nameof(global::System.DateTimeKind.Unspecified).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(global::System.DateTimeKind.Utc).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(global::System.DateTimeKind.Local).AsSpan(), global::System.StringComparison.Ordinal) => true, + 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, _ => false, }; } @@ -325,7 +322,7 @@ namespace A.B #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name) + in global::System.ReadOnlySpan name) => TryParse(name, out var value, false, false) ? value : ThrowValueNotFound(name.ToString()); /// @@ -340,7 +337,7 @@ namespace A.B #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, bool ignoreCase) => TryParse(name, out var value, ignoreCase, false) ? value : ThrowValueNotFound(name.ToString()); @@ -358,7 +355,7 @@ namespace A.B #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, bool ignoreCase, bool allowMatchingMetadataAttribute) => TryParse(name, out var value, ignoreCase, allowMatchingMetadataAttribute) ? value : ThrowValueNotFound(name.ToString()); @@ -379,7 +376,7 @@ namespace A.B #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::System.DateTimeKind value) => TryParse(name, out value, false, false); @@ -400,7 +397,7 @@ namespace A.B #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::System.DateTimeKind value, bool ignoreCase) => TryParse(name, out value, ignoreCase, false); @@ -424,7 +421,7 @@ namespace A.B #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::System.DateTimeKind result, bool ignoreCase, bool allowMatchingMetadataAttribute) @@ -436,22 +433,22 @@ namespace A.B #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::System.DateTimeKind result, bool allowMatchingMetadataAttribute) { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(global::System.DateTimeKind.Unspecified).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.DateTimeKind.Unspecified), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.DateTimeKind.Unspecified; return true; - case ReadOnlySpan current when current.Equals(nameof(global::System.DateTimeKind.Utc).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.DateTimeKind.Utc), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.DateTimeKind.Utc; return true; - case ReadOnlySpan current when current.Equals(nameof(global::System.DateTimeKind.Local).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.DateTimeKind.Local), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.DateTimeKind.Local; return true; - case ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): result = (global::System.DateTimeKind)numericResult; return true; default: @@ -464,22 +461,22 @@ namespace A.B #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::System.DateTimeKind result, bool allowMatchingMetadataAttribute) { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(global::System.DateTimeKind.Unspecified).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.DateTimeKind.Unspecified), global::System.StringComparison.Ordinal): result = global::System.DateTimeKind.Unspecified; return true; - case ReadOnlySpan current when current.Equals(nameof(global::System.DateTimeKind.Utc).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.DateTimeKind.Utc), global::System.StringComparison.Ordinal): result = global::System.DateTimeKind.Utc; return true; - case ReadOnlySpan current when current.Equals(nameof(global::System.DateTimeKind.Local).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.DateTimeKind.Local), global::System.StringComparison.Ordinal): result = global::System.DateTimeKind.Local; return true; - case ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): result = (global::System.DateTimeKind)numericResult; return true; default: diff --git a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateForExternalEnum.verified.txt b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateForExternalEnum.verified.txt index ecf5057..0dd61e3 100644 --- a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateForExternalEnum.verified.txt +++ b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateForExternalEnum.verified.txt @@ -8,9 +8,6 @@ //------------------------------------------------------------------------------ #nullable enable -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 -using System; -#endif namespace System { @@ -116,7 +113,7 @@ namespace System /// /// The name to check if it's defined /// true if a member with the name exists in the enumeration, false otherwise - public static bool IsDefined(in ReadOnlySpan name) => IsDefined(name, allowMatchingMetadataAttribute: false); + public static bool IsDefined(in global::System.ReadOnlySpan name) => IsDefined(name, allowMatchingMetadataAttribute: false); /// /// Returns a boolean telling whether an enum with the given name exists in the enumeration, @@ -128,16 +125,16 @@ namespace System /// If true, considers the value of metadata attributes,otherwise ignores them /// true if a member with the name exists in the enumeration, or a member is decorated /// with a [Display] attribute with the name, false otherwise - public static bool IsDefined(in ReadOnlySpan name, bool allowMatchingMetadataAttribute) + public static bool IsDefined(in global::System.ReadOnlySpan name, bool allowMatchingMetadataAttribute) { return name switch { - ReadOnlySpan current when current.Equals(nameof(global::System.StringComparison.CurrentCulture).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(global::System.StringComparison.CurrentCultureIgnoreCase).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(global::System.StringComparison.InvariantCulture).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(global::System.StringComparison.InvariantCultureIgnoreCase).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(global::System.StringComparison.Ordinal).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(global::System.StringComparison.OrdinalIgnoreCase).AsSpan(), global::System.StringComparison.Ordinal) => true, + 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, _ => false, }; } @@ -355,7 +352,7 @@ namespace System #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name) + in global::System.ReadOnlySpan name) => TryParse(name, out var value, false, false) ? value : ThrowValueNotFound(name.ToString()); /// @@ -370,7 +367,7 @@ namespace System #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, bool ignoreCase) => TryParse(name, out var value, ignoreCase, false) ? value : ThrowValueNotFound(name.ToString()); @@ -388,7 +385,7 @@ namespace System #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, bool ignoreCase, bool allowMatchingMetadataAttribute) => TryParse(name, out var value, ignoreCase, allowMatchingMetadataAttribute) ? value : ThrowValueNotFound(name.ToString()); @@ -409,7 +406,7 @@ namespace System #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::System.StringComparison value) => TryParse(name, out value, false, false); @@ -430,7 +427,7 @@ namespace System #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::System.StringComparison value, bool ignoreCase) => TryParse(name, out value, ignoreCase, false); @@ -454,7 +451,7 @@ namespace System #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::System.StringComparison result, bool ignoreCase, bool allowMatchingMetadataAttribute) @@ -466,31 +463,31 @@ namespace System #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::System.StringComparison result, bool allowMatchingMetadataAttribute) { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(global::System.StringComparison.CurrentCulture).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.CurrentCulture), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.StringComparison.CurrentCulture; return true; - case ReadOnlySpan current when current.Equals(nameof(global::System.StringComparison.CurrentCultureIgnoreCase).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.CurrentCultureIgnoreCase), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.StringComparison.CurrentCultureIgnoreCase; return true; - case ReadOnlySpan current when current.Equals(nameof(global::System.StringComparison.InvariantCulture).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.InvariantCulture), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.StringComparison.InvariantCulture; return true; - case ReadOnlySpan current when current.Equals(nameof(global::System.StringComparison.InvariantCultureIgnoreCase).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.InvariantCultureIgnoreCase), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.StringComparison.InvariantCultureIgnoreCase; return true; - case ReadOnlySpan current when current.Equals(nameof(global::System.StringComparison.Ordinal).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.Ordinal), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.StringComparison.Ordinal; return true; - case ReadOnlySpan current when current.Equals(nameof(global::System.StringComparison.OrdinalIgnoreCase).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.OrdinalIgnoreCase), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.StringComparison.OrdinalIgnoreCase; return true; - case ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): result = (global::System.StringComparison)numericResult; return true; default: @@ -503,31 +500,31 @@ namespace System #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::System.StringComparison result, bool allowMatchingMetadataAttribute) { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(global::System.StringComparison.CurrentCulture).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.CurrentCulture), global::System.StringComparison.Ordinal): result = global::System.StringComparison.CurrentCulture; return true; - case ReadOnlySpan current when current.Equals(nameof(global::System.StringComparison.CurrentCultureIgnoreCase).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.CurrentCultureIgnoreCase), global::System.StringComparison.Ordinal): result = global::System.StringComparison.CurrentCultureIgnoreCase; return true; - case ReadOnlySpan current when current.Equals(nameof(global::System.StringComparison.InvariantCulture).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.InvariantCulture), global::System.StringComparison.Ordinal): result = global::System.StringComparison.InvariantCulture; return true; - case ReadOnlySpan current when current.Equals(nameof(global::System.StringComparison.InvariantCultureIgnoreCase).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.InvariantCultureIgnoreCase), global::System.StringComparison.Ordinal): result = global::System.StringComparison.InvariantCultureIgnoreCase; return true; - case ReadOnlySpan current when current.Equals(nameof(global::System.StringComparison.Ordinal).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.Ordinal), global::System.StringComparison.Ordinal): result = global::System.StringComparison.Ordinal; return true; - case ReadOnlySpan current when current.Equals(nameof(global::System.StringComparison.OrdinalIgnoreCase).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.OrdinalIgnoreCase), global::System.StringComparison.Ordinal): result = global::System.StringComparison.OrdinalIgnoreCase; return true; - case ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): result = (global::System.StringComparison)numericResult; return true; default: diff --git a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateForExternalFlagsEnum.verified.txt b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateForExternalFlagsEnum.verified.txt index 7aa87e6..47875a9 100644 --- a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateForExternalFlagsEnum.verified.txt +++ b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateForExternalFlagsEnum.verified.txt @@ -8,9 +8,6 @@ //------------------------------------------------------------------------------ #nullable enable -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 -using System; -#endif namespace System.IO { @@ -128,7 +125,7 @@ namespace System.IO /// /// The name to check if it's defined /// true if a member with the name exists in the enumeration, false otherwise - public static bool IsDefined(in ReadOnlySpan name) => IsDefined(name, allowMatchingMetadataAttribute: false); + public static bool IsDefined(in global::System.ReadOnlySpan name) => IsDefined(name, allowMatchingMetadataAttribute: false); /// /// Returns a boolean telling whether an enum with the given name exists in the enumeration, @@ -140,16 +137,16 @@ namespace System.IO /// If true, considers the value of metadata attributes,otherwise ignores them /// true if a member with the name exists in the enumeration, or a member is decorated /// with a [Display] attribute with the name, false otherwise - public static bool IsDefined(in ReadOnlySpan name, bool allowMatchingMetadataAttribute) + public static bool IsDefined(in global::System.ReadOnlySpan name, bool allowMatchingMetadataAttribute) { return name switch { - ReadOnlySpan current when current.Equals(nameof(global::System.IO.FileShare.None).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(global::System.IO.FileShare.Read).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(global::System.IO.FileShare.Write).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(global::System.IO.FileShare.ReadWrite).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(global::System.IO.FileShare.Delete).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(global::System.IO.FileShare.Inheritable).AsSpan(), global::System.StringComparison.Ordinal) => true, + 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, _ => false, }; } @@ -367,7 +364,7 @@ namespace System.IO #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name) + in global::System.ReadOnlySpan name) => TryParse(name, out var value, false, false) ? value : ThrowValueNotFound(name.ToString()); /// @@ -382,7 +379,7 @@ namespace System.IO #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, bool ignoreCase) => TryParse(name, out var value, ignoreCase, false) ? value : ThrowValueNotFound(name.ToString()); @@ -400,7 +397,7 @@ namespace System.IO #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, bool ignoreCase, bool allowMatchingMetadataAttribute) => TryParse(name, out var value, ignoreCase, allowMatchingMetadataAttribute) ? value : ThrowValueNotFound(name.ToString()); @@ -421,7 +418,7 @@ namespace System.IO #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::System.IO.FileShare value) => TryParse(name, out value, false, false); @@ -442,7 +439,7 @@ namespace System.IO #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::System.IO.FileShare value, bool ignoreCase) => TryParse(name, out value, ignoreCase, false); @@ -466,7 +463,7 @@ namespace System.IO #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::System.IO.FileShare result, bool ignoreCase, bool allowMatchingMetadataAttribute) @@ -478,31 +475,31 @@ namespace System.IO #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::System.IO.FileShare result, bool allowMatchingMetadataAttribute) { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(global::System.IO.FileShare.None).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.IO.FileShare.None), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.IO.FileShare.None; return true; - case ReadOnlySpan current when current.Equals(nameof(global::System.IO.FileShare.Read).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.IO.FileShare.Read), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.IO.FileShare.Read; return true; - case ReadOnlySpan current when current.Equals(nameof(global::System.IO.FileShare.Write).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.IO.FileShare.Write), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.IO.FileShare.Write; return true; - case ReadOnlySpan current when current.Equals(nameof(global::System.IO.FileShare.ReadWrite).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.IO.FileShare.ReadWrite), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.IO.FileShare.ReadWrite; return true; - case ReadOnlySpan current when current.Equals(nameof(global::System.IO.FileShare.Delete).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.IO.FileShare.Delete), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.IO.FileShare.Delete; return true; - case ReadOnlySpan current when current.Equals(nameof(global::System.IO.FileShare.Inheritable).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.IO.FileShare.Inheritable), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.IO.FileShare.Inheritable; return true; - case ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): result = (global::System.IO.FileShare)numericResult; return true; default: @@ -515,31 +512,31 @@ namespace System.IO #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::System.IO.FileShare result, bool allowMatchingMetadataAttribute) { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(global::System.IO.FileShare.None).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.IO.FileShare.None), global::System.StringComparison.Ordinal): result = global::System.IO.FileShare.None; return true; - case ReadOnlySpan current when current.Equals(nameof(global::System.IO.FileShare.Read).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.IO.FileShare.Read), global::System.StringComparison.Ordinal): result = global::System.IO.FileShare.Read; return true; - case ReadOnlySpan current when current.Equals(nameof(global::System.IO.FileShare.Write).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.IO.FileShare.Write), global::System.StringComparison.Ordinal): result = global::System.IO.FileShare.Write; return true; - case ReadOnlySpan current when current.Equals(nameof(global::System.IO.FileShare.ReadWrite).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.IO.FileShare.ReadWrite), global::System.StringComparison.Ordinal): result = global::System.IO.FileShare.ReadWrite; return true; - case ReadOnlySpan current when current.Equals(nameof(global::System.IO.FileShare.Delete).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.IO.FileShare.Delete), global::System.StringComparison.Ordinal): result = global::System.IO.FileShare.Delete; return true; - case ReadOnlySpan current when current.Equals(nameof(global::System.IO.FileShare.Inheritable).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.IO.FileShare.Inheritable), global::System.StringComparison.Ordinal): result = global::System.IO.FileShare.Inheritable; return true; - case ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): result = (global::System.IO.FileShare)numericResult; return true; default: diff --git a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateForMultipleExternalEnums.verified.txt b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateForMultipleExternalEnums.verified.txt index c23cc6b..52fe607 100644 --- a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateForMultipleExternalEnums.verified.txt +++ b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateForMultipleExternalEnums.verified.txt @@ -9,9 +9,6 @@ //------------------------------------------------------------------------------ #nullable enable -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 -using System; -#endif namespace System { @@ -147,7 +144,7 @@ namespace System /// /// The name to check if it's defined /// true if a member with the name exists in the enumeration, false otherwise - public static bool IsDefined(in ReadOnlySpan name) => IsDefined(name, allowMatchingMetadataAttribute: false); + public static bool IsDefined(in global::System.ReadOnlySpan name) => IsDefined(name, allowMatchingMetadataAttribute: false); /// /// Returns a boolean telling whether an enum with the given name exists in the enumeration, @@ -159,26 +156,26 @@ namespace System /// If true, considers the value of metadata attributes,otherwise ignores them /// true if a member with the name exists in the enumeration, or a member is decorated /// with a [Display] attribute with the name, false otherwise - public static bool IsDefined(in ReadOnlySpan name, bool allowMatchingMetadataAttribute) + public static bool IsDefined(in global::System.ReadOnlySpan name, bool allowMatchingMetadataAttribute) { return name switch { - ReadOnlySpan current when current.Equals(nameof(global::System.ConsoleColor.Black).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(global::System.ConsoleColor.DarkBlue).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(global::System.ConsoleColor.DarkGreen).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(global::System.ConsoleColor.DarkCyan).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(global::System.ConsoleColor.DarkRed).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(global::System.ConsoleColor.DarkMagenta).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(global::System.ConsoleColor.DarkYellow).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(global::System.ConsoleColor.Gray).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(global::System.ConsoleColor.DarkGray).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(global::System.ConsoleColor.Blue).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(global::System.ConsoleColor.Green).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(global::System.ConsoleColor.Cyan).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(global::System.ConsoleColor.Red).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(global::System.ConsoleColor.Magenta).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(global::System.ConsoleColor.Yellow).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(global::System.ConsoleColor.White).AsSpan(), global::System.StringComparison.Ordinal) => true, + 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, _ => false, }; } @@ -456,7 +453,7 @@ namespace System #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name) + in global::System.ReadOnlySpan name) => TryParse(name, out var value, false, false) ? value : ThrowValueNotFound(name.ToString()); /// @@ -471,7 +468,7 @@ namespace System #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, bool ignoreCase) => TryParse(name, out var value, ignoreCase, false) ? value : ThrowValueNotFound(name.ToString()); @@ -489,7 +486,7 @@ namespace System #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, bool ignoreCase, bool allowMatchingMetadataAttribute) => TryParse(name, out var value, ignoreCase, allowMatchingMetadataAttribute) ? value : ThrowValueNotFound(name.ToString()); @@ -510,7 +507,7 @@ namespace System #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::System.ConsoleColor value) => TryParse(name, out value, false, false); @@ -531,7 +528,7 @@ namespace System #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::System.ConsoleColor value, bool ignoreCase) => TryParse(name, out value, ignoreCase, false); @@ -555,7 +552,7 @@ namespace System #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::System.ConsoleColor result, bool ignoreCase, bool allowMatchingMetadataAttribute) @@ -567,61 +564,61 @@ namespace System #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::System.ConsoleColor result, bool allowMatchingMetadataAttribute) { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(global::System.ConsoleColor.Black).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.ConsoleColor.Black), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.ConsoleColor.Black; return true; - case ReadOnlySpan current when current.Equals(nameof(global::System.ConsoleColor.DarkBlue).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.ConsoleColor.DarkBlue), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.ConsoleColor.DarkBlue; return true; - case ReadOnlySpan current when current.Equals(nameof(global::System.ConsoleColor.DarkGreen).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.ConsoleColor.DarkGreen), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.ConsoleColor.DarkGreen; return true; - case ReadOnlySpan current when current.Equals(nameof(global::System.ConsoleColor.DarkCyan).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.ConsoleColor.DarkCyan), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.ConsoleColor.DarkCyan; return true; - case ReadOnlySpan current when current.Equals(nameof(global::System.ConsoleColor.DarkRed).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.ConsoleColor.DarkRed), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.ConsoleColor.DarkRed; return true; - case ReadOnlySpan current when current.Equals(nameof(global::System.ConsoleColor.DarkMagenta).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.ConsoleColor.DarkMagenta), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.ConsoleColor.DarkMagenta; return true; - case ReadOnlySpan current when current.Equals(nameof(global::System.ConsoleColor.DarkYellow).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.ConsoleColor.DarkYellow), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.ConsoleColor.DarkYellow; return true; - case ReadOnlySpan current when current.Equals(nameof(global::System.ConsoleColor.Gray).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.ConsoleColor.Gray), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.ConsoleColor.Gray; return true; - case ReadOnlySpan current when current.Equals(nameof(global::System.ConsoleColor.DarkGray).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.ConsoleColor.DarkGray), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.ConsoleColor.DarkGray; return true; - case ReadOnlySpan current when current.Equals(nameof(global::System.ConsoleColor.Blue).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.ConsoleColor.Blue), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.ConsoleColor.Blue; return true; - case ReadOnlySpan current when current.Equals(nameof(global::System.ConsoleColor.Green).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.ConsoleColor.Green), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.ConsoleColor.Green; return true; - case ReadOnlySpan current when current.Equals(nameof(global::System.ConsoleColor.Cyan).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.ConsoleColor.Cyan), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.ConsoleColor.Cyan; return true; - case ReadOnlySpan current when current.Equals(nameof(global::System.ConsoleColor.Red).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.ConsoleColor.Red), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.ConsoleColor.Red; return true; - case ReadOnlySpan current when current.Equals(nameof(global::System.ConsoleColor.Magenta).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.ConsoleColor.Magenta), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.ConsoleColor.Magenta; return true; - case ReadOnlySpan current when current.Equals(nameof(global::System.ConsoleColor.Yellow).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.ConsoleColor.Yellow), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.ConsoleColor.Yellow; return true; - case ReadOnlySpan current when current.Equals(nameof(global::System.ConsoleColor.White).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.ConsoleColor.White), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.ConsoleColor.White; return true; - case ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): result = (global::System.ConsoleColor)numericResult; return true; default: @@ -634,61 +631,61 @@ namespace System #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::System.ConsoleColor result, bool allowMatchingMetadataAttribute) { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(global::System.ConsoleColor.Black).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.ConsoleColor.Black), global::System.StringComparison.Ordinal): result = global::System.ConsoleColor.Black; return true; - case ReadOnlySpan current when current.Equals(nameof(global::System.ConsoleColor.DarkBlue).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.ConsoleColor.DarkBlue), global::System.StringComparison.Ordinal): result = global::System.ConsoleColor.DarkBlue; return true; - case ReadOnlySpan current when current.Equals(nameof(global::System.ConsoleColor.DarkGreen).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.ConsoleColor.DarkGreen), global::System.StringComparison.Ordinal): result = global::System.ConsoleColor.DarkGreen; return true; - case ReadOnlySpan current when current.Equals(nameof(global::System.ConsoleColor.DarkCyan).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.ConsoleColor.DarkCyan), global::System.StringComparison.Ordinal): result = global::System.ConsoleColor.DarkCyan; return true; - case ReadOnlySpan current when current.Equals(nameof(global::System.ConsoleColor.DarkRed).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.ConsoleColor.DarkRed), global::System.StringComparison.Ordinal): result = global::System.ConsoleColor.DarkRed; return true; - case ReadOnlySpan current when current.Equals(nameof(global::System.ConsoleColor.DarkMagenta).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.ConsoleColor.DarkMagenta), global::System.StringComparison.Ordinal): result = global::System.ConsoleColor.DarkMagenta; return true; - case ReadOnlySpan current when current.Equals(nameof(global::System.ConsoleColor.DarkYellow).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.ConsoleColor.DarkYellow), global::System.StringComparison.Ordinal): result = global::System.ConsoleColor.DarkYellow; return true; - case ReadOnlySpan current when current.Equals(nameof(global::System.ConsoleColor.Gray).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.ConsoleColor.Gray), global::System.StringComparison.Ordinal): result = global::System.ConsoleColor.Gray; return true; - case ReadOnlySpan current when current.Equals(nameof(global::System.ConsoleColor.DarkGray).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.ConsoleColor.DarkGray), global::System.StringComparison.Ordinal): result = global::System.ConsoleColor.DarkGray; return true; - case ReadOnlySpan current when current.Equals(nameof(global::System.ConsoleColor.Blue).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.ConsoleColor.Blue), global::System.StringComparison.Ordinal): result = global::System.ConsoleColor.Blue; return true; - case ReadOnlySpan current when current.Equals(nameof(global::System.ConsoleColor.Green).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.ConsoleColor.Green), global::System.StringComparison.Ordinal): result = global::System.ConsoleColor.Green; return true; - case ReadOnlySpan current when current.Equals(nameof(global::System.ConsoleColor.Cyan).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.ConsoleColor.Cyan), global::System.StringComparison.Ordinal): result = global::System.ConsoleColor.Cyan; return true; - case ReadOnlySpan current when current.Equals(nameof(global::System.ConsoleColor.Red).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.ConsoleColor.Red), global::System.StringComparison.Ordinal): result = global::System.ConsoleColor.Red; return true; - case ReadOnlySpan current when current.Equals(nameof(global::System.ConsoleColor.Magenta).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.ConsoleColor.Magenta), global::System.StringComparison.Ordinal): result = global::System.ConsoleColor.Magenta; return true; - case ReadOnlySpan current when current.Equals(nameof(global::System.ConsoleColor.Yellow).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.ConsoleColor.Yellow), global::System.StringComparison.Ordinal): result = global::System.ConsoleColor.Yellow; return true; - case ReadOnlySpan current when current.Equals(nameof(global::System.ConsoleColor.White).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.ConsoleColor.White), global::System.StringComparison.Ordinal): result = global::System.ConsoleColor.White; return true; - case ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): result = (global::System.ConsoleColor)numericResult; return true; default: @@ -772,9 +769,6 @@ namespace System //------------------------------------------------------------------------------ #nullable enable -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 -using System; -#endif namespace System { @@ -871,7 +865,7 @@ namespace System /// /// The name to check if it's defined /// true if a member with the name exists in the enumeration, false otherwise - public static bool IsDefined(in ReadOnlySpan name) => IsDefined(name, allowMatchingMetadataAttribute: false); + public static bool IsDefined(in global::System.ReadOnlySpan name) => IsDefined(name, allowMatchingMetadataAttribute: false); /// /// Returns a boolean telling whether an enum with the given name exists in the enumeration, @@ -883,13 +877,13 @@ namespace System /// If true, considers the value of metadata attributes,otherwise ignores them /// true if a member with the name exists in the enumeration, or a member is decorated /// with a [Display] attribute with the name, false otherwise - public static bool IsDefined(in ReadOnlySpan name, bool allowMatchingMetadataAttribute) + public static bool IsDefined(in global::System.ReadOnlySpan name, bool allowMatchingMetadataAttribute) { return name switch { - ReadOnlySpan current when current.Equals(nameof(global::System.DateTimeKind.Unspecified).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(global::System.DateTimeKind.Utc).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(global::System.DateTimeKind.Local).AsSpan(), global::System.StringComparison.Ordinal) => true, + 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, _ => false, }; } @@ -1089,7 +1083,7 @@ namespace System #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name) + in global::System.ReadOnlySpan name) => TryParse(name, out var value, false, false) ? value : ThrowValueNotFound(name.ToString()); /// @@ -1104,7 +1098,7 @@ namespace System #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, bool ignoreCase) => TryParse(name, out var value, ignoreCase, false) ? value : ThrowValueNotFound(name.ToString()); @@ -1122,7 +1116,7 @@ namespace System #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, bool ignoreCase, bool allowMatchingMetadataAttribute) => TryParse(name, out var value, ignoreCase, allowMatchingMetadataAttribute) ? value : ThrowValueNotFound(name.ToString()); @@ -1143,7 +1137,7 @@ namespace System #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::System.DateTimeKind value) => TryParse(name, out value, false, false); @@ -1164,7 +1158,7 @@ namespace System #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::System.DateTimeKind value, bool ignoreCase) => TryParse(name, out value, ignoreCase, false); @@ -1188,7 +1182,7 @@ namespace System #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::System.DateTimeKind result, bool ignoreCase, bool allowMatchingMetadataAttribute) @@ -1200,22 +1194,22 @@ namespace System #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::System.DateTimeKind result, bool allowMatchingMetadataAttribute) { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(global::System.DateTimeKind.Unspecified).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.DateTimeKind.Unspecified), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.DateTimeKind.Unspecified; return true; - case ReadOnlySpan current when current.Equals(nameof(global::System.DateTimeKind.Utc).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.DateTimeKind.Utc), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.DateTimeKind.Utc; return true; - case ReadOnlySpan current when current.Equals(nameof(global::System.DateTimeKind.Local).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.DateTimeKind.Local), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.DateTimeKind.Local; return true; - case ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): result = (global::System.DateTimeKind)numericResult; return true; default: @@ -1228,22 +1222,22 @@ namespace System #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::System.DateTimeKind result, bool allowMatchingMetadataAttribute) { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(global::System.DateTimeKind.Unspecified).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.DateTimeKind.Unspecified), global::System.StringComparison.Ordinal): result = global::System.DateTimeKind.Unspecified; return true; - case ReadOnlySpan current when current.Equals(nameof(global::System.DateTimeKind.Utc).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.DateTimeKind.Utc), global::System.StringComparison.Ordinal): result = global::System.DateTimeKind.Utc; return true; - case ReadOnlySpan current when current.Equals(nameof(global::System.DateTimeKind.Local).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.DateTimeKind.Local), global::System.StringComparison.Ordinal): result = global::System.DateTimeKind.Local; return true; - case ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): result = (global::System.DateTimeKind)numericResult; return true; default: diff --git a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanHandleNamespaceAndClassNameAreTheSame.verified.txt b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanHandleNamespaceAndClassNameAreTheSame.verified.txt index 0e90f72..1b2c4eb 100644 --- a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanHandleNamespaceAndClassNameAreTheSame.verified.txt +++ b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanHandleNamespaceAndClassNameAreTheSame.verified.txt @@ -8,9 +8,6 @@ //------------------------------------------------------------------------------ #nullable enable -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 -using System; -#endif namespace Foo { @@ -101,7 +98,7 @@ namespace Foo /// /// The name to check if it's defined /// true if a member with the name exists in the enumeration, false otherwise - public static bool IsDefined(in ReadOnlySpan name) => IsDefined(name, allowMatchingMetadataAttribute: false); + public static bool IsDefined(in global::System.ReadOnlySpan name) => IsDefined(name, allowMatchingMetadataAttribute: false); /// /// Returns a boolean telling whether an enum with the given name exists in the enumeration, @@ -113,11 +110,11 @@ namespace Foo /// If true, considers the value of metadata attributes,otherwise ignores them /// true if a member with the name exists in the enumeration, or a member is decorated /// with a [Display] attribute with the name, false otherwise - public static bool IsDefined(in ReadOnlySpan name, bool allowMatchingMetadataAttribute) + public static bool IsDefined(in global::System.ReadOnlySpan name, bool allowMatchingMetadataAttribute) { return name switch { - ReadOnlySpan current when current.Equals(nameof(global::Foo.TestEnum.Value1).AsSpan(), global::System.StringComparison.Ordinal) => true, + global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::Foo.TestEnum.Value1), global::System.StringComparison.Ordinal) => true, _ => false, }; } @@ -305,7 +302,7 @@ namespace Foo #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name) + in global::System.ReadOnlySpan name) => TryParse(name, out var value, false, false) ? value : ThrowValueNotFound(name.ToString()); /// @@ -320,7 +317,7 @@ namespace Foo #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, bool ignoreCase) => TryParse(name, out var value, ignoreCase, false) ? value : ThrowValueNotFound(name.ToString()); @@ -338,7 +335,7 @@ namespace Foo #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, bool ignoreCase, bool allowMatchingMetadataAttribute) => TryParse(name, out var value, ignoreCase, allowMatchingMetadataAttribute) ? value : ThrowValueNotFound(name.ToString()); @@ -359,7 +356,7 @@ namespace Foo #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::Foo.TestEnum value) => TryParse(name, out value, false, false); @@ -380,7 +377,7 @@ namespace Foo #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::Foo.TestEnum value, bool ignoreCase) => TryParse(name, out value, ignoreCase, false); @@ -404,7 +401,7 @@ namespace Foo #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::Foo.TestEnum result, bool ignoreCase, bool allowMatchingMetadataAttribute) @@ -416,16 +413,16 @@ namespace Foo #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::Foo.TestEnum result, bool allowMatchingMetadataAttribute) { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(global::Foo.TestEnum.Value1).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::Foo.TestEnum.Value1), global::System.StringComparison.OrdinalIgnoreCase): result = global::Foo.TestEnum.Value1; return true; - case ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): result = (global::Foo.TestEnum)numericResult; return true; default: @@ -438,16 +435,16 @@ namespace Foo #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::Foo.TestEnum result, bool allowMatchingMetadataAttribute) { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(global::Foo.TestEnum.Value1).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::Foo.TestEnum.Value1), global::System.StringComparison.Ordinal): result = global::Foo.TestEnum.Value1; return true; - case ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): result = (global::Foo.TestEnum)numericResult; return true; default: 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 0e104bc..3237afb 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 @@ -8,9 +8,6 @@ //------------------------------------------------------------------------------ #nullable enable -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 -using System; -#endif #pragma warning disable CS0612 // Ignore usages of obsolete members or enums #pragma warning disable CS0618 // Ignore usages of obsolete members or enums @@ -102,7 +99,7 @@ using System; /// /// The name to check if it's defined /// true if a member with the name exists in the enumeration, false otherwise - public static bool IsDefined(in ReadOnlySpan name) => IsDefined(name, allowMatchingMetadataAttribute: false); + public static bool IsDefined(in global::System.ReadOnlySpan name) => IsDefined(name, allowMatchingMetadataAttribute: false); /// /// Returns a boolean telling whether an enum with the given name exists in the enumeration, @@ -114,12 +111,12 @@ using System; /// If true, considers the value of metadata attributes,otherwise ignores them /// true if a member with the name exists in the enumeration, or a member is decorated /// with a [Display] attribute with the name, false otherwise - public static bool IsDefined(in ReadOnlySpan name, bool allowMatchingMetadataAttribute) + public static bool IsDefined(in global::System.ReadOnlySpan name, bool allowMatchingMetadataAttribute) { return name switch { - ReadOnlySpan current when current.Equals(nameof(global::MyEnum.First).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(global::MyEnum.Second).AsSpan(), global::System.StringComparison.Ordinal) => true, + 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, _ => false, }; } @@ -313,7 +310,7 @@ using System; #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name) + in global::System.ReadOnlySpan name) => TryParse(name, out var value, false, false) ? value : ThrowValueNotFound(name.ToString()); /// @@ -328,7 +325,7 @@ using System; #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, bool ignoreCase) => TryParse(name, out var value, ignoreCase, false) ? value : ThrowValueNotFound(name.ToString()); @@ -346,7 +343,7 @@ using System; #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, bool ignoreCase, bool allowMatchingMetadataAttribute) => TryParse(name, out var value, ignoreCase, allowMatchingMetadataAttribute) ? value : ThrowValueNotFound(name.ToString()); @@ -367,7 +364,7 @@ using System; #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyEnum value) => TryParse(name, out value, false, false); @@ -388,7 +385,7 @@ using System; #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyEnum value, bool ignoreCase) => TryParse(name, out value, ignoreCase, false); @@ -412,7 +409,7 @@ using System; #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyEnum result, bool ignoreCase, bool allowMatchingMetadataAttribute) @@ -424,19 +421,19 @@ using System; #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyEnum result, bool allowMatchingMetadataAttribute) { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(global::MyEnum.First).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyEnum.First), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyEnum.First; return true; - case ReadOnlySpan current when current.Equals(nameof(global::MyEnum.Second).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyEnum.Second), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyEnum.Second; return true; - case ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): result = (global::MyEnum)numericResult; return true; default: @@ -449,19 +446,19 @@ using System; #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyEnum result, bool allowMatchingMetadataAttribute) { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(global::MyEnum.First).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyEnum.First), global::System.StringComparison.Ordinal): result = global::MyEnum.First; return true; - case ReadOnlySpan current when current.Equals(nameof(global::MyEnum.Second).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyEnum.Second), global::System.StringComparison.Ordinal): result = global::MyEnum.Second; return true; - case ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): result = (global::MyEnum)numericResult; return true; default: 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 0e104bc..3237afb 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 @@ -8,9 +8,6 @@ //------------------------------------------------------------------------------ #nullable enable -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 -using System; -#endif #pragma warning disable CS0612 // Ignore usages of obsolete members or enums #pragma warning disable CS0618 // Ignore usages of obsolete members or enums @@ -102,7 +99,7 @@ using System; /// /// The name to check if it's defined /// true if a member with the name exists in the enumeration, false otherwise - public static bool IsDefined(in ReadOnlySpan name) => IsDefined(name, allowMatchingMetadataAttribute: false); + public static bool IsDefined(in global::System.ReadOnlySpan name) => IsDefined(name, allowMatchingMetadataAttribute: false); /// /// Returns a boolean telling whether an enum with the given name exists in the enumeration, @@ -114,12 +111,12 @@ using System; /// If true, considers the value of metadata attributes,otherwise ignores them /// true if a member with the name exists in the enumeration, or a member is decorated /// with a [Display] attribute with the name, false otherwise - public static bool IsDefined(in ReadOnlySpan name, bool allowMatchingMetadataAttribute) + public static bool IsDefined(in global::System.ReadOnlySpan name, bool allowMatchingMetadataAttribute) { return name switch { - ReadOnlySpan current when current.Equals(nameof(global::MyEnum.First).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(global::MyEnum.Second).AsSpan(), global::System.StringComparison.Ordinal) => true, + 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, _ => false, }; } @@ -313,7 +310,7 @@ using System; #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name) + in global::System.ReadOnlySpan name) => TryParse(name, out var value, false, false) ? value : ThrowValueNotFound(name.ToString()); /// @@ -328,7 +325,7 @@ using System; #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, bool ignoreCase) => TryParse(name, out var value, ignoreCase, false) ? value : ThrowValueNotFound(name.ToString()); @@ -346,7 +343,7 @@ using System; #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, bool ignoreCase, bool allowMatchingMetadataAttribute) => TryParse(name, out var value, ignoreCase, allowMatchingMetadataAttribute) ? value : ThrowValueNotFound(name.ToString()); @@ -367,7 +364,7 @@ using System; #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyEnum value) => TryParse(name, out value, false, false); @@ -388,7 +385,7 @@ using System; #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyEnum value, bool ignoreCase) => TryParse(name, out value, ignoreCase, false); @@ -412,7 +409,7 @@ using System; #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyEnum result, bool ignoreCase, bool allowMatchingMetadataAttribute) @@ -424,19 +421,19 @@ using System; #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyEnum result, bool allowMatchingMetadataAttribute) { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(global::MyEnum.First).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyEnum.First), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyEnum.First; return true; - case ReadOnlySpan current when current.Equals(nameof(global::MyEnum.Second).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyEnum.Second), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyEnum.Second; return true; - case ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): result = (global::MyEnum)numericResult; return true; default: @@ -449,19 +446,19 @@ using System; #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyEnum result, bool allowMatchingMetadataAttribute) { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(global::MyEnum.First).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyEnum.First), global::System.StringComparison.Ordinal): result = global::MyEnum.First; return true; - case ReadOnlySpan current when current.Equals(nameof(global::MyEnum.Second).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyEnum.Second), global::System.StringComparison.Ordinal): result = global::MyEnum.Second; return true; - case ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): result = (global::MyEnum)numericResult; return true; default: 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 0e104bc..3237afb 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 @@ -8,9 +8,6 @@ //------------------------------------------------------------------------------ #nullable enable -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 -using System; -#endif #pragma warning disable CS0612 // Ignore usages of obsolete members or enums #pragma warning disable CS0618 // Ignore usages of obsolete members or enums @@ -102,7 +99,7 @@ using System; /// /// The name to check if it's defined /// true if a member with the name exists in the enumeration, false otherwise - public static bool IsDefined(in ReadOnlySpan name) => IsDefined(name, allowMatchingMetadataAttribute: false); + public static bool IsDefined(in global::System.ReadOnlySpan name) => IsDefined(name, allowMatchingMetadataAttribute: false); /// /// Returns a boolean telling whether an enum with the given name exists in the enumeration, @@ -114,12 +111,12 @@ using System; /// If true, considers the value of metadata attributes,otherwise ignores them /// true if a member with the name exists in the enumeration, or a member is decorated /// with a [Display] attribute with the name, false otherwise - public static bool IsDefined(in ReadOnlySpan name, bool allowMatchingMetadataAttribute) + public static bool IsDefined(in global::System.ReadOnlySpan name, bool allowMatchingMetadataAttribute) { return name switch { - ReadOnlySpan current when current.Equals(nameof(global::MyEnum.First).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(global::MyEnum.Second).AsSpan(), global::System.StringComparison.Ordinal) => true, + 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, _ => false, }; } @@ -313,7 +310,7 @@ using System; #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name) + in global::System.ReadOnlySpan name) => TryParse(name, out var value, false, false) ? value : ThrowValueNotFound(name.ToString()); /// @@ -328,7 +325,7 @@ using System; #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, bool ignoreCase) => TryParse(name, out var value, ignoreCase, false) ? value : ThrowValueNotFound(name.ToString()); @@ -346,7 +343,7 @@ using System; #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, bool ignoreCase, bool allowMatchingMetadataAttribute) => TryParse(name, out var value, ignoreCase, allowMatchingMetadataAttribute) ? value : ThrowValueNotFound(name.ToString()); @@ -367,7 +364,7 @@ using System; #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyEnum value) => TryParse(name, out value, false, false); @@ -388,7 +385,7 @@ using System; #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyEnum value, bool ignoreCase) => TryParse(name, out value, ignoreCase, false); @@ -412,7 +409,7 @@ using System; #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyEnum result, bool ignoreCase, bool allowMatchingMetadataAttribute) @@ -424,19 +421,19 @@ using System; #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyEnum result, bool allowMatchingMetadataAttribute) { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(global::MyEnum.First).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyEnum.First), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyEnum.First; return true; - case ReadOnlySpan current when current.Equals(nameof(global::MyEnum.Second).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyEnum.Second), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyEnum.Second; return true; - case ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): result = (global::MyEnum)numericResult; return true; default: @@ -449,19 +446,19 @@ using System; #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyEnum result, bool allowMatchingMetadataAttribute) { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(global::MyEnum.First).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyEnum.First), global::System.StringComparison.Ordinal): result = global::MyEnum.First; return true; - case ReadOnlySpan current when current.Equals(nameof(global::MyEnum.Second).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyEnum.Second), global::System.StringComparison.Ordinal): result = global::MyEnum.Second; return true; - case ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): result = (global::MyEnum)numericResult; return true; default: 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 0e104bc..3237afb 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 @@ -8,9 +8,6 @@ //------------------------------------------------------------------------------ #nullable enable -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 -using System; -#endif #pragma warning disable CS0612 // Ignore usages of obsolete members or enums #pragma warning disable CS0618 // Ignore usages of obsolete members or enums @@ -102,7 +99,7 @@ using System; /// /// The name to check if it's defined /// true if a member with the name exists in the enumeration, false otherwise - public static bool IsDefined(in ReadOnlySpan name) => IsDefined(name, allowMatchingMetadataAttribute: false); + public static bool IsDefined(in global::System.ReadOnlySpan name) => IsDefined(name, allowMatchingMetadataAttribute: false); /// /// Returns a boolean telling whether an enum with the given name exists in the enumeration, @@ -114,12 +111,12 @@ using System; /// If true, considers the value of metadata attributes,otherwise ignores them /// true if a member with the name exists in the enumeration, or a member is decorated /// with a [Display] attribute with the name, false otherwise - public static bool IsDefined(in ReadOnlySpan name, bool allowMatchingMetadataAttribute) + public static bool IsDefined(in global::System.ReadOnlySpan name, bool allowMatchingMetadataAttribute) { return name switch { - ReadOnlySpan current when current.Equals(nameof(global::MyEnum.First).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(global::MyEnum.Second).AsSpan(), global::System.StringComparison.Ordinal) => true, + 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, _ => false, }; } @@ -313,7 +310,7 @@ using System; #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name) + in global::System.ReadOnlySpan name) => TryParse(name, out var value, false, false) ? value : ThrowValueNotFound(name.ToString()); /// @@ -328,7 +325,7 @@ using System; #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, bool ignoreCase) => TryParse(name, out var value, ignoreCase, false) ? value : ThrowValueNotFound(name.ToString()); @@ -346,7 +343,7 @@ using System; #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, bool ignoreCase, bool allowMatchingMetadataAttribute) => TryParse(name, out var value, ignoreCase, allowMatchingMetadataAttribute) ? value : ThrowValueNotFound(name.ToString()); @@ -367,7 +364,7 @@ using System; #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyEnum value) => TryParse(name, out value, false, false); @@ -388,7 +385,7 @@ using System; #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyEnum value, bool ignoreCase) => TryParse(name, out value, ignoreCase, false); @@ -412,7 +409,7 @@ using System; #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyEnum result, bool ignoreCase, bool allowMatchingMetadataAttribute) @@ -424,19 +421,19 @@ using System; #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyEnum result, bool allowMatchingMetadataAttribute) { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(global::MyEnum.First).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyEnum.First), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyEnum.First; return true; - case ReadOnlySpan current when current.Equals(nameof(global::MyEnum.Second).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyEnum.Second), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyEnum.Second; return true; - case ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): result = (global::MyEnum)numericResult; return true; default: @@ -449,19 +446,19 @@ using System; #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyEnum result, bool allowMatchingMetadataAttribute) { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(global::MyEnum.First).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyEnum.First), global::System.StringComparison.Ordinal): result = global::MyEnum.First; return true; - case ReadOnlySpan current when current.Equals(nameof(global::MyEnum.Second).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyEnum.Second), global::System.StringComparison.Ordinal): result = global::MyEnum.Second; return true; - case ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): result = (global::MyEnum)numericResult; return true; default: diff --git a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.HandlesStringsWithQuotesAndSlashesInDescription.verified.txt b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.HandlesStringsWithQuotesAndSlashesInDescription.verified.txt index 7cb00a8..1acd92e 100644 --- a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.HandlesStringsWithQuotesAndSlashesInDescription.verified.txt +++ b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.HandlesStringsWithQuotesAndSlashesInDescription.verified.txt @@ -8,9 +8,6 @@ //------------------------------------------------------------------------------ #nullable enable -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 -using System; -#endif namespace Test { @@ -141,7 +138,7 @@ namespace Test /// /// The name to check if it's defined /// true if a member with the name exists in the enumeration, false otherwise - public static bool IsDefined(in ReadOnlySpan name) => IsDefined(name, allowMatchingMetadataAttribute: false); + public static bool IsDefined(in global::System.ReadOnlySpan name) => IsDefined(name, allowMatchingMetadataAttribute: false); /// /// Returns a boolean telling whether an enum with the given name exists in the enumeration, @@ -153,18 +150,18 @@ namespace Test /// If true, considers the value of metadata attributes,otherwise ignores them /// true if a member with the name exists in the enumeration, or a member is decorated /// with a [Display] attribute with the name, false otherwise - public static bool IsDefined(in ReadOnlySpan name, bool allowMatchingMetadataAttribute) + public static bool IsDefined(in global::System.ReadOnlySpan name, bool allowMatchingMetadataAttribute) { var isDefinedInDisplayAttribute = false; if (allowMatchingMetadataAttribute) { isDefinedInDisplayAttribute = name switch { - ReadOnlySpan current when current.Equals("Quotes \"".AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals("Literal Quotes \"".AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals("Backslash \\".AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals("LiteralBackslash \\".AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals("New\nLine".AsSpan(), global::System.StringComparison.Ordinal) => true, + 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, _ => false, }; } @@ -176,11 +173,11 @@ namespace Test return name switch { - ReadOnlySpan current when current.Equals(nameof(global::Test.StringTesting.Quotes).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(global::Test.StringTesting.LiteralQuotes).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(global::Test.StringTesting.Backslash).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(global::Test.StringTesting.BackslashLiteral).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(global::Test.StringTesting.NewLine).AsSpan(), global::System.StringComparison.Ordinal) => true, + 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, _ => false, }; } @@ -438,7 +435,7 @@ namespace Test #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name) + in global::System.ReadOnlySpan name) => TryParse(name, out var value, false, false) ? value : ThrowValueNotFound(name.ToString()); /// @@ -453,7 +450,7 @@ namespace Test #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, bool ignoreCase) => TryParse(name, out var value, ignoreCase, false) ? value : ThrowValueNotFound(name.ToString()); @@ -471,7 +468,7 @@ namespace Test #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, bool ignoreCase, bool allowMatchingMetadataAttribute) => TryParse(name, out var value, ignoreCase, allowMatchingMetadataAttribute) ? value : ThrowValueNotFound(name.ToString()); @@ -492,7 +489,7 @@ namespace Test #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::Test.StringTesting value) => TryParse(name, out value, false, false); @@ -513,7 +510,7 @@ namespace Test #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::Test.StringTesting value, bool ignoreCase) => TryParse(name, out value, ignoreCase, false); @@ -537,7 +534,7 @@ namespace Test #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::Test.StringTesting result, bool ignoreCase, bool allowMatchingMetadataAttribute) @@ -549,7 +546,7 @@ namespace Test #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::Test.StringTesting result, bool allowMatchingMetadataAttribute) { @@ -557,19 +554,19 @@ namespace Test { switch (name) { - case ReadOnlySpan current when current.Equals("Quotes \"".AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, "Quotes \"", global::System.StringComparison.OrdinalIgnoreCase): result = global::Test.StringTesting.Quotes; return true; - case ReadOnlySpan current when current.Equals("Literal Quotes \"".AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, "Literal Quotes \"", global::System.StringComparison.OrdinalIgnoreCase): result = global::Test.StringTesting.LiteralQuotes; return true; - case ReadOnlySpan current when current.Equals("Backslash \\".AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, "Backslash \\", global::System.StringComparison.OrdinalIgnoreCase): result = global::Test.StringTesting.Backslash; return true; - case ReadOnlySpan current when current.Equals("LiteralBackslash \\".AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, "LiteralBackslash \\", global::System.StringComparison.OrdinalIgnoreCase): result = global::Test.StringTesting.BackslashLiteral; return true; - case ReadOnlySpan current when current.Equals("New\nLine".AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, "New\nLine", global::System.StringComparison.OrdinalIgnoreCase): result = global::Test.StringTesting.NewLine; return true; default: @@ -579,22 +576,22 @@ namespace Test switch (name) { - case ReadOnlySpan current when current.Equals(nameof(global::Test.StringTesting.Quotes).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::Test.StringTesting.Quotes), global::System.StringComparison.OrdinalIgnoreCase): result = global::Test.StringTesting.Quotes; return true; - case ReadOnlySpan current when current.Equals(nameof(global::Test.StringTesting.LiteralQuotes).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::Test.StringTesting.LiteralQuotes), global::System.StringComparison.OrdinalIgnoreCase): result = global::Test.StringTesting.LiteralQuotes; return true; - case ReadOnlySpan current when current.Equals(nameof(global::Test.StringTesting.Backslash).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::Test.StringTesting.Backslash), global::System.StringComparison.OrdinalIgnoreCase): result = global::Test.StringTesting.Backslash; return true; - case ReadOnlySpan current when current.Equals(nameof(global::Test.StringTesting.BackslashLiteral).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::Test.StringTesting.BackslashLiteral), global::System.StringComparison.OrdinalIgnoreCase): result = global::Test.StringTesting.BackslashLiteral; return true; - case ReadOnlySpan current when current.Equals(nameof(global::Test.StringTesting.NewLine).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::Test.StringTesting.NewLine), global::System.StringComparison.OrdinalIgnoreCase): result = global::Test.StringTesting.NewLine; return true; - case ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): result = (global::Test.StringTesting)numericResult; return true; default: @@ -607,7 +604,7 @@ namespace Test #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::Test.StringTesting result, bool allowMatchingMetadataAttribute) { @@ -615,19 +612,19 @@ namespace Test { switch (name) { - case ReadOnlySpan current when current.Equals("Quotes \"".AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, "Quotes \"", global::System.StringComparison.Ordinal): result = global::Test.StringTesting.Quotes; return true; - case ReadOnlySpan current when current.Equals("Literal Quotes \"".AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, "Literal Quotes \"", global::System.StringComparison.Ordinal): result = global::Test.StringTesting.LiteralQuotes; return true; - case ReadOnlySpan current when current.Equals("Backslash \\".AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, "Backslash \\", global::System.StringComparison.Ordinal): result = global::Test.StringTesting.Backslash; return true; - case ReadOnlySpan current when current.Equals("LiteralBackslash \\".AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, "LiteralBackslash \\", global::System.StringComparison.Ordinal): result = global::Test.StringTesting.BackslashLiteral; return true; - case ReadOnlySpan current when current.Equals("New\nLine".AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, "New\nLine", global::System.StringComparison.Ordinal): result = global::Test.StringTesting.NewLine; return true; default: @@ -637,22 +634,22 @@ namespace Test switch (name) { - case ReadOnlySpan current when current.Equals(nameof(global::Test.StringTesting.Quotes).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::Test.StringTesting.Quotes), global::System.StringComparison.Ordinal): result = global::Test.StringTesting.Quotes; return true; - case ReadOnlySpan current when current.Equals(nameof(global::Test.StringTesting.LiteralQuotes).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::Test.StringTesting.LiteralQuotes), global::System.StringComparison.Ordinal): result = global::Test.StringTesting.LiteralQuotes; return true; - case ReadOnlySpan current when current.Equals(nameof(global::Test.StringTesting.Backslash).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::Test.StringTesting.Backslash), global::System.StringComparison.Ordinal): result = global::Test.StringTesting.Backslash; return true; - case ReadOnlySpan current when current.Equals(nameof(global::Test.StringTesting.BackslashLiteral).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::Test.StringTesting.BackslashLiteral), global::System.StringComparison.Ordinal): result = global::Test.StringTesting.BackslashLiteral; return true; - case ReadOnlySpan current when current.Equals(nameof(global::Test.StringTesting.NewLine).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::Test.StringTesting.NewLine), global::System.StringComparison.Ordinal): result = global::Test.StringTesting.NewLine; return true; - case ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): result = (global::Test.StringTesting)numericResult; return true; default: diff --git a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.CanHandleEnumsWithSameNameInDifferentNamespaces.verified.txt b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.CanHandleEnumsWithSameNameInDifferentNamespaces.verified.txt index 8a7a66f..a28d497 100644 --- a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.CanHandleEnumsWithSameNameInDifferentNamespaces.verified.txt +++ b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.CanHandleEnumsWithSameNameInDifferentNamespaces.verified.txt @@ -98,9 +98,6 @@ namespace NetEscapades.EnumGenerators //------------------------------------------------------------------------------ #nullable enable -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 -using System; -#endif namespace Foo { @@ -209,7 +206,7 @@ namespace Foo /// /// The name to check if it's defined /// true if a member with the name exists in the enumeration, false otherwise - public static bool IsDefined(in ReadOnlySpan name) => IsDefined(name, allowMatchingMetadataAttribute: false); + public static bool IsDefined(in global::System.ReadOnlySpan name) => IsDefined(name, allowMatchingMetadataAttribute: false); /// /// Returns a boolean telling whether an enum with the given name exists in the enumeration, @@ -221,13 +218,13 @@ namespace Foo /// If true, considers the value of metadata attributes,otherwise ignores them /// true if a member with the name exists in the enumeration, or a member is decorated /// with a [Display] attribute with the name, false otherwise - public static bool IsDefined(in ReadOnlySpan name, bool allowMatchingMetadataAttribute) + public static bool IsDefined(in global::System.ReadOnlySpan name, bool allowMatchingMetadataAttribute) { return name switch { - ReadOnlySpan current when current.Equals(nameof(global::Foo.MyEnum.First).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(global::Foo.MyEnum.Second).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(global::Foo.MyEnum.Third).AsSpan(), global::System.StringComparison.Ordinal) => true, + 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, _ => false, }; } @@ -427,7 +424,7 @@ namespace Foo #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name) + in global::System.ReadOnlySpan name) => TryParse(name, out var value, false, false) ? value : ThrowValueNotFound(name.ToString()); /// @@ -442,7 +439,7 @@ namespace Foo #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, bool ignoreCase) => TryParse(name, out var value, ignoreCase, false) ? value : ThrowValueNotFound(name.ToString()); @@ -460,7 +457,7 @@ namespace Foo #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, bool ignoreCase, bool allowMatchingMetadataAttribute) => TryParse(name, out var value, ignoreCase, allowMatchingMetadataAttribute) ? value : ThrowValueNotFound(name.ToString()); @@ -481,7 +478,7 @@ namespace Foo #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::Foo.MyEnum value) => TryParse(name, out value, false, false); @@ -502,7 +499,7 @@ namespace Foo #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::Foo.MyEnum value, bool ignoreCase) => TryParse(name, out value, ignoreCase, false); @@ -526,7 +523,7 @@ namespace Foo #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::Foo.MyEnum result, bool ignoreCase, bool allowMatchingMetadataAttribute) @@ -538,22 +535,22 @@ namespace Foo #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::Foo.MyEnum result, bool allowMatchingMetadataAttribute) { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(global::Foo.MyEnum.First).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::Foo.MyEnum.First), global::System.StringComparison.OrdinalIgnoreCase): result = global::Foo.MyEnum.First; return true; - case ReadOnlySpan current when current.Equals(nameof(global::Foo.MyEnum.Second).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::Foo.MyEnum.Second), global::System.StringComparison.OrdinalIgnoreCase): result = global::Foo.MyEnum.Second; return true; - case ReadOnlySpan current when current.Equals(nameof(global::Foo.MyEnum.Third).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::Foo.MyEnum.Third), global::System.StringComparison.OrdinalIgnoreCase): result = global::Foo.MyEnum.Third; return true; - case ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): result = (global::Foo.MyEnum)numericResult; return true; default: @@ -566,22 +563,22 @@ namespace Foo #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::Foo.MyEnum result, bool allowMatchingMetadataAttribute) { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(global::Foo.MyEnum.First).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::Foo.MyEnum.First), global::System.StringComparison.Ordinal): result = global::Foo.MyEnum.First; return true; - case ReadOnlySpan current when current.Equals(nameof(global::Foo.MyEnum.Second).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::Foo.MyEnum.Second), global::System.StringComparison.Ordinal): result = global::Foo.MyEnum.Second; return true; - case ReadOnlySpan current when current.Equals(nameof(global::Foo.MyEnum.Third).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::Foo.MyEnum.Third), global::System.StringComparison.Ordinal): result = global::Foo.MyEnum.Third; return true; - case ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): result = (global::Foo.MyEnum)numericResult; return true; default: @@ -639,9 +636,6 @@ namespace Foo //------------------------------------------------------------------------------ #nullable enable -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 -using System; -#endif namespace Bar { @@ -750,7 +744,7 @@ namespace Bar /// /// The name to check if it's defined /// true if a member with the name exists in the enumeration, false otherwise - public static bool IsDefined(in ReadOnlySpan name) => IsDefined(name, allowMatchingMetadataAttribute: false); + public static bool IsDefined(in global::System.ReadOnlySpan name) => IsDefined(name, allowMatchingMetadataAttribute: false); /// /// Returns a boolean telling whether an enum with the given name exists in the enumeration, @@ -762,13 +756,13 @@ namespace Bar /// If true, considers the value of metadata attributes,otherwise ignores them /// true if a member with the name exists in the enumeration, or a member is decorated /// with a [Display] attribute with the name, false otherwise - public static bool IsDefined(in ReadOnlySpan name, bool allowMatchingMetadataAttribute) + public static bool IsDefined(in global::System.ReadOnlySpan name, bool allowMatchingMetadataAttribute) { return name switch { - ReadOnlySpan current when current.Equals(nameof(global::Bar.MyEnum.First).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(global::Bar.MyEnum.Second).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(global::Bar.MyEnum.Third).AsSpan(), global::System.StringComparison.Ordinal) => true, + 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, _ => false, }; } @@ -968,7 +962,7 @@ namespace Bar #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name) + in global::System.ReadOnlySpan name) => TryParse(name, out var value, false, false) ? value : ThrowValueNotFound(name.ToString()); /// @@ -983,7 +977,7 @@ namespace Bar #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, bool ignoreCase) => TryParse(name, out var value, ignoreCase, false) ? value : ThrowValueNotFound(name.ToString()); @@ -1001,7 +995,7 @@ namespace Bar #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, bool ignoreCase, bool allowMatchingMetadataAttribute) => TryParse(name, out var value, ignoreCase, allowMatchingMetadataAttribute) ? value : ThrowValueNotFound(name.ToString()); @@ -1022,7 +1016,7 @@ namespace Bar #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::Bar.MyEnum value) => TryParse(name, out value, false, false); @@ -1043,7 +1037,7 @@ namespace Bar #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::Bar.MyEnum value, bool ignoreCase) => TryParse(name, out value, ignoreCase, false); @@ -1067,7 +1061,7 @@ namespace Bar #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::Bar.MyEnum result, bool ignoreCase, bool allowMatchingMetadataAttribute) @@ -1079,22 +1073,22 @@ namespace Bar #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::Bar.MyEnum result, bool allowMatchingMetadataAttribute) { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(global::Bar.MyEnum.First).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::Bar.MyEnum.First), global::System.StringComparison.OrdinalIgnoreCase): result = global::Bar.MyEnum.First; return true; - case ReadOnlySpan current when current.Equals(nameof(global::Bar.MyEnum.Second).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::Bar.MyEnum.Second), global::System.StringComparison.OrdinalIgnoreCase): result = global::Bar.MyEnum.Second; return true; - case ReadOnlySpan current when current.Equals(nameof(global::Bar.MyEnum.Third).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::Bar.MyEnum.Third), global::System.StringComparison.OrdinalIgnoreCase): result = global::Bar.MyEnum.Third; return true; - case ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): result = (global::Bar.MyEnum)numericResult; return true; default: @@ -1107,22 +1101,22 @@ namespace Bar #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::Bar.MyEnum result, bool allowMatchingMetadataAttribute) { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(global::Bar.MyEnum.First).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::Bar.MyEnum.First), global::System.StringComparison.Ordinal): result = global::Bar.MyEnum.First; return true; - case ReadOnlySpan current when current.Equals(nameof(global::Bar.MyEnum.Second).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::Bar.MyEnum.Second), global::System.StringComparison.Ordinal): result = global::Bar.MyEnum.Second; return true; - case ReadOnlySpan current when current.Equals(nameof(global::Bar.MyEnum.Third).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::Bar.MyEnum.Third), global::System.StringComparison.Ordinal): result = global::Bar.MyEnum.Third; return true; - case ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): result = (global::Bar.MyEnum)numericResult; return true; default: diff --git a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.CanInterceptEnumInDifferentNamespace.verified.txt b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.CanInterceptEnumInDifferentNamespace.verified.txt index fd079f1..c5ba686 100644 --- a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.CanInterceptEnumInDifferentNamespace.verified.txt +++ b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.CanInterceptEnumInDifferentNamespace.verified.txt @@ -98,9 +98,6 @@ namespace NetEscapades.EnumGenerators //------------------------------------------------------------------------------ #nullable enable -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 -using System; -#endif namespace Bar { @@ -209,7 +206,7 @@ namespace Bar /// /// The name to check if it's defined /// true if a member with the name exists in the enumeration, false otherwise - public static bool IsDefined(in ReadOnlySpan name) => IsDefined(name, allowMatchingMetadataAttribute: false); + public static bool IsDefined(in global::System.ReadOnlySpan name) => IsDefined(name, allowMatchingMetadataAttribute: false); /// /// Returns a boolean telling whether an enum with the given name exists in the enumeration, @@ -221,13 +218,13 @@ namespace Bar /// If true, considers the value of metadata attributes,otherwise ignores them /// true if a member with the name exists in the enumeration, or a member is decorated /// with a [Display] attribute with the name, false otherwise - public static bool IsDefined(in ReadOnlySpan name, bool allowMatchingMetadataAttribute) + public static bool IsDefined(in global::System.ReadOnlySpan name, bool allowMatchingMetadataAttribute) { return name switch { - ReadOnlySpan current when current.Equals(nameof(global::Foo.MyEnum.First).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(global::Foo.MyEnum.Second).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(global::Foo.MyEnum.Third).AsSpan(), global::System.StringComparison.Ordinal) => true, + 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, _ => false, }; } @@ -427,7 +424,7 @@ namespace Bar #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name) + in global::System.ReadOnlySpan name) => TryParse(name, out var value, false, false) ? value : ThrowValueNotFound(name.ToString()); /// @@ -442,7 +439,7 @@ namespace Bar #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, bool ignoreCase) => TryParse(name, out var value, ignoreCase, false) ? value : ThrowValueNotFound(name.ToString()); @@ -460,7 +457,7 @@ namespace Bar #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, bool ignoreCase, bool allowMatchingMetadataAttribute) => TryParse(name, out var value, ignoreCase, allowMatchingMetadataAttribute) ? value : ThrowValueNotFound(name.ToString()); @@ -481,7 +478,7 @@ namespace Bar #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::Foo.MyEnum value) => TryParse(name, out value, false, false); @@ -502,7 +499,7 @@ namespace Bar #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::Foo.MyEnum value, bool ignoreCase) => TryParse(name, out value, ignoreCase, false); @@ -526,7 +523,7 @@ namespace Bar #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::Foo.MyEnum result, bool ignoreCase, bool allowMatchingMetadataAttribute) @@ -538,22 +535,22 @@ namespace Bar #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::Foo.MyEnum result, bool allowMatchingMetadataAttribute) { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(global::Foo.MyEnum.First).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::Foo.MyEnum.First), global::System.StringComparison.OrdinalIgnoreCase): result = global::Foo.MyEnum.First; return true; - case ReadOnlySpan current when current.Equals(nameof(global::Foo.MyEnum.Second).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::Foo.MyEnum.Second), global::System.StringComparison.OrdinalIgnoreCase): result = global::Foo.MyEnum.Second; return true; - case ReadOnlySpan current when current.Equals(nameof(global::Foo.MyEnum.Third).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::Foo.MyEnum.Third), global::System.StringComparison.OrdinalIgnoreCase): result = global::Foo.MyEnum.Third; return true; - case ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): result = (global::Foo.MyEnum)numericResult; return true; default: @@ -566,22 +563,22 @@ namespace Bar #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::Foo.MyEnum result, bool allowMatchingMetadataAttribute) { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(global::Foo.MyEnum.First).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::Foo.MyEnum.First), global::System.StringComparison.Ordinal): result = global::Foo.MyEnum.First; return true; - case ReadOnlySpan current when current.Equals(nameof(global::Foo.MyEnum.Second).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::Foo.MyEnum.Second), global::System.StringComparison.Ordinal): result = global::Foo.MyEnum.Second; return true; - case ReadOnlySpan current when current.Equals(nameof(global::Foo.MyEnum.Third).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::Foo.MyEnum.Third), global::System.StringComparison.Ordinal): result = global::Foo.MyEnum.Third; return true; - case ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): result = (global::Foo.MyEnum)numericResult; return true; default: diff --git a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.CanInterceptEnumInGlobalNamespace.verified.txt b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.CanInterceptEnumInGlobalNamespace.verified.txt index c2d730e..4b45f8f 100644 --- a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.CanInterceptEnumInGlobalNamespace.verified.txt +++ b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.CanInterceptEnumInGlobalNamespace.verified.txt @@ -98,9 +98,6 @@ namespace NetEscapades.EnumGenerators //------------------------------------------------------------------------------ #nullable enable -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 -using System; -#endif #pragma warning disable CS0612 // Ignore usages of obsolete members or enums #pragma warning disable CS0618 // Ignore usages of obsolete members or enums @@ -207,7 +204,7 @@ using System; /// /// The name to check if it's defined /// true if a member with the name exists in the enumeration, false otherwise - public static bool IsDefined(in ReadOnlySpan name) => IsDefined(name, allowMatchingMetadataAttribute: false); + public static bool IsDefined(in global::System.ReadOnlySpan name) => IsDefined(name, allowMatchingMetadataAttribute: false); /// /// Returns a boolean telling whether an enum with the given name exists in the enumeration, @@ -219,13 +216,13 @@ using System; /// If true, considers the value of metadata attributes,otherwise ignores them /// true if a member with the name exists in the enumeration, or a member is decorated /// with a [Display] attribute with the name, false otherwise - public static bool IsDefined(in ReadOnlySpan name, bool allowMatchingMetadataAttribute) + public static bool IsDefined(in global::System.ReadOnlySpan name, bool allowMatchingMetadataAttribute) { return name switch { - ReadOnlySpan current when current.Equals(nameof(global::MyEnum.First).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(global::MyEnum.Second).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(global::MyEnum.Third).AsSpan(), global::System.StringComparison.Ordinal) => true, + 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, _ => false, }; } @@ -425,7 +422,7 @@ using System; #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name) + in global::System.ReadOnlySpan name) => TryParse(name, out var value, false, false) ? value : ThrowValueNotFound(name.ToString()); /// @@ -440,7 +437,7 @@ using System; #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, bool ignoreCase) => TryParse(name, out var value, ignoreCase, false) ? value : ThrowValueNotFound(name.ToString()); @@ -458,7 +455,7 @@ using System; #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, bool ignoreCase, bool allowMatchingMetadataAttribute) => TryParse(name, out var value, ignoreCase, allowMatchingMetadataAttribute) ? value : ThrowValueNotFound(name.ToString()); @@ -479,7 +476,7 @@ using System; #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyEnum value) => TryParse(name, out value, false, false); @@ -500,7 +497,7 @@ using System; #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyEnum value, bool ignoreCase) => TryParse(name, out value, ignoreCase, false); @@ -524,7 +521,7 @@ using System; #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyEnum result, bool ignoreCase, bool allowMatchingMetadataAttribute) @@ -536,22 +533,22 @@ using System; #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyEnum result, bool allowMatchingMetadataAttribute) { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(global::MyEnum.First).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyEnum.First), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyEnum.First; return true; - case ReadOnlySpan current when current.Equals(nameof(global::MyEnum.Second).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyEnum.Second), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyEnum.Second; return true; - case ReadOnlySpan current when current.Equals(nameof(global::MyEnum.Third).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyEnum.Third), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyEnum.Third; return true; - case ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): result = (global::MyEnum)numericResult; return true; default: @@ -564,22 +561,22 @@ using System; #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyEnum result, bool allowMatchingMetadataAttribute) { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(global::MyEnum.First).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyEnum.First), global::System.StringComparison.Ordinal): result = global::MyEnum.First; return true; - case ReadOnlySpan current when current.Equals(nameof(global::MyEnum.Second).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyEnum.Second), global::System.StringComparison.Ordinal): result = global::MyEnum.Second; return true; - case ReadOnlySpan current when current.Equals(nameof(global::MyEnum.Third).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyEnum.Third), global::System.StringComparison.Ordinal): result = global::MyEnum.Third; return true; - case ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): result = (global::MyEnum)numericResult; return true; default: diff --git a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.CanInterceptExternalEnumToString.verified.txt b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.CanInterceptExternalEnumToString.verified.txt index c545abc..da91d98 100644 --- a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.CanInterceptExternalEnumToString.verified.txt +++ b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.CanInterceptExternalEnumToString.verified.txt @@ -98,9 +98,6 @@ namespace NetEscapades.EnumGenerators //------------------------------------------------------------------------------ #nullable enable -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 -using System; -#endif namespace System { @@ -206,7 +203,7 @@ namespace System /// /// The name to check if it's defined /// true if a member with the name exists in the enumeration, false otherwise - public static bool IsDefined(in ReadOnlySpan name) => IsDefined(name, allowMatchingMetadataAttribute: false); + public static bool IsDefined(in global::System.ReadOnlySpan name) => IsDefined(name, allowMatchingMetadataAttribute: false); /// /// Returns a boolean telling whether an enum with the given name exists in the enumeration, @@ -218,16 +215,16 @@ namespace System /// If true, considers the value of metadata attributes,otherwise ignores them /// true if a member with the name exists in the enumeration, or a member is decorated /// with a [Display] attribute with the name, false otherwise - public static bool IsDefined(in ReadOnlySpan name, bool allowMatchingMetadataAttribute) + public static bool IsDefined(in global::System.ReadOnlySpan name, bool allowMatchingMetadataAttribute) { return name switch { - ReadOnlySpan current when current.Equals(nameof(global::System.StringComparison.CurrentCulture).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(global::System.StringComparison.CurrentCultureIgnoreCase).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(global::System.StringComparison.InvariantCulture).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(global::System.StringComparison.InvariantCultureIgnoreCase).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(global::System.StringComparison.Ordinal).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(global::System.StringComparison.OrdinalIgnoreCase).AsSpan(), global::System.StringComparison.Ordinal) => true, + 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, _ => false, }; } @@ -445,7 +442,7 @@ namespace System #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name) + in global::System.ReadOnlySpan name) => TryParse(name, out var value, false, false) ? value : ThrowValueNotFound(name.ToString()); /// @@ -460,7 +457,7 @@ namespace System #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, bool ignoreCase) => TryParse(name, out var value, ignoreCase, false) ? value : ThrowValueNotFound(name.ToString()); @@ -478,7 +475,7 @@ namespace System #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, bool ignoreCase, bool allowMatchingMetadataAttribute) => TryParse(name, out var value, ignoreCase, allowMatchingMetadataAttribute) ? value : ThrowValueNotFound(name.ToString()); @@ -499,7 +496,7 @@ namespace System #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::System.StringComparison value) => TryParse(name, out value, false, false); @@ -520,7 +517,7 @@ namespace System #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::System.StringComparison value, bool ignoreCase) => TryParse(name, out value, ignoreCase, false); @@ -544,7 +541,7 @@ namespace System #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::System.StringComparison result, bool ignoreCase, bool allowMatchingMetadataAttribute) @@ -556,31 +553,31 @@ namespace System #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::System.StringComparison result, bool allowMatchingMetadataAttribute) { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(global::System.StringComparison.CurrentCulture).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.CurrentCulture), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.StringComparison.CurrentCulture; return true; - case ReadOnlySpan current when current.Equals(nameof(global::System.StringComparison.CurrentCultureIgnoreCase).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.CurrentCultureIgnoreCase), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.StringComparison.CurrentCultureIgnoreCase; return true; - case ReadOnlySpan current when current.Equals(nameof(global::System.StringComparison.InvariantCulture).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.InvariantCulture), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.StringComparison.InvariantCulture; return true; - case ReadOnlySpan current when current.Equals(nameof(global::System.StringComparison.InvariantCultureIgnoreCase).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.InvariantCultureIgnoreCase), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.StringComparison.InvariantCultureIgnoreCase; return true; - case ReadOnlySpan current when current.Equals(nameof(global::System.StringComparison.Ordinal).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.Ordinal), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.StringComparison.Ordinal; return true; - case ReadOnlySpan current when current.Equals(nameof(global::System.StringComparison.OrdinalIgnoreCase).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.OrdinalIgnoreCase), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.StringComparison.OrdinalIgnoreCase; return true; - case ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): result = (global::System.StringComparison)numericResult; return true; default: @@ -593,31 +590,31 @@ namespace System #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::System.StringComparison result, bool allowMatchingMetadataAttribute) { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(global::System.StringComparison.CurrentCulture).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.CurrentCulture), global::System.StringComparison.Ordinal): result = global::System.StringComparison.CurrentCulture; return true; - case ReadOnlySpan current when current.Equals(nameof(global::System.StringComparison.CurrentCultureIgnoreCase).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.CurrentCultureIgnoreCase), global::System.StringComparison.Ordinal): result = global::System.StringComparison.CurrentCultureIgnoreCase; return true; - case ReadOnlySpan current when current.Equals(nameof(global::System.StringComparison.InvariantCulture).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.InvariantCulture), global::System.StringComparison.Ordinal): result = global::System.StringComparison.InvariantCulture; return true; - case ReadOnlySpan current when current.Equals(nameof(global::System.StringComparison.InvariantCultureIgnoreCase).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.InvariantCultureIgnoreCase), global::System.StringComparison.Ordinal): result = global::System.StringComparison.InvariantCultureIgnoreCase; return true; - case ReadOnlySpan current when current.Equals(nameof(global::System.StringComparison.Ordinal).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.Ordinal), global::System.StringComparison.Ordinal): result = global::System.StringComparison.Ordinal; return true; - case ReadOnlySpan current when current.Equals(nameof(global::System.StringComparison.OrdinalIgnoreCase).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.OrdinalIgnoreCase), global::System.StringComparison.Ordinal): result = global::System.StringComparison.OrdinalIgnoreCase; return true; - case ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): result = (global::System.StringComparison)numericResult; return true; default: diff --git a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.CanInterceptHasFlag.verified.txt b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.CanInterceptHasFlag.verified.txt index cc4a98f..245c538 100644 --- a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.CanInterceptHasFlag.verified.txt +++ b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.CanInterceptHasFlag.verified.txt @@ -98,9 +98,6 @@ namespace NetEscapades.EnumGenerators //------------------------------------------------------------------------------ #nullable enable -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 -using System; -#endif namespace MyTestNameSpace { @@ -209,7 +206,7 @@ namespace MyTestNameSpace /// /// The name to check if it's defined /// true if a member with the name exists in the enumeration, false otherwise - public static bool IsDefined(in ReadOnlySpan name) => IsDefined(name, allowMatchingMetadataAttribute: false); + public static bool IsDefined(in global::System.ReadOnlySpan name) => IsDefined(name, allowMatchingMetadataAttribute: false); /// /// Returns a boolean telling whether an enum with the given name exists in the enumeration, @@ -221,13 +218,13 @@ namespace MyTestNameSpace /// If true, considers the value of metadata attributes,otherwise ignores them /// true if a member with the name exists in the enumeration, or a member is decorated /// with a [Display] attribute with the name, false otherwise - public static bool IsDefined(in ReadOnlySpan name, bool allowMatchingMetadataAttribute) + public static bool IsDefined(in global::System.ReadOnlySpan name, bool allowMatchingMetadataAttribute) { return name switch { - ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.First).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.Second).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.Third).AsSpan(), global::System.StringComparison.Ordinal) => true, + 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, _ => false, }; } @@ -427,7 +424,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name) + in global::System.ReadOnlySpan name) => TryParse(name, out var value, false, false) ? value : ThrowValueNotFound(name.ToString()); /// @@ -442,7 +439,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, bool ignoreCase) => TryParse(name, out var value, ignoreCase, false) ? value : ThrowValueNotFound(name.ToString()); @@ -460,7 +457,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, bool ignoreCase, bool allowMatchingMetadataAttribute) => TryParse(name, out var value, ignoreCase, allowMatchingMetadataAttribute) ? value : ThrowValueNotFound(name.ToString()); @@ -481,7 +478,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyTestNameSpace.MyEnum value) => TryParse(name, out value, false, false); @@ -502,7 +499,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyTestNameSpace.MyEnum value, bool ignoreCase) => TryParse(name, out value, ignoreCase, false); @@ -526,7 +523,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyTestNameSpace.MyEnum result, bool ignoreCase, bool allowMatchingMetadataAttribute) @@ -538,22 +535,22 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyTestNameSpace.MyEnum result, bool allowMatchingMetadataAttribute) { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.First).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.First), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyTestNameSpace.MyEnum.First; return true; - case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.Second).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Second), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyTestNameSpace.MyEnum.Second; return true; - case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.Third).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Third), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyTestNameSpace.MyEnum.Third; return true; - case ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): result = (global::MyTestNameSpace.MyEnum)numericResult; return true; default: @@ -566,22 +563,22 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyTestNameSpace.MyEnum result, bool allowMatchingMetadataAttribute) { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.First).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.First), global::System.StringComparison.Ordinal): result = global::MyTestNameSpace.MyEnum.First; return true; - case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.Second).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Second), global::System.StringComparison.Ordinal): result = global::MyTestNameSpace.MyEnum.Second; return true; - case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.Third).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Third), global::System.StringComparison.Ordinal): result = global::MyTestNameSpace.MyEnum.Third; return true; - case ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): result = (global::MyTestNameSpace.MyEnum)numericResult; return true; default: diff --git a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.CanInterceptMultipleEnumsToString.verified.txt b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.CanInterceptMultipleEnumsToString.verified.txt index ebb218b..9d0cfa8 100644 --- a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.CanInterceptMultipleEnumsToString.verified.txt +++ b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.CanInterceptMultipleEnumsToString.verified.txt @@ -98,9 +98,6 @@ namespace NetEscapades.EnumGenerators //------------------------------------------------------------------------------ #nullable enable -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 -using System; -#endif namespace MyTestNameSpace { @@ -197,7 +194,7 @@ namespace MyTestNameSpace /// /// The name to check if it's defined /// true if a member with the name exists in the enumeration, false otherwise - public static bool IsDefined(in ReadOnlySpan name) => IsDefined(name, allowMatchingMetadataAttribute: false); + public static bool IsDefined(in global::System.ReadOnlySpan name) => IsDefined(name, allowMatchingMetadataAttribute: false); /// /// Returns a boolean telling whether an enum with the given name exists in the enumeration, @@ -209,13 +206,13 @@ namespace MyTestNameSpace /// If true, considers the value of metadata attributes,otherwise ignores them /// true if a member with the name exists in the enumeration, or a member is decorated /// with a [Display] attribute with the name, false otherwise - public static bool IsDefined(in ReadOnlySpan name, bool allowMatchingMetadataAttribute) + public static bool IsDefined(in global::System.ReadOnlySpan name, bool allowMatchingMetadataAttribute) { return name switch { - ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.First).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.Second).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.Third).AsSpan(), global::System.StringComparison.Ordinal) => true, + 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, _ => false, }; } @@ -415,7 +412,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name) + in global::System.ReadOnlySpan name) => TryParse(name, out var value, false, false) ? value : ThrowValueNotFound(name.ToString()); /// @@ -430,7 +427,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, bool ignoreCase) => TryParse(name, out var value, ignoreCase, false) ? value : ThrowValueNotFound(name.ToString()); @@ -448,7 +445,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, bool ignoreCase, bool allowMatchingMetadataAttribute) => TryParse(name, out var value, ignoreCase, allowMatchingMetadataAttribute) ? value : ThrowValueNotFound(name.ToString()); @@ -469,7 +466,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyTestNameSpace.MyEnum value) => TryParse(name, out value, false, false); @@ -490,7 +487,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyTestNameSpace.MyEnum value, bool ignoreCase) => TryParse(name, out value, ignoreCase, false); @@ -514,7 +511,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyTestNameSpace.MyEnum result, bool ignoreCase, bool allowMatchingMetadataAttribute) @@ -526,22 +523,22 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyTestNameSpace.MyEnum result, bool allowMatchingMetadataAttribute) { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.First).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.First), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyTestNameSpace.MyEnum.First; return true; - case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.Second).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Second), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyTestNameSpace.MyEnum.Second; return true; - case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.Third).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Third), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyTestNameSpace.MyEnum.Third; return true; - case ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): result = (global::MyTestNameSpace.MyEnum)numericResult; return true; default: @@ -554,22 +551,22 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyTestNameSpace.MyEnum result, bool allowMatchingMetadataAttribute) { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.First).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.First), global::System.StringComparison.Ordinal): result = global::MyTestNameSpace.MyEnum.First; return true; - case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.Second).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Second), global::System.StringComparison.Ordinal): result = global::MyTestNameSpace.MyEnum.Second; return true; - case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.Third).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Third), global::System.StringComparison.Ordinal): result = global::MyTestNameSpace.MyEnum.Third; return true; - case ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): result = (global::MyTestNameSpace.MyEnum)numericResult; return true; default: @@ -627,9 +624,6 @@ namespace MyTestNameSpace //------------------------------------------------------------------------------ #nullable enable -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 -using System; -#endif namespace MyTestNameSpace { @@ -726,7 +720,7 @@ namespace MyTestNameSpace /// /// The name to check if it's defined /// true if a member with the name exists in the enumeration, false otherwise - public static bool IsDefined(in ReadOnlySpan name) => IsDefined(name, allowMatchingMetadataAttribute: false); + public static bool IsDefined(in global::System.ReadOnlySpan name) => IsDefined(name, allowMatchingMetadataAttribute: false); /// /// Returns a boolean telling whether an enum with the given name exists in the enumeration, @@ -738,13 +732,13 @@ namespace MyTestNameSpace /// If true, considers the value of metadata attributes,otherwise ignores them /// true if a member with the name exists in the enumeration, or a member is decorated /// with a [Display] attribute with the name, false otherwise - public static bool IsDefined(in ReadOnlySpan name, bool allowMatchingMetadataAttribute) + public static bool IsDefined(in global::System.ReadOnlySpan name, bool allowMatchingMetadataAttribute) { return name switch { - ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.AnotherEnum.First).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.AnotherEnum.Second).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.AnotherEnum.Third).AsSpan(), global::System.StringComparison.Ordinal) => true, + 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, _ => false, }; } @@ -944,7 +938,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name) + in global::System.ReadOnlySpan name) => TryParse(name, out var value, false, false) ? value : ThrowValueNotFound(name.ToString()); /// @@ -959,7 +953,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, bool ignoreCase) => TryParse(name, out var value, ignoreCase, false) ? value : ThrowValueNotFound(name.ToString()); @@ -977,7 +971,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, bool ignoreCase, bool allowMatchingMetadataAttribute) => TryParse(name, out var value, ignoreCase, allowMatchingMetadataAttribute) ? value : ThrowValueNotFound(name.ToString()); @@ -998,7 +992,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyTestNameSpace.AnotherEnum value) => TryParse(name, out value, false, false); @@ -1019,7 +1013,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyTestNameSpace.AnotherEnum value, bool ignoreCase) => TryParse(name, out value, ignoreCase, false); @@ -1043,7 +1037,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyTestNameSpace.AnotherEnum result, bool ignoreCase, bool allowMatchingMetadataAttribute) @@ -1055,22 +1049,22 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyTestNameSpace.AnotherEnum result, bool allowMatchingMetadataAttribute) { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.AnotherEnum.First).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.AnotherEnum.First), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyTestNameSpace.AnotherEnum.First; return true; - case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.AnotherEnum.Second).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.AnotherEnum.Second), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyTestNameSpace.AnotherEnum.Second; return true; - case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.AnotherEnum.Third).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.AnotherEnum.Third), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyTestNameSpace.AnotherEnum.Third; return true; - case ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): result = (global::MyTestNameSpace.AnotherEnum)numericResult; return true; default: @@ -1083,22 +1077,22 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyTestNameSpace.AnotherEnum result, bool allowMatchingMetadataAttribute) { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.AnotherEnum.First).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.AnotherEnum.First), global::System.StringComparison.Ordinal): result = global::MyTestNameSpace.AnotherEnum.First; return true; - case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.AnotherEnum.Second).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.AnotherEnum.Second), global::System.StringComparison.Ordinal): result = global::MyTestNameSpace.AnotherEnum.Second; return true; - case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.AnotherEnum.Third).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.AnotherEnum.Third), global::System.StringComparison.Ordinal): result = global::MyTestNameSpace.AnotherEnum.Third; return true; - case ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): result = (global::MyTestNameSpace.AnotherEnum)numericResult; return true; default: diff --git a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.CanInterceptToString.verified.txt b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.CanInterceptToString.verified.txt index d13f9a9..2737509 100644 --- a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.CanInterceptToString.verified.txt +++ b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.CanInterceptToString.verified.txt @@ -98,9 +98,6 @@ namespace NetEscapades.EnumGenerators //------------------------------------------------------------------------------ #nullable enable -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 -using System; -#endif namespace MyTestNameSpace { @@ -194,7 +191,7 @@ namespace MyTestNameSpace /// /// The name to check if it's defined /// true if a member with the name exists in the enumeration, false otherwise - public static bool IsDefined(in ReadOnlySpan name) => IsDefined(name, allowMatchingMetadataAttribute: false); + public static bool IsDefined(in global::System.ReadOnlySpan name) => IsDefined(name, allowMatchingMetadataAttribute: false); /// /// Returns a boolean telling whether an enum with the given name exists in the enumeration, @@ -206,12 +203,12 @@ namespace MyTestNameSpace /// If true, considers the value of metadata attributes,otherwise ignores them /// true if a member with the name exists in the enumeration, or a member is decorated /// with a [Display] attribute with the name, false otherwise - public static bool IsDefined(in ReadOnlySpan name, bool allowMatchingMetadataAttribute) + public static bool IsDefined(in global::System.ReadOnlySpan name, bool allowMatchingMetadataAttribute) { return name switch { - ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.First).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.Second).AsSpan(), global::System.StringComparison.Ordinal) => true, + 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, _ => false, }; } @@ -405,7 +402,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name) + in global::System.ReadOnlySpan name) => TryParse(name, out var value, false, false) ? value : ThrowValueNotFound(name.ToString()); /// @@ -420,7 +417,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, bool ignoreCase) => TryParse(name, out var value, ignoreCase, false) ? value : ThrowValueNotFound(name.ToString()); @@ -438,7 +435,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, bool ignoreCase, bool allowMatchingMetadataAttribute) => TryParse(name, out var value, ignoreCase, allowMatchingMetadataAttribute) ? value : ThrowValueNotFound(name.ToString()); @@ -459,7 +456,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyTestNameSpace.MyEnum value) => TryParse(name, out value, false, false); @@ -480,7 +477,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyTestNameSpace.MyEnum value, bool ignoreCase) => TryParse(name, out value, ignoreCase, false); @@ -504,7 +501,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyTestNameSpace.MyEnum result, bool ignoreCase, bool allowMatchingMetadataAttribute) @@ -516,19 +513,19 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyTestNameSpace.MyEnum result, bool allowMatchingMetadataAttribute) { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.First).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.First), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyTestNameSpace.MyEnum.First; return true; - case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.Second).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Second), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyTestNameSpace.MyEnum.Second; return true; - case ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): result = (global::MyTestNameSpace.MyEnum)numericResult; return true; default: @@ -541,19 +538,19 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyTestNameSpace.MyEnum result, bool allowMatchingMetadataAttribute) { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.First).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.First), global::System.StringComparison.Ordinal): result = global::MyTestNameSpace.MyEnum.First; return true; - case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.Second).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Second), global::System.StringComparison.Ordinal): result = global::MyTestNameSpace.MyEnum.Second; return true; - case ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): result = (global::MyTestNameSpace.MyEnum)numericResult; return true; default: diff --git a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.CanInterceptToStringWhenCsharp11.verified.txt b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.CanInterceptToStringWhenCsharp11.verified.txt index d13f9a9..2737509 100644 --- a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.CanInterceptToStringWhenCsharp11.verified.txt +++ b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.CanInterceptToStringWhenCsharp11.verified.txt @@ -98,9 +98,6 @@ namespace NetEscapades.EnumGenerators //------------------------------------------------------------------------------ #nullable enable -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 -using System; -#endif namespace MyTestNameSpace { @@ -194,7 +191,7 @@ namespace MyTestNameSpace /// /// The name to check if it's defined /// true if a member with the name exists in the enumeration, false otherwise - public static bool IsDefined(in ReadOnlySpan name) => IsDefined(name, allowMatchingMetadataAttribute: false); + public static bool IsDefined(in global::System.ReadOnlySpan name) => IsDefined(name, allowMatchingMetadataAttribute: false); /// /// Returns a boolean telling whether an enum with the given name exists in the enumeration, @@ -206,12 +203,12 @@ namespace MyTestNameSpace /// If true, considers the value of metadata attributes,otherwise ignores them /// true if a member with the name exists in the enumeration, or a member is decorated /// with a [Display] attribute with the name, false otherwise - public static bool IsDefined(in ReadOnlySpan name, bool allowMatchingMetadataAttribute) + public static bool IsDefined(in global::System.ReadOnlySpan name, bool allowMatchingMetadataAttribute) { return name switch { - ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.First).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.Second).AsSpan(), global::System.StringComparison.Ordinal) => true, + 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, _ => false, }; } @@ -405,7 +402,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name) + in global::System.ReadOnlySpan name) => TryParse(name, out var value, false, false) ? value : ThrowValueNotFound(name.ToString()); /// @@ -420,7 +417,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, bool ignoreCase) => TryParse(name, out var value, ignoreCase, false) ? value : ThrowValueNotFound(name.ToString()); @@ -438,7 +435,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, bool ignoreCase, bool allowMatchingMetadataAttribute) => TryParse(name, out var value, ignoreCase, allowMatchingMetadataAttribute) ? value : ThrowValueNotFound(name.ToString()); @@ -459,7 +456,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyTestNameSpace.MyEnum value) => TryParse(name, out value, false, false); @@ -480,7 +477,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyTestNameSpace.MyEnum value, bool ignoreCase) => TryParse(name, out value, ignoreCase, false); @@ -504,7 +501,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyTestNameSpace.MyEnum result, bool ignoreCase, bool allowMatchingMetadataAttribute) @@ -516,19 +513,19 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyTestNameSpace.MyEnum result, bool allowMatchingMetadataAttribute) { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.First).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.First), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyTestNameSpace.MyEnum.First; return true; - case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.Second).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Second), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyTestNameSpace.MyEnum.Second; return true; - case ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): result = (global::MyTestNameSpace.MyEnum)numericResult; return true; default: @@ -541,19 +538,19 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyTestNameSpace.MyEnum result, bool allowMatchingMetadataAttribute) { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.First).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.First), global::System.StringComparison.Ordinal): result = global::MyTestNameSpace.MyEnum.First; return true; - case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.Second).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Second), global::System.StringComparison.Ordinal): result = global::MyTestNameSpace.MyEnum.Second; return true; - case ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): result = (global::MyTestNameSpace.MyEnum)numericResult; return true; default: diff --git a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.CanInterceptUsingInterceptableAttributeToString.verified.txt b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.CanInterceptUsingInterceptableAttributeToString.verified.txt index bb7beaf..bff4425 100644 --- a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.CanInterceptUsingInterceptableAttributeToString.verified.txt +++ b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.CanInterceptUsingInterceptableAttributeToString.verified.txt @@ -98,9 +98,6 @@ namespace NetEscapades.EnumGenerators //------------------------------------------------------------------------------ #nullable enable -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 -using System; -#endif namespace System { @@ -206,7 +203,7 @@ namespace System /// /// The name to check if it's defined /// true if a member with the name exists in the enumeration, false otherwise - public static bool IsDefined(in ReadOnlySpan name) => IsDefined(name, allowMatchingMetadataAttribute: false); + public static bool IsDefined(in global::System.ReadOnlySpan name) => IsDefined(name, allowMatchingMetadataAttribute: false); /// /// Returns a boolean telling whether an enum with the given name exists in the enumeration, @@ -218,16 +215,16 @@ namespace System /// If true, considers the value of metadata attributes,otherwise ignores them /// true if a member with the name exists in the enumeration, or a member is decorated /// with a [Display] attribute with the name, false otherwise - public static bool IsDefined(in ReadOnlySpan name, bool allowMatchingMetadataAttribute) + public static bool IsDefined(in global::System.ReadOnlySpan name, bool allowMatchingMetadataAttribute) { return name switch { - ReadOnlySpan current when current.Equals(nameof(global::System.StringComparison.CurrentCulture).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(global::System.StringComparison.CurrentCultureIgnoreCase).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(global::System.StringComparison.InvariantCulture).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(global::System.StringComparison.InvariantCultureIgnoreCase).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(global::System.StringComparison.Ordinal).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(global::System.StringComparison.OrdinalIgnoreCase).AsSpan(), global::System.StringComparison.Ordinal) => true, + 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, _ => false, }; } @@ -445,7 +442,7 @@ namespace System #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name) + in global::System.ReadOnlySpan name) => TryParse(name, out var value, false, false) ? value : ThrowValueNotFound(name.ToString()); /// @@ -460,7 +457,7 @@ namespace System #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, bool ignoreCase) => TryParse(name, out var value, ignoreCase, false) ? value : ThrowValueNotFound(name.ToString()); @@ -478,7 +475,7 @@ namespace System #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, bool ignoreCase, bool allowMatchingMetadataAttribute) => TryParse(name, out var value, ignoreCase, allowMatchingMetadataAttribute) ? value : ThrowValueNotFound(name.ToString()); @@ -499,7 +496,7 @@ namespace System #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::System.StringComparison value) => TryParse(name, out value, false, false); @@ -520,7 +517,7 @@ namespace System #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::System.StringComparison value, bool ignoreCase) => TryParse(name, out value, ignoreCase, false); @@ -544,7 +541,7 @@ namespace System #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::System.StringComparison result, bool ignoreCase, bool allowMatchingMetadataAttribute) @@ -556,31 +553,31 @@ namespace System #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::System.StringComparison result, bool allowMatchingMetadataAttribute) { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(global::System.StringComparison.CurrentCulture).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.CurrentCulture), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.StringComparison.CurrentCulture; return true; - case ReadOnlySpan current when current.Equals(nameof(global::System.StringComparison.CurrentCultureIgnoreCase).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.CurrentCultureIgnoreCase), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.StringComparison.CurrentCultureIgnoreCase; return true; - case ReadOnlySpan current when current.Equals(nameof(global::System.StringComparison.InvariantCulture).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.InvariantCulture), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.StringComparison.InvariantCulture; return true; - case ReadOnlySpan current when current.Equals(nameof(global::System.StringComparison.InvariantCultureIgnoreCase).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.InvariantCultureIgnoreCase), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.StringComparison.InvariantCultureIgnoreCase; return true; - case ReadOnlySpan current when current.Equals(nameof(global::System.StringComparison.Ordinal).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.Ordinal), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.StringComparison.Ordinal; return true; - case ReadOnlySpan current when current.Equals(nameof(global::System.StringComparison.OrdinalIgnoreCase).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.OrdinalIgnoreCase), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.StringComparison.OrdinalIgnoreCase; return true; - case ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): result = (global::System.StringComparison)numericResult; return true; default: @@ -593,31 +590,31 @@ namespace System #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::System.StringComparison result, bool allowMatchingMetadataAttribute) { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(global::System.StringComparison.CurrentCulture).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.CurrentCulture), global::System.StringComparison.Ordinal): result = global::System.StringComparison.CurrentCulture; return true; - case ReadOnlySpan current when current.Equals(nameof(global::System.StringComparison.CurrentCultureIgnoreCase).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.CurrentCultureIgnoreCase), global::System.StringComparison.Ordinal): result = global::System.StringComparison.CurrentCultureIgnoreCase; return true; - case ReadOnlySpan current when current.Equals(nameof(global::System.StringComparison.InvariantCulture).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.InvariantCulture), global::System.StringComparison.Ordinal): result = global::System.StringComparison.InvariantCulture; return true; - case ReadOnlySpan current when current.Equals(nameof(global::System.StringComparison.InvariantCultureIgnoreCase).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.InvariantCultureIgnoreCase), global::System.StringComparison.Ordinal): result = global::System.StringComparison.InvariantCultureIgnoreCase; return true; - case ReadOnlySpan current when current.Equals(nameof(global::System.StringComparison.Ordinal).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.Ordinal), global::System.StringComparison.Ordinal): result = global::System.StringComparison.Ordinal; return true; - case ReadOnlySpan current when current.Equals(nameof(global::System.StringComparison.OrdinalIgnoreCase).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.OrdinalIgnoreCase), global::System.StringComparison.Ordinal): result = global::System.StringComparison.OrdinalIgnoreCase; return true; - case ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): result = (global::System.StringComparison)numericResult; return true; default: diff --git a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.CanNotInterceptEnumWithoutInterceptorPackage.verified.txt b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.CanNotInterceptEnumWithoutInterceptorPackage.verified.txt index 6f3189f..5b77e74 100644 --- a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.CanNotInterceptEnumWithoutInterceptorPackage.verified.txt +++ b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.CanNotInterceptEnumWithoutInterceptorPackage.verified.txt @@ -98,9 +98,6 @@ namespace NetEscapades.EnumGenerators //------------------------------------------------------------------------------ #nullable enable -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 -using System; -#endif namespace MyTestNameSpace { @@ -194,7 +191,7 @@ namespace MyTestNameSpace /// /// The name to check if it's defined /// true if a member with the name exists in the enumeration, false otherwise - public static bool IsDefined(in ReadOnlySpan name) => IsDefined(name, allowMatchingMetadataAttribute: false); + public static bool IsDefined(in global::System.ReadOnlySpan name) => IsDefined(name, allowMatchingMetadataAttribute: false); /// /// Returns a boolean telling whether an enum with the given name exists in the enumeration, @@ -206,12 +203,12 @@ namespace MyTestNameSpace /// If true, considers the value of metadata attributes,otherwise ignores them /// true if a member with the name exists in the enumeration, or a member is decorated /// with a [Display] attribute with the name, false otherwise - public static bool IsDefined(in ReadOnlySpan name, bool allowMatchingMetadataAttribute) + public static bool IsDefined(in global::System.ReadOnlySpan name, bool allowMatchingMetadataAttribute) { return name switch { - ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.First).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.Second).AsSpan(), global::System.StringComparison.Ordinal) => true, + 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, _ => false, }; } @@ -405,7 +402,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name) + in global::System.ReadOnlySpan name) => TryParse(name, out var value, false, false) ? value : ThrowValueNotFound(name.ToString()); /// @@ -420,7 +417,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, bool ignoreCase) => TryParse(name, out var value, ignoreCase, false) ? value : ThrowValueNotFound(name.ToString()); @@ -438,7 +435,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, bool ignoreCase, bool allowMatchingMetadataAttribute) => TryParse(name, out var value, ignoreCase, allowMatchingMetadataAttribute) ? value : ThrowValueNotFound(name.ToString()); @@ -459,7 +456,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyTestNameSpace.MyEnum value) => TryParse(name, out value, false, false); @@ -480,7 +477,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyTestNameSpace.MyEnum value, bool ignoreCase) => TryParse(name, out value, ignoreCase, false); @@ -504,7 +501,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyTestNameSpace.MyEnum result, bool ignoreCase, bool allowMatchingMetadataAttribute) @@ -516,19 +513,19 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyTestNameSpace.MyEnum result, bool allowMatchingMetadataAttribute) { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.First).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.First), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyTestNameSpace.MyEnum.First; return true; - case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.Second).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Second), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyTestNameSpace.MyEnum.Second; return true; - case ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): result = (global::MyTestNameSpace.MyEnum)numericResult; return true; default: @@ -541,19 +538,19 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyTestNameSpace.MyEnum result, bool allowMatchingMetadataAttribute) { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.First).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.First), global::System.StringComparison.Ordinal): result = global::MyTestNameSpace.MyEnum.First; return true; - case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.Second).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Second), global::System.StringComparison.Ordinal): result = global::MyTestNameSpace.MyEnum.Second; return true; - case ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): result = (global::MyTestNameSpace.MyEnum)numericResult; return true; default: diff --git a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.CanNotInterceptUsageInStringInterpolation.verified.txt b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.CanNotInterceptUsageInStringInterpolation.verified.txt index aa01dff..d458497 100644 --- a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.CanNotInterceptUsageInStringInterpolation.verified.txt +++ b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.CanNotInterceptUsageInStringInterpolation.verified.txt @@ -1,4 +1,4 @@ -[ +[ //------------------------------------------------------------------------------ // // This code was generated by the NetEscapades.EnumGenerators source generator @@ -98,9 +98,6 @@ namespace NetEscapades.EnumGenerators //------------------------------------------------------------------------------ #nullable enable -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 -using System; -#endif namespace MyTestNameSpace { @@ -194,7 +191,7 @@ namespace MyTestNameSpace /// /// The name to check if it's defined /// true if a member with the name exists in the enumeration, false otherwise - public static bool IsDefined(in ReadOnlySpan name) => IsDefined(name, allowMatchingMetadataAttribute: false); + public static bool IsDefined(in global::System.ReadOnlySpan name) => IsDefined(name, allowMatchingMetadataAttribute: false); /// /// Returns a boolean telling whether an enum with the given name exists in the enumeration, @@ -206,12 +203,12 @@ namespace MyTestNameSpace /// If true, considers the value of metadata attributes,otherwise ignores them /// true if a member with the name exists in the enumeration, or a member is decorated /// with a [Display] attribute with the name, false otherwise - public static bool IsDefined(in ReadOnlySpan name, bool allowMatchingMetadataAttribute) + public static bool IsDefined(in global::System.ReadOnlySpan name, bool allowMatchingMetadataAttribute) { return name switch { - ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.First).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.Second).AsSpan(), global::System.StringComparison.Ordinal) => true, + 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, _ => false, }; } @@ -405,7 +402,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name) + in global::System.ReadOnlySpan name) => TryParse(name, out var value, false, false) ? value : ThrowValueNotFound(name.ToString()); /// @@ -420,7 +417,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, bool ignoreCase) => TryParse(name, out var value, ignoreCase, false) ? value : ThrowValueNotFound(name.ToString()); @@ -438,7 +435,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, bool ignoreCase, bool allowMatchingMetadataAttribute) => TryParse(name, out var value, ignoreCase, allowMatchingMetadataAttribute) ? value : ThrowValueNotFound(name.ToString()); @@ -459,7 +456,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyTestNameSpace.MyEnum value) => TryParse(name, out value, false, false); @@ -480,7 +477,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyTestNameSpace.MyEnum value, bool ignoreCase) => TryParse(name, out value, ignoreCase, false); @@ -504,7 +501,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyTestNameSpace.MyEnum result, bool ignoreCase, bool allowMatchingMetadataAttribute) @@ -516,19 +513,19 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyTestNameSpace.MyEnum result, bool allowMatchingMetadataAttribute) { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.First).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.First), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyTestNameSpace.MyEnum.First; return true; - case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.Second).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Second), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyTestNameSpace.MyEnum.Second; return true; - case ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): result = (global::MyTestNameSpace.MyEnum)numericResult; return true; default: @@ -541,19 +538,19 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyTestNameSpace.MyEnum result, bool allowMatchingMetadataAttribute) { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.First).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.First), global::System.StringComparison.Ordinal): result = global::MyTestNameSpace.MyEnum.First; return true; - case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.Second).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Second), global::System.StringComparison.Ordinal): result = global::MyTestNameSpace.MyEnum.Second; return true; - case ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): result = (global::MyTestNameSpace.MyEnum)numericResult; return true; default: diff --git a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.CanNotInterceptUsageWithEnumDirectly.verified.txt b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.CanNotInterceptUsageWithEnumDirectly.verified.txt index aa01dff..d458497 100644 --- a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.CanNotInterceptUsageWithEnumDirectly.verified.txt +++ b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.CanNotInterceptUsageWithEnumDirectly.verified.txt @@ -1,4 +1,4 @@ -[ +[ //------------------------------------------------------------------------------ // // This code was generated by the NetEscapades.EnumGenerators source generator @@ -98,9 +98,6 @@ namespace NetEscapades.EnumGenerators //------------------------------------------------------------------------------ #nullable enable -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 -using System; -#endif namespace MyTestNameSpace { @@ -194,7 +191,7 @@ namespace MyTestNameSpace /// /// The name to check if it's defined /// true if a member with the name exists in the enumeration, false otherwise - public static bool IsDefined(in ReadOnlySpan name) => IsDefined(name, allowMatchingMetadataAttribute: false); + public static bool IsDefined(in global::System.ReadOnlySpan name) => IsDefined(name, allowMatchingMetadataAttribute: false); /// /// Returns a boolean telling whether an enum with the given name exists in the enumeration, @@ -206,12 +203,12 @@ namespace MyTestNameSpace /// If true, considers the value of metadata attributes,otherwise ignores them /// true if a member with the name exists in the enumeration, or a member is decorated /// with a [Display] attribute with the name, false otherwise - public static bool IsDefined(in ReadOnlySpan name, bool allowMatchingMetadataAttribute) + public static bool IsDefined(in global::System.ReadOnlySpan name, bool allowMatchingMetadataAttribute) { return name switch { - ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.First).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.Second).AsSpan(), global::System.StringComparison.Ordinal) => true, + 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, _ => false, }; } @@ -405,7 +402,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name) + in global::System.ReadOnlySpan name) => TryParse(name, out var value, false, false) ? value : ThrowValueNotFound(name.ToString()); /// @@ -420,7 +417,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, bool ignoreCase) => TryParse(name, out var value, ignoreCase, false) ? value : ThrowValueNotFound(name.ToString()); @@ -438,7 +435,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, bool ignoreCase, bool allowMatchingMetadataAttribute) => TryParse(name, out var value, ignoreCase, allowMatchingMetadataAttribute) ? value : ThrowValueNotFound(name.ToString()); @@ -459,7 +456,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyTestNameSpace.MyEnum value) => TryParse(name, out value, false, false); @@ -480,7 +477,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyTestNameSpace.MyEnum value, bool ignoreCase) => TryParse(name, out value, ignoreCase, false); @@ -504,7 +501,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyTestNameSpace.MyEnum result, bool ignoreCase, bool allowMatchingMetadataAttribute) @@ -516,19 +513,19 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyTestNameSpace.MyEnum result, bool allowMatchingMetadataAttribute) { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.First).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.First), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyTestNameSpace.MyEnum.First; return true; - case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.Second).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Second), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyTestNameSpace.MyEnum.Second; return true; - case ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): result = (global::MyTestNameSpace.MyEnum)numericResult; return true; default: @@ -541,19 +538,19 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyTestNameSpace.MyEnum result, bool allowMatchingMetadataAttribute) { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.First).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.First), global::System.StringComparison.Ordinal): result = global::MyTestNameSpace.MyEnum.First; return true; - case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.Second).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Second), global::System.StringComparison.Ordinal): result = global::MyTestNameSpace.MyEnum.Second; return true; - case ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): result = (global::MyTestNameSpace.MyEnum)numericResult; return true; default: 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 9ec782b..de9138c 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 @@ -8,9 +8,6 @@ //------------------------------------------------------------------------------ #nullable enable -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 -using System; -#endif #pragma warning disable CS0612 // Ignore usages of obsolete members or enums #pragma warning disable CS0618 // Ignore usages of obsolete members or enums @@ -102,7 +99,7 @@ using System; /// /// The name to check if it's defined /// true if a member with the name exists in the enumeration, false otherwise - public static bool IsDefined(in ReadOnlySpan name) => IsDefined(name, allowMatchingMetadataAttribute: false); + public static bool IsDefined(in global::System.ReadOnlySpan name) => IsDefined(name, allowMatchingMetadataAttribute: false); /// /// Returns a boolean telling whether an enum with the given name exists in the enumeration, @@ -114,12 +111,12 @@ using System; /// If true, considers the value of metadata attributes,otherwise ignores them /// true if a member with the name exists in the enumeration, or a member is decorated /// with a [Display] attribute with the name, false otherwise - public static bool IsDefined(in ReadOnlySpan name, bool allowMatchingMetadataAttribute) + public static bool IsDefined(in global::System.ReadOnlySpan name, bool allowMatchingMetadataAttribute) { return name switch { - ReadOnlySpan current when current.Equals(nameof(global::OtherEnum.First).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(global::OtherEnum.Second).AsSpan(), global::System.StringComparison.Ordinal) => true, + 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, _ => false, }; } @@ -313,7 +310,7 @@ using System; #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name) + in global::System.ReadOnlySpan name) => TryParse(name, out var value, false, false) ? value : ThrowValueNotFound(name.ToString()); /// @@ -328,7 +325,7 @@ using System; #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, bool ignoreCase) => TryParse(name, out var value, ignoreCase, false) ? value : ThrowValueNotFound(name.ToString()); @@ -346,7 +343,7 @@ using System; #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, bool ignoreCase, bool allowMatchingMetadataAttribute) => TryParse(name, out var value, ignoreCase, allowMatchingMetadataAttribute) ? value : ThrowValueNotFound(name.ToString()); @@ -367,7 +364,7 @@ using System; #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::OtherEnum value) => TryParse(name, out value, false, false); @@ -388,7 +385,7 @@ using System; #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::OtherEnum value, bool ignoreCase) => TryParse(name, out value, ignoreCase, false); @@ -412,7 +409,7 @@ using System; #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::OtherEnum result, bool ignoreCase, bool allowMatchingMetadataAttribute) @@ -424,19 +421,19 @@ using System; #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::OtherEnum result, bool allowMatchingMetadataAttribute) { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(global::OtherEnum.First).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::OtherEnum.First), global::System.StringComparison.OrdinalIgnoreCase): result = global::OtherEnum.First; return true; - case ReadOnlySpan current when current.Equals(nameof(global::OtherEnum.Second).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::OtherEnum.Second), global::System.StringComparison.OrdinalIgnoreCase): result = global::OtherEnum.Second; return true; - case ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): result = (global::OtherEnum)numericResult; return true; default: @@ -449,19 +446,19 @@ using System; #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::OtherEnum result, bool allowMatchingMetadataAttribute) { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(global::OtherEnum.First).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::OtherEnum.First), global::System.StringComparison.Ordinal): result = global::OtherEnum.First; return true; - case ReadOnlySpan current when current.Equals(nameof(global::OtherEnum.Second).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::OtherEnum.Second), global::System.StringComparison.Ordinal): result = global::OtherEnum.Second; return true; - case ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): result = (global::OtherEnum)numericResult; return true; default: 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 9ec782b..de9138c 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 @@ -8,9 +8,6 @@ //------------------------------------------------------------------------------ #nullable enable -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 -using System; -#endif #pragma warning disable CS0612 // Ignore usages of obsolete members or enums #pragma warning disable CS0618 // Ignore usages of obsolete members or enums @@ -102,7 +99,7 @@ using System; /// /// The name to check if it's defined /// true if a member with the name exists in the enumeration, false otherwise - public static bool IsDefined(in ReadOnlySpan name) => IsDefined(name, allowMatchingMetadataAttribute: false); + public static bool IsDefined(in global::System.ReadOnlySpan name) => IsDefined(name, allowMatchingMetadataAttribute: false); /// /// Returns a boolean telling whether an enum with the given name exists in the enumeration, @@ -114,12 +111,12 @@ using System; /// If true, considers the value of metadata attributes,otherwise ignores them /// true if a member with the name exists in the enumeration, or a member is decorated /// with a [Display] attribute with the name, false otherwise - public static bool IsDefined(in ReadOnlySpan name, bool allowMatchingMetadataAttribute) + public static bool IsDefined(in global::System.ReadOnlySpan name, bool allowMatchingMetadataAttribute) { return name switch { - ReadOnlySpan current when current.Equals(nameof(global::OtherEnum.First).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(global::OtherEnum.Second).AsSpan(), global::System.StringComparison.Ordinal) => true, + 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, _ => false, }; } @@ -313,7 +310,7 @@ using System; #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name) + in global::System.ReadOnlySpan name) => TryParse(name, out var value, false, false) ? value : ThrowValueNotFound(name.ToString()); /// @@ -328,7 +325,7 @@ using System; #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, bool ignoreCase) => TryParse(name, out var value, ignoreCase, false) ? value : ThrowValueNotFound(name.ToString()); @@ -346,7 +343,7 @@ using System; #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, bool ignoreCase, bool allowMatchingMetadataAttribute) => TryParse(name, out var value, ignoreCase, allowMatchingMetadataAttribute) ? value : ThrowValueNotFound(name.ToString()); @@ -367,7 +364,7 @@ using System; #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::OtherEnum value) => TryParse(name, out value, false, false); @@ -388,7 +385,7 @@ using System; #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::OtherEnum value, bool ignoreCase) => TryParse(name, out value, ignoreCase, false); @@ -412,7 +409,7 @@ using System; #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::OtherEnum result, bool ignoreCase, bool allowMatchingMetadataAttribute) @@ -424,19 +421,19 @@ using System; #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::OtherEnum result, bool allowMatchingMetadataAttribute) { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(global::OtherEnum.First).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::OtherEnum.First), global::System.StringComparison.OrdinalIgnoreCase): result = global::OtherEnum.First; return true; - case ReadOnlySpan current when current.Equals(nameof(global::OtherEnum.Second).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::OtherEnum.Second), global::System.StringComparison.OrdinalIgnoreCase): result = global::OtherEnum.Second; return true; - case ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): result = (global::OtherEnum)numericResult; return true; default: @@ -449,19 +446,19 @@ using System; #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::OtherEnum result, bool allowMatchingMetadataAttribute) { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(global::OtherEnum.First).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::OtherEnum.First), global::System.StringComparison.Ordinal): result = global::OtherEnum.First; return true; - case ReadOnlySpan current when current.Equals(nameof(global::OtherEnum.Second).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::OtherEnum.Second), global::System.StringComparison.Ordinal): result = global::OtherEnum.Second; return true; - case ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): result = (global::OtherEnum)numericResult; return true; default: diff --git a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.DoesNotInterceptEnumMarkedAsNotInterceptable.verified.txt b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.DoesNotInterceptEnumMarkedAsNotInterceptable.verified.txt index 6bdf55e..9c92bc8 100644 --- a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.DoesNotInterceptEnumMarkedAsNotInterceptable.verified.txt +++ b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.DoesNotInterceptEnumMarkedAsNotInterceptable.verified.txt @@ -98,9 +98,6 @@ namespace NetEscapades.EnumGenerators //------------------------------------------------------------------------------ #nullable enable -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 -using System; -#endif namespace MyTestNameSpace { @@ -197,7 +194,7 @@ namespace MyTestNameSpace /// /// The name to check if it's defined /// true if a member with the name exists in the enumeration, false otherwise - public static bool IsDefined(in ReadOnlySpan name) => IsDefined(name, allowMatchingMetadataAttribute: false); + public static bool IsDefined(in global::System.ReadOnlySpan name) => IsDefined(name, allowMatchingMetadataAttribute: false); /// /// Returns a boolean telling whether an enum with the given name exists in the enumeration, @@ -209,13 +206,13 @@ namespace MyTestNameSpace /// If true, considers the value of metadata attributes,otherwise ignores them /// true if a member with the name exists in the enumeration, or a member is decorated /// with a [Display] attribute with the name, false otherwise - public static bool IsDefined(in ReadOnlySpan name, bool allowMatchingMetadataAttribute) + public static bool IsDefined(in global::System.ReadOnlySpan name, bool allowMatchingMetadataAttribute) { return name switch { - ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.First).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.Second).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.Third).AsSpan(), global::System.StringComparison.Ordinal) => true, + 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, _ => false, }; } @@ -415,7 +412,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name) + in global::System.ReadOnlySpan name) => TryParse(name, out var value, false, false) ? value : ThrowValueNotFound(name.ToString()); /// @@ -430,7 +427,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, bool ignoreCase) => TryParse(name, out var value, ignoreCase, false) ? value : ThrowValueNotFound(name.ToString()); @@ -448,7 +445,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, bool ignoreCase, bool allowMatchingMetadataAttribute) => TryParse(name, out var value, ignoreCase, allowMatchingMetadataAttribute) ? value : ThrowValueNotFound(name.ToString()); @@ -469,7 +466,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyTestNameSpace.MyEnum value) => TryParse(name, out value, false, false); @@ -490,7 +487,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyTestNameSpace.MyEnum value, bool ignoreCase) => TryParse(name, out value, ignoreCase, false); @@ -514,7 +511,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyTestNameSpace.MyEnum result, bool ignoreCase, bool allowMatchingMetadataAttribute) @@ -526,22 +523,22 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyTestNameSpace.MyEnum result, bool allowMatchingMetadataAttribute) { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.First).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.First), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyTestNameSpace.MyEnum.First; return true; - case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.Second).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Second), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyTestNameSpace.MyEnum.Second; return true; - case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.Third).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Third), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyTestNameSpace.MyEnum.Third; return true; - case ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): result = (global::MyTestNameSpace.MyEnum)numericResult; return true; default: @@ -554,22 +551,22 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyTestNameSpace.MyEnum result, bool allowMatchingMetadataAttribute) { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.First).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.First), global::System.StringComparison.Ordinal): result = global::MyTestNameSpace.MyEnum.First; return true; - case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.Second).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Second), global::System.StringComparison.Ordinal): result = global::MyTestNameSpace.MyEnum.Second; return true; - case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.Third).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Third), global::System.StringComparison.Ordinal): result = global::MyTestNameSpace.MyEnum.Third; return true; - case ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): result = (global::MyTestNameSpace.MyEnum)numericResult; return true; default: @@ -627,9 +624,6 @@ namespace MyTestNameSpace //------------------------------------------------------------------------------ #nullable enable -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 -using System; -#endif namespace MyTestNameSpace { @@ -738,7 +732,7 @@ namespace MyTestNameSpace /// /// The name to check if it's defined /// true if a member with the name exists in the enumeration, false otherwise - public static bool IsDefined(in ReadOnlySpan name) => IsDefined(name, allowMatchingMetadataAttribute: false); + public static bool IsDefined(in global::System.ReadOnlySpan name) => IsDefined(name, allowMatchingMetadataAttribute: false); /// /// Returns a boolean telling whether an enum with the given name exists in the enumeration, @@ -750,13 +744,13 @@ namespace MyTestNameSpace /// If true, considers the value of metadata attributes,otherwise ignores them /// true if a member with the name exists in the enumeration, or a member is decorated /// with a [Display] attribute with the name, false otherwise - public static bool IsDefined(in ReadOnlySpan name, bool allowMatchingMetadataAttribute) + public static bool IsDefined(in global::System.ReadOnlySpan name, bool allowMatchingMetadataAttribute) { return name switch { - ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.AnotherEnum.First).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.AnotherEnum.Second).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.AnotherEnum.Third).AsSpan(), global::System.StringComparison.Ordinal) => true, + 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, _ => false, }; } @@ -956,7 +950,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name) + in global::System.ReadOnlySpan name) => TryParse(name, out var value, false, false) ? value : ThrowValueNotFound(name.ToString()); /// @@ -971,7 +965,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, bool ignoreCase) => TryParse(name, out var value, ignoreCase, false) ? value : ThrowValueNotFound(name.ToString()); @@ -989,7 +983,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, bool ignoreCase, bool allowMatchingMetadataAttribute) => TryParse(name, out var value, ignoreCase, allowMatchingMetadataAttribute) ? value : ThrowValueNotFound(name.ToString()); @@ -1010,7 +1004,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyTestNameSpace.AnotherEnum value) => TryParse(name, out value, false, false); @@ -1031,7 +1025,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyTestNameSpace.AnotherEnum value, bool ignoreCase) => TryParse(name, out value, ignoreCase, false); @@ -1055,7 +1049,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyTestNameSpace.AnotherEnum result, bool ignoreCase, bool allowMatchingMetadataAttribute) @@ -1067,22 +1061,22 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyTestNameSpace.AnotherEnum result, bool allowMatchingMetadataAttribute) { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.AnotherEnum.First).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.AnotherEnum.First), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyTestNameSpace.AnotherEnum.First; return true; - case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.AnotherEnum.Second).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.AnotherEnum.Second), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyTestNameSpace.AnotherEnum.Second; return true; - case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.AnotherEnum.Third).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.AnotherEnum.Third), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyTestNameSpace.AnotherEnum.Third; return true; - case ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): result = (global::MyTestNameSpace.AnotherEnum)numericResult; return true; default: @@ -1095,22 +1089,22 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyTestNameSpace.AnotherEnum result, bool allowMatchingMetadataAttribute) { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.AnotherEnum.First).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.AnotherEnum.First), global::System.StringComparison.Ordinal): result = global::MyTestNameSpace.AnotherEnum.First; return true; - case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.AnotherEnum.Second).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.AnotherEnum.Second), global::System.StringComparison.Ordinal): result = global::MyTestNameSpace.AnotherEnum.Second; return true; - case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.AnotherEnum.Third).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.AnotherEnum.Third), global::System.StringComparison.Ordinal): result = global::MyTestNameSpace.AnotherEnum.Third; return true; - case ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): result = (global::MyTestNameSpace.AnotherEnum)numericResult; return true; default: diff --git a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.DoesNotInterceptExternalEnumMarkedAsNotInterceptable.verified.txt b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.DoesNotInterceptExternalEnumMarkedAsNotInterceptable.verified.txt index ac00d55..5644038 100644 --- a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.DoesNotInterceptExternalEnumMarkedAsNotInterceptable.verified.txt +++ b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.DoesNotInterceptExternalEnumMarkedAsNotInterceptable.verified.txt @@ -98,9 +98,6 @@ namespace NetEscapades.EnumGenerators //------------------------------------------------------------------------------ #nullable enable -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 -using System; -#endif namespace System { @@ -206,7 +203,7 @@ namespace System /// /// The name to check if it's defined /// true if a member with the name exists in the enumeration, false otherwise - public static bool IsDefined(in ReadOnlySpan name) => IsDefined(name, allowMatchingMetadataAttribute: false); + public static bool IsDefined(in global::System.ReadOnlySpan name) => IsDefined(name, allowMatchingMetadataAttribute: false); /// /// Returns a boolean telling whether an enum with the given name exists in the enumeration, @@ -218,16 +215,16 @@ namespace System /// If true, considers the value of metadata attributes,otherwise ignores them /// true if a member with the name exists in the enumeration, or a member is decorated /// with a [Display] attribute with the name, false otherwise - public static bool IsDefined(in ReadOnlySpan name, bool allowMatchingMetadataAttribute) + public static bool IsDefined(in global::System.ReadOnlySpan name, bool allowMatchingMetadataAttribute) { return name switch { - ReadOnlySpan current when current.Equals(nameof(global::System.StringComparison.CurrentCulture).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(global::System.StringComparison.CurrentCultureIgnoreCase).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(global::System.StringComparison.InvariantCulture).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(global::System.StringComparison.InvariantCultureIgnoreCase).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(global::System.StringComparison.Ordinal).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(global::System.StringComparison.OrdinalIgnoreCase).AsSpan(), global::System.StringComparison.Ordinal) => true, + 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, _ => false, }; } @@ -445,7 +442,7 @@ namespace System #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name) + in global::System.ReadOnlySpan name) => TryParse(name, out var value, false, false) ? value : ThrowValueNotFound(name.ToString()); /// @@ -460,7 +457,7 @@ namespace System #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, bool ignoreCase) => TryParse(name, out var value, ignoreCase, false) ? value : ThrowValueNotFound(name.ToString()); @@ -478,7 +475,7 @@ namespace System #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, bool ignoreCase, bool allowMatchingMetadataAttribute) => TryParse(name, out var value, ignoreCase, allowMatchingMetadataAttribute) ? value : ThrowValueNotFound(name.ToString()); @@ -499,7 +496,7 @@ namespace System #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::System.StringComparison value) => TryParse(name, out value, false, false); @@ -520,7 +517,7 @@ namespace System #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::System.StringComparison value, bool ignoreCase) => TryParse(name, out value, ignoreCase, false); @@ -544,7 +541,7 @@ namespace System #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::System.StringComparison result, bool ignoreCase, bool allowMatchingMetadataAttribute) @@ -556,31 +553,31 @@ namespace System #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::System.StringComparison result, bool allowMatchingMetadataAttribute) { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(global::System.StringComparison.CurrentCulture).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.CurrentCulture), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.StringComparison.CurrentCulture; return true; - case ReadOnlySpan current when current.Equals(nameof(global::System.StringComparison.CurrentCultureIgnoreCase).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.CurrentCultureIgnoreCase), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.StringComparison.CurrentCultureIgnoreCase; return true; - case ReadOnlySpan current when current.Equals(nameof(global::System.StringComparison.InvariantCulture).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.InvariantCulture), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.StringComparison.InvariantCulture; return true; - case ReadOnlySpan current when current.Equals(nameof(global::System.StringComparison.InvariantCultureIgnoreCase).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.InvariantCultureIgnoreCase), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.StringComparison.InvariantCultureIgnoreCase; return true; - case ReadOnlySpan current when current.Equals(nameof(global::System.StringComparison.Ordinal).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.Ordinal), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.StringComparison.Ordinal; return true; - case ReadOnlySpan current when current.Equals(nameof(global::System.StringComparison.OrdinalIgnoreCase).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.OrdinalIgnoreCase), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.StringComparison.OrdinalIgnoreCase; return true; - case ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): result = (global::System.StringComparison)numericResult; return true; default: @@ -593,31 +590,31 @@ namespace System #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::System.StringComparison result, bool allowMatchingMetadataAttribute) { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(global::System.StringComparison.CurrentCulture).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.CurrentCulture), global::System.StringComparison.Ordinal): result = global::System.StringComparison.CurrentCulture; return true; - case ReadOnlySpan current when current.Equals(nameof(global::System.StringComparison.CurrentCultureIgnoreCase).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.CurrentCultureIgnoreCase), global::System.StringComparison.Ordinal): result = global::System.StringComparison.CurrentCultureIgnoreCase; return true; - case ReadOnlySpan current when current.Equals(nameof(global::System.StringComparison.InvariantCulture).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.InvariantCulture), global::System.StringComparison.Ordinal): result = global::System.StringComparison.InvariantCulture; return true; - case ReadOnlySpan current when current.Equals(nameof(global::System.StringComparison.InvariantCultureIgnoreCase).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.InvariantCultureIgnoreCase), global::System.StringComparison.Ordinal): result = global::System.StringComparison.InvariantCultureIgnoreCase; return true; - case ReadOnlySpan current when current.Equals(nameof(global::System.StringComparison.Ordinal).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.Ordinal), global::System.StringComparison.Ordinal): result = global::System.StringComparison.Ordinal; return true; - case ReadOnlySpan current when current.Equals(nameof(global::System.StringComparison.OrdinalIgnoreCase).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.StringComparison.OrdinalIgnoreCase), global::System.StringComparison.Ordinal): result = global::System.StringComparison.OrdinalIgnoreCase; return true; - case ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): result = (global::System.StringComparison)numericResult; return true; default: @@ -681,9 +678,6 @@ namespace System //------------------------------------------------------------------------------ #nullable enable -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 -using System; -#endif namespace System { @@ -780,7 +774,7 @@ namespace System /// /// The name to check if it's defined /// true if a member with the name exists in the enumeration, false otherwise - public static bool IsDefined(in ReadOnlySpan name) => IsDefined(name, allowMatchingMetadataAttribute: false); + public static bool IsDefined(in global::System.ReadOnlySpan name) => IsDefined(name, allowMatchingMetadataAttribute: false); /// /// Returns a boolean telling whether an enum with the given name exists in the enumeration, @@ -792,13 +786,13 @@ namespace System /// If true, considers the value of metadata attributes,otherwise ignores them /// true if a member with the name exists in the enumeration, or a member is decorated /// with a [Display] attribute with the name, false otherwise - public static bool IsDefined(in ReadOnlySpan name, bool allowMatchingMetadataAttribute) + public static bool IsDefined(in global::System.ReadOnlySpan name, bool allowMatchingMetadataAttribute) { return name switch { - ReadOnlySpan current when current.Equals(nameof(global::System.DateTimeKind.Unspecified).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(global::System.DateTimeKind.Utc).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(global::System.DateTimeKind.Local).AsSpan(), global::System.StringComparison.Ordinal) => true, + 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, _ => false, }; } @@ -998,7 +992,7 @@ namespace System #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name) + in global::System.ReadOnlySpan name) => TryParse(name, out var value, false, false) ? value : ThrowValueNotFound(name.ToString()); /// @@ -1013,7 +1007,7 @@ namespace System #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, bool ignoreCase) => TryParse(name, out var value, ignoreCase, false) ? value : ThrowValueNotFound(name.ToString()); @@ -1031,7 +1025,7 @@ namespace System #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, bool ignoreCase, bool allowMatchingMetadataAttribute) => TryParse(name, out var value, ignoreCase, allowMatchingMetadataAttribute) ? value : ThrowValueNotFound(name.ToString()); @@ -1052,7 +1046,7 @@ namespace System #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::System.DateTimeKind value) => TryParse(name, out value, false, false); @@ -1073,7 +1067,7 @@ namespace System #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::System.DateTimeKind value, bool ignoreCase) => TryParse(name, out value, ignoreCase, false); @@ -1097,7 +1091,7 @@ namespace System #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::System.DateTimeKind result, bool ignoreCase, bool allowMatchingMetadataAttribute) @@ -1109,22 +1103,22 @@ namespace System #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::System.DateTimeKind result, bool allowMatchingMetadataAttribute) { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(global::System.DateTimeKind.Unspecified).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.DateTimeKind.Unspecified), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.DateTimeKind.Unspecified; return true; - case ReadOnlySpan current when current.Equals(nameof(global::System.DateTimeKind.Utc).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.DateTimeKind.Utc), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.DateTimeKind.Utc; return true; - case ReadOnlySpan current when current.Equals(nameof(global::System.DateTimeKind.Local).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.DateTimeKind.Local), global::System.StringComparison.OrdinalIgnoreCase): result = global::System.DateTimeKind.Local; return true; - case ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): result = (global::System.DateTimeKind)numericResult; return true; default: @@ -1137,22 +1131,22 @@ namespace System #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::System.DateTimeKind result, bool allowMatchingMetadataAttribute) { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(global::System.DateTimeKind.Unspecified).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.DateTimeKind.Unspecified), global::System.StringComparison.Ordinal): result = global::System.DateTimeKind.Unspecified; return true; - case ReadOnlySpan current when current.Equals(nameof(global::System.DateTimeKind.Utc).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.DateTimeKind.Utc), global::System.StringComparison.Ordinal): result = global::System.DateTimeKind.Utc; return true; - case ReadOnlySpan current when current.Equals(nameof(global::System.DateTimeKind.Local).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::System.DateTimeKind.Local), global::System.StringComparison.Ordinal): result = global::System.DateTimeKind.Local; return true; - case ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): result = (global::System.DateTimeKind)numericResult; return true; default: diff --git a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.DoesNotInterceptToStringWhenDisabled.verified.txt b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.DoesNotInterceptToStringWhenDisabled.verified.txt index 202cd22..d458497 100644 --- a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.DoesNotInterceptToStringWhenDisabled.verified.txt +++ b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.DoesNotInterceptToStringWhenDisabled.verified.txt @@ -98,9 +98,6 @@ namespace NetEscapades.EnumGenerators //------------------------------------------------------------------------------ #nullable enable -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 -using System; -#endif namespace MyTestNameSpace { @@ -194,7 +191,7 @@ namespace MyTestNameSpace /// /// The name to check if it's defined /// true if a member with the name exists in the enumeration, false otherwise - public static bool IsDefined(in ReadOnlySpan name) => IsDefined(name, allowMatchingMetadataAttribute: false); + public static bool IsDefined(in global::System.ReadOnlySpan name) => IsDefined(name, allowMatchingMetadataAttribute: false); /// /// Returns a boolean telling whether an enum with the given name exists in the enumeration, @@ -206,12 +203,12 @@ namespace MyTestNameSpace /// If true, considers the value of metadata attributes,otherwise ignores them /// true if a member with the name exists in the enumeration, or a member is decorated /// with a [Display] attribute with the name, false otherwise - public static bool IsDefined(in ReadOnlySpan name, bool allowMatchingMetadataAttribute) + public static bool IsDefined(in global::System.ReadOnlySpan name, bool allowMatchingMetadataAttribute) { return name switch { - ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.First).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.Second).AsSpan(), global::System.StringComparison.Ordinal) => true, + 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, _ => false, }; } @@ -405,7 +402,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name) + in global::System.ReadOnlySpan name) => TryParse(name, out var value, false, false) ? value : ThrowValueNotFound(name.ToString()); /// @@ -420,7 +417,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, bool ignoreCase) => TryParse(name, out var value, ignoreCase, false) ? value : ThrowValueNotFound(name.ToString()); @@ -438,7 +435,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, bool ignoreCase, bool allowMatchingMetadataAttribute) => TryParse(name, out var value, ignoreCase, allowMatchingMetadataAttribute) ? value : ThrowValueNotFound(name.ToString()); @@ -459,7 +456,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyTestNameSpace.MyEnum value) => TryParse(name, out value, false, false); @@ -480,7 +477,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyTestNameSpace.MyEnum value, bool ignoreCase) => TryParse(name, out value, ignoreCase, false); @@ -504,7 +501,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyTestNameSpace.MyEnum result, bool ignoreCase, bool allowMatchingMetadataAttribute) @@ -516,19 +513,19 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyTestNameSpace.MyEnum result, bool allowMatchingMetadataAttribute) { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.First).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.First), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyTestNameSpace.MyEnum.First; return true; - case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.Second).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Second), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyTestNameSpace.MyEnum.Second; return true; - case ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): result = (global::MyTestNameSpace.MyEnum)numericResult; return true; default: @@ -541,19 +538,19 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyTestNameSpace.MyEnum result, bool allowMatchingMetadataAttribute) { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.First).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.First), global::System.StringComparison.Ordinal): result = global::MyTestNameSpace.MyEnum.First; return true; - case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.Second).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Second), global::System.StringComparison.Ordinal): result = global::MyTestNameSpace.MyEnum.Second; return true; - case ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): result = (global::MyTestNameSpace.MyEnum)numericResult; return true; default: diff --git a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.DoesNotInterceptToStringWhenOldCsharp.verified.txt b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.DoesNotInterceptToStringWhenOldCsharp.verified.txt index 202cd22..d458497 100644 --- a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.DoesNotInterceptToStringWhenOldCsharp.verified.txt +++ b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/InterceptorTests.DoesNotInterceptToStringWhenOldCsharp.verified.txt @@ -98,9 +98,6 @@ namespace NetEscapades.EnumGenerators //------------------------------------------------------------------------------ #nullable enable -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 -using System; -#endif namespace MyTestNameSpace { @@ -194,7 +191,7 @@ namespace MyTestNameSpace /// /// The name to check if it's defined /// true if a member with the name exists in the enumeration, false otherwise - public static bool IsDefined(in ReadOnlySpan name) => IsDefined(name, allowMatchingMetadataAttribute: false); + public static bool IsDefined(in global::System.ReadOnlySpan name) => IsDefined(name, allowMatchingMetadataAttribute: false); /// /// Returns a boolean telling whether an enum with the given name exists in the enumeration, @@ -206,12 +203,12 @@ namespace MyTestNameSpace /// If true, considers the value of metadata attributes,otherwise ignores them /// true if a member with the name exists in the enumeration, or a member is decorated /// with a [Display] attribute with the name, false otherwise - public static bool IsDefined(in ReadOnlySpan name, bool allowMatchingMetadataAttribute) + public static bool IsDefined(in global::System.ReadOnlySpan name, bool allowMatchingMetadataAttribute) { return name switch { - ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.First).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.Second).AsSpan(), global::System.StringComparison.Ordinal) => true, + 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, _ => false, }; } @@ -405,7 +402,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name) + in global::System.ReadOnlySpan name) => TryParse(name, out var value, false, false) ? value : ThrowValueNotFound(name.ToString()); /// @@ -420,7 +417,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, bool ignoreCase) => TryParse(name, out var value, ignoreCase, false) ? value : ThrowValueNotFound(name.ToString()); @@ -438,7 +435,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, bool ignoreCase, bool allowMatchingMetadataAttribute) => TryParse(name, out var value, ignoreCase, allowMatchingMetadataAttribute) ? value : ThrowValueNotFound(name.ToString()); @@ -459,7 +456,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyTestNameSpace.MyEnum value) => TryParse(name, out value, false, false); @@ -480,7 +477,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyTestNameSpace.MyEnum value, bool ignoreCase) => TryParse(name, out value, ignoreCase, false); @@ -504,7 +501,7 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyTestNameSpace.MyEnum result, bool ignoreCase, bool allowMatchingMetadataAttribute) @@ -516,19 +513,19 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyTestNameSpace.MyEnum result, bool allowMatchingMetadataAttribute) { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.First).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.First), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyTestNameSpace.MyEnum.First; return true; - case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.Second).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Second), global::System.StringComparison.OrdinalIgnoreCase): result = global::MyTestNameSpace.MyEnum.Second; return true; - case ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): result = (global::MyTestNameSpace.MyEnum)numericResult; return true; default: @@ -541,19 +538,19 @@ namespace MyTestNameSpace #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::MyTestNameSpace.MyEnum result, bool allowMatchingMetadataAttribute) { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.First).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.First), global::System.StringComparison.Ordinal): result = global::MyTestNameSpace.MyEnum.First; return true; - case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.Second).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::MyTestNameSpace.MyEnum.Second), global::System.StringComparison.Ordinal): result = global::MyTestNameSpace.MyEnum.Second; return true; - case ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): result = (global::MyTestNameSpace.MyEnum)numericResult; return true; default: diff --git a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesEnumCorrectly.verified.txt b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesEnumCorrectly.verified.txt index e7b9c8b..a2c12ac 100644 --- a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesEnumCorrectly.verified.txt +++ b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesEnumCorrectly.verified.txt @@ -8,9 +8,6 @@ //------------------------------------------------------------------------------ #nullable enable -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 -using System; -#endif namespace Something.Blah { @@ -104,7 +101,7 @@ namespace Something.Blah /// /// The name to check if it's defined /// true if a member with the name exists in the enumeration, false otherwise - public static bool IsDefined(in ReadOnlySpan name) => IsDefined(name, allowMatchingMetadataAttribute: false); + public static bool IsDefined(in global::System.ReadOnlySpan name) => IsDefined(name, allowMatchingMetadataAttribute: false); /// /// Returns a boolean telling whether an enum with the given name exists in the enumeration, @@ -116,12 +113,12 @@ namespace Something.Blah /// If true, considers the value of metadata attributes,otherwise ignores them /// true if a member with the name exists in the enumeration, or a member is decorated /// with a [Display] attribute with the name, false otherwise - public static bool IsDefined(in ReadOnlySpan name, bool allowMatchingMetadataAttribute) + public static bool IsDefined(in global::System.ReadOnlySpan name, bool allowMatchingMetadataAttribute) { return name switch { - ReadOnlySpan current when current.Equals(nameof(global::Something.Blah.ShortName.First).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(global::Something.Blah.ShortName.Second).AsSpan(), global::System.StringComparison.Ordinal) => true, + 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, _ => false, }; } @@ -315,7 +312,7 @@ namespace Something.Blah #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name) + in global::System.ReadOnlySpan name) => TryParse(name, out var value, false, false) ? value : ThrowValueNotFound(name.ToString()); /// @@ -330,7 +327,7 @@ namespace Something.Blah #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, bool ignoreCase) => TryParse(name, out var value, ignoreCase, false) ? value : ThrowValueNotFound(name.ToString()); @@ -348,7 +345,7 @@ namespace Something.Blah #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, bool ignoreCase, bool allowMatchingMetadataAttribute) => TryParse(name, out var value, ignoreCase, allowMatchingMetadataAttribute) ? value : ThrowValueNotFound(name.ToString()); @@ -369,7 +366,7 @@ namespace Something.Blah #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::Something.Blah.ShortName value) => TryParse(name, out value, false, false); @@ -390,7 +387,7 @@ namespace Something.Blah #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::Something.Blah.ShortName value, bool ignoreCase) => TryParse(name, out value, ignoreCase, false); @@ -414,7 +411,7 @@ namespace Something.Blah #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::Something.Blah.ShortName result, bool ignoreCase, bool allowMatchingMetadataAttribute) @@ -426,19 +423,19 @@ namespace Something.Blah #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::Something.Blah.ShortName result, bool allowMatchingMetadataAttribute) { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(global::Something.Blah.ShortName.First).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::Something.Blah.ShortName.First), global::System.StringComparison.OrdinalIgnoreCase): result = global::Something.Blah.ShortName.First; return true; - case ReadOnlySpan current when current.Equals(nameof(global::Something.Blah.ShortName.Second).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::Something.Blah.ShortName.Second), global::System.StringComparison.OrdinalIgnoreCase): result = global::Something.Blah.ShortName.Second; return true; - case ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): result = (global::Something.Blah.ShortName)numericResult; return true; default: @@ -451,19 +448,19 @@ namespace Something.Blah #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::Something.Blah.ShortName result, bool allowMatchingMetadataAttribute) { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(global::Something.Blah.ShortName.First).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::Something.Blah.ShortName.First), global::System.StringComparison.Ordinal): result = global::Something.Blah.ShortName.First; return true; - case ReadOnlySpan current when current.Equals(nameof(global::Something.Blah.ShortName.Second).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::Something.Blah.ShortName.Second), global::System.StringComparison.Ordinal): result = global::Something.Blah.ShortName.Second; return true; - case ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): result = (global::Something.Blah.ShortName)numericResult; return true; default: diff --git a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFlagsEnumCorrectly.verified.txt b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFlagsEnumCorrectly.verified.txt index c4b085d..9c0ee26 100644 --- a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFlagsEnumCorrectly.verified.txt +++ b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFlagsEnumCorrectly.verified.txt @@ -8,9 +8,6 @@ //------------------------------------------------------------------------------ #nullable enable -#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 -using System; -#endif namespace Something.Blah { @@ -116,7 +113,7 @@ namespace Something.Blah /// /// The name to check if it's defined /// true if a member with the name exists in the enumeration, false otherwise - public static bool IsDefined(in ReadOnlySpan name) => IsDefined(name, allowMatchingMetadataAttribute: false); + public static bool IsDefined(in global::System.ReadOnlySpan name) => IsDefined(name, allowMatchingMetadataAttribute: false); /// /// Returns a boolean telling whether an enum with the given name exists in the enumeration, @@ -128,12 +125,12 @@ namespace Something.Blah /// If true, considers the value of metadata attributes,otherwise ignores them /// true if a member with the name exists in the enumeration, or a member is decorated /// with a [Display] attribute with the name, false otherwise - public static bool IsDefined(in ReadOnlySpan name, bool allowMatchingMetadataAttribute) + public static bool IsDefined(in global::System.ReadOnlySpan name, bool allowMatchingMetadataAttribute) { return name switch { - ReadOnlySpan current when current.Equals(nameof(global::Something.Blah.ShortName.First).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(global::Something.Blah.ShortName.Second).AsSpan(), global::System.StringComparison.Ordinal) => true, + 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, _ => false, }; } @@ -327,7 +324,7 @@ namespace Something.Blah #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name) + in global::System.ReadOnlySpan name) => TryParse(name, out var value, false, false) ? value : ThrowValueNotFound(name.ToString()); /// @@ -342,7 +339,7 @@ namespace Something.Blah #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, bool ignoreCase) => TryParse(name, out var value, ignoreCase, false) ? value : ThrowValueNotFound(name.ToString()); @@ -360,7 +357,7 @@ namespace Something.Blah #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, bool ignoreCase, bool allowMatchingMetadataAttribute) => TryParse(name, out var value, ignoreCase, allowMatchingMetadataAttribute) ? value : ThrowValueNotFound(name.ToString()); @@ -381,7 +378,7 @@ namespace Something.Blah #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::Something.Blah.ShortName value) => TryParse(name, out value, false, false); @@ -402,7 +399,7 @@ namespace Something.Blah #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::Something.Blah.ShortName value, bool ignoreCase) => TryParse(name, out value, ignoreCase, false); @@ -426,7 +423,7 @@ namespace Something.Blah #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::Something.Blah.ShortName result, bool ignoreCase, bool allowMatchingMetadataAttribute) @@ -438,19 +435,19 @@ namespace Something.Blah #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::Something.Blah.ShortName result, bool allowMatchingMetadataAttribute) { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(global::Something.Blah.ShortName.First).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::Something.Blah.ShortName.First), global::System.StringComparison.OrdinalIgnoreCase): result = global::Something.Blah.ShortName.First; return true; - case ReadOnlySpan current when current.Equals(nameof(global::Something.Blah.ShortName.Second).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::Something.Blah.ShortName.Second), global::System.StringComparison.OrdinalIgnoreCase): result = global::Something.Blah.ShortName.Second; return true; - case ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): result = (global::Something.Blah.ShortName)numericResult; return true; default: @@ -463,19 +460,19 @@ namespace Something.Blah #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif - in ReadOnlySpan name, + in global::System.ReadOnlySpan name, out global::Something.Blah.ShortName result, bool allowMatchingMetadataAttribute) { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(global::Something.Blah.ShortName.First).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::Something.Blah.ShortName.First), global::System.StringComparison.Ordinal): result = global::Something.Blah.ShortName.First; return true; - case ReadOnlySpan current when current.Equals(nameof(global::Something.Blah.ShortName.Second).AsSpan(), global::System.StringComparison.Ordinal): + case global::System.ReadOnlySpan current when global::System.MemoryExtensions.Equals(current, nameof(global::Something.Blah.ShortName.Second), global::System.StringComparison.Ordinal): result = global::Something.Blah.ShortName.Second; return true; - case ReadOnlySpan current when int.TryParse(name, out var numericResult): + case global::System.ReadOnlySpan current when int.TryParse(name, out var numericResult): result = (global::Something.Blah.ShortName)numericResult; return true; default: