From 49449050b520f2daa8551c2774222d01f719c209 Mon Sep 17 00:00:00 2001 From: Andrew Lock Date: Sun, 4 Jun 2023 21:54:50 +0100 Subject: [PATCH] Fix Error CS0426 : The type name 'TestEnum' does not exist in the type 'Foo' Occurs when there's a class that matches the namespace name Fixes #61 --- .../SourceGenerationHelper.cs | 116 +++--- .../EnumInFooExtensionsTests.cs | 83 +++++ .../Enums.cs | 20 ++ .../EnumGeneratorTests.cs | 23 ++ ...ExtensionsForFlagsEnum_Params.verified.txt | 160 ++++----- ...numExtensionsInChildNamespace.verified.txt | 130 +++---- ...umExtensionsInGlobalNamespace.verified.txt | 130 +++---- ...teEnumExtensionsInNestedClass.verified.txt | 130 +++---- ...eEnumExtensionsWithCustomName.verified.txt | 130 +++---- ...EnumExtensionsWithCustomNames.verified.txt | 202 +++++------ ...ExtensionsWithCustomNamespace.verified.txt | 130 +++---- ...onsWithCustomNamespaceAndName.verified.txt | 130 +++---- ...ExtensionsWithSameDisplayName.verified.txt | 194 +++++----- ...mespaceAndClassNameAreTheSame.verified.txt | 336 ++++++++++++++++++ ...tTests.GeneratesEnumCorrectly.verified.txt | 130 +++---- ...s.GeneratesFlagsEnumCorrectly.verified.txt | 132 +++---- 16 files changed, 1320 insertions(+), 856 deletions(-) create mode 100644 tests/NetEscapades.EnumGenerators.IntegrationTests/EnumInFooExtensionsTests.cs create mode 100644 tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanHandleNamespaceAndClassNameAreTheSame.verified.txt diff --git a/src/NetEscapades.EnumGenerators/SourceGenerationHelper.cs b/src/NetEscapades.EnumGenerators/SourceGenerationHelper.cs index f741368..93beb76 100644 --- a/src/NetEscapades.EnumGenerators/SourceGenerationHelper.cs +++ b/src/NetEscapades.EnumGenerators/SourceGenerationHelper.cs @@ -66,9 +66,11 @@ namespace ").Append(enumToGenerate.Namespace).Append(@" {"); } + var fullyQualifiedName = $"global::{enumToGenerate.FullyQualifiedName}"; + sb.Append(@" /// - /// Extension methods for + /// Extension methods for /// ").Append(enumToGenerate.IsPublic ? "public" : "internal").Append(@" static partial class ").Append(enumToGenerate.Name).Append(@" { @@ -79,25 +81,25 @@ namespace ").Append(enumToGenerate.Namespace).Append(@" public const int Length = ").Append(enumToGenerate.Names.Count).Append(";").Append(@" /// - /// Returns the string representation of the value. + /// Returns the string representation of the value. /// If the attribute is decorated with a [Display] attribute, then /// uses the provided value. Otherwise uses the name of the member, equivalent to /// calling ToString() on . /// /// The value to retrieve the string value for /// The string representation of the value - public static string ToStringFast(this ").Append(enumToGenerate.FullyQualifiedName).Append(@" value) + public static string ToStringFast(this ").Append(fullyQualifiedName).Append(@" value) => value switch {"); foreach (var member in enumToGenerate.Names) { sb.Append(@" - ").Append(enumToGenerate.FullyQualifiedName).Append('.').Append(member.Key) + ").Append(fullyQualifiedName).Append('.').Append(member.Key) .Append(" => "); if (member.Value.DisplayName is null) { - sb.Append("nameof(").Append(enumToGenerate.FullyQualifiedName).Append('.').Append(member.Key).Append("),"); + sb.Append("nameof(").Append(fullyQualifiedName).Append('.').Append(member.Key).Append("),"); } else { @@ -122,7 +124,7 @@ public static string ToStringFast(this ").Append(enumToGenerate.FullyQualifiedNa /// true if the fields set in the flag are also set in the current instance; otherwise false. /// If the underlying value of is zero, the method returns true. /// This is consistent with the behaviour of - public static bool HasFlagFast(this ").Append(enumToGenerate.FullyQualifiedName).Append(@" value, ").Append(enumToGenerate.FullyQualifiedName).Append(@" flag) + public static bool HasFlagFast(this ").Append(fullyQualifiedName).Append(@" value, ").Append(fullyQualifiedName).Append(@" flag) => flag == 0 ? true : (value & flag) == flag;"); } @@ -133,13 +135,13 @@ public static bool HasFlagFast(this ").Append(enumToGenerate.FullyQualifiedName) /// /// The value to check if it's defined /// true if the value exists in the enumeration, false otherwise - public static bool IsDefined(").Append(enumToGenerate.FullyQualifiedName).Append(@" value) + public static bool IsDefined(").Append(fullyQualifiedName).Append(@" value) => value switch {"); foreach (var member in enumToGenerate.Names) { sb.Append(@" - ").Append(enumToGenerate.FullyQualifiedName).Append('.').Append(member.Key) + ").Append(fullyQualifiedName).Append('.').Append(member.Key) .Append(" => true,"); } @@ -203,7 +205,7 @@ public static bool IsDefined(string name, bool allowMatchingMetadataAttribute) foreach (var member in enumToGenerate.Names) { sb.Append(@" - nameof(").Append(enumToGenerate.FullyQualifiedName).Append('.').Append(member.Key).Append(@") => true,"); + nameof(").Append(fullyQualifiedName).Append('.').Append(member.Key).Append(@") => true,"); } sb.Append(@" @@ -269,7 +271,7 @@ public static bool IsDefined(in ReadOnlySpan name, bool allowMatchingMetad foreach (var member in enumToGenerate.Names) { sb.Append(@" - ReadOnlySpan current when current.Equals(nameof(").Append(enumToGenerate.FullyQualifiedName).Append('.').Append(member.Key) + ReadOnlySpan current when current.Equals(nameof(").Append(fullyQualifiedName).Append('.').Append(member.Key) .Append(@").AsSpan(), global::System.StringComparison.Ordinal) => true,"); } @@ -283,36 +285,36 @@ ReadOnlySpan current when current.Equals(nameof(").Append(enumToGenerate.F /// /// Converts the string representation of the name or numeric value of - /// an to the equivalent instance. + /// an to the equivalent instance. /// The return value indicates whether the conversion succeeded. /// /// The case-sensitive string representation of the enumeration name or underlying value to convert /// When this method returns, contains an object of type - /// whose + /// whose /// value is represented by if the parse operation succeeds. /// If the parse operation fails, contains the default value of the underlying type - /// of . This parameter is passed uninitialized. + /// of . This parameter is passed uninitialized. /// true if the value parameter was converted successfully; otherwise, false. public static bool TryParse( #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif string? name, - out ").Append(enumToGenerate.FullyQualifiedName).Append(@" value) + out ").Append(fullyQualifiedName).Append(@" value) => TryParse(name, out value, false, false);"); sb.Append(@" /// /// Converts the string representation of the name or numeric value of - /// an to the equivalent instance. + /// an to the equivalent instance. /// The return value indicates whether the conversion succeeded. /// /// The string representation of the enumeration name or underlying value to convert /// When this method returns, contains an object of type - /// whose + /// whose /// value is represented by if the parse operation succeeds. /// If the parse operation fails, contains the default value of the underlying type - /// of . This parameter is passed uninitialized. + /// of . This parameter is passed uninitialized. /// true to read value in case insensitive mode; false to read value in case sensitive mode. /// true if the value parameter was converted successfully; otherwise, false. public static bool TryParse( @@ -320,22 +322,22 @@ public static bool TryParse( [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif string? name, - out ").Append(enumToGenerate.FullyQualifiedName).Append(@" value, + out ").Append(fullyQualifiedName).Append(@" value, bool ignoreCase) => TryParse(name, out value, ignoreCase, false);"); sb.Append(@" /// /// Converts the string representation of the name or numeric value of - /// an to the equivalent instance. + /// an to the equivalent instance. /// The return value indicates whether the conversion succeeded. /// /// The string representation of the enumeration name or underlying value to convert /// When this method returns, contains an object of type - /// whose + /// whose /// value is represented by if the parse operation succeeds. /// If the parse operation fails, contains the default value of the underlying type - /// of . This parameter is passed uninitialized. + /// of . This parameter is passed uninitialized. /// true to read value in case insensitive mode; false to read value in case sensitive mode. /// If true, considers the value included in metadata attributes such as /// [Display] attribute when parsing, otherwise only considers the member names. @@ -345,7 +347,7 @@ public static bool TryParse( [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif string? name, - out ").Append(enumToGenerate.FullyQualifiedName).Append(@" value, + out ").Append(fullyQualifiedName).Append(@" value, bool ignoreCase, bool allowMatchingMetadataAttribute) {"); @@ -365,7 +367,7 @@ public static bool TryParse( { sb.Append(@" case string s when s.Equals(""").Append(member.Value.DisplayName).Append(@""", global::System.StringComparison.OrdinalIgnoreCase): - value = ").Append(enumToGenerate.FullyQualifiedName).Append('.').Append(member.Key).Append(@"; + value = ").Append(fullyQualifiedName).Append('.').Append(member.Key).Append(@"; return true;"); } } @@ -385,7 +387,7 @@ public static bool TryParse( { sb.Append(@" case """).Append(member.Value.DisplayName).Append(@""": - value = ").Append(enumToGenerate.FullyQualifiedName).Append('.').Append(member.Key).Append(@"; + value = ").Append(fullyQualifiedName).Append('.').Append(member.Key).Append(@"; return true;"); } } @@ -407,15 +409,15 @@ public static bool TryParse( foreach (var member in enumToGenerate.Names) { sb.Append(@" - case string s when s.Equals(nameof(").Append(enumToGenerate.FullyQualifiedName).Append('.').Append(member.Key).Append( + case string s when s.Equals(nameof(").Append(fullyQualifiedName).Append('.').Append(member.Key).Append( @"), global::System.StringComparison.OrdinalIgnoreCase): - value = ").Append(enumToGenerate.FullyQualifiedName).Append('.').Append(member.Key).Append(@"; + value = ").Append(fullyQualifiedName).Append('.').Append(member.Key).Append(@"; return true;"); } sb.Append(@" case string s when ").Append(enumToGenerate.UnderlyingType).Append(@".TryParse(name, out var val): - value = (").Append(enumToGenerate.FullyQualifiedName).Append(@")val; + value = (").Append(fullyQualifiedName).Append(@")val; return true; default: value = default; @@ -429,14 +431,14 @@ public static bool TryParse( foreach (var member in enumToGenerate.Names) { sb.Append(@" - case nameof(").Append(enumToGenerate.FullyQualifiedName).Append('.').Append(member.Key).Append(@"): - value = ").Append(enumToGenerate.FullyQualifiedName).Append('.').Append(member.Key).Append(@"; + case nameof(").Append(fullyQualifiedName).Append('.').Append(member.Key).Append(@"): + value = ").Append(fullyQualifiedName).Append('.').Append(member.Key).Append(@"; return true;"); } sb.Append(@" case string s when ").Append(enumToGenerate.UnderlyingType).Append(@".TryParse(name, out var val): - value = (").Append(enumToGenerate.FullyQualifiedName).Append(@")val; + value = (").Append(fullyQualifiedName).Append(@")val; return true; default: value = default; @@ -450,36 +452,36 @@ public static bool TryParse( #if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Converts the span representation of the name or numeric value of - /// an to the equivalent instance. + /// an to the equivalent instance. /// The return value indicates whether the conversion succeeded. /// /// The span representation of the enumeration name or underlying value to convert /// When this method returns, contains an object of type - /// whose + /// whose /// value is represented by if the parse operation succeeds. /// If the parse operation fails, contains the default value of the underlying type - /// of . This parameter is passed uninitialized. + /// of . This parameter is passed uninitialized. /// true if the value parameter was converted successfully; otherwise, false. public static bool TryParse( #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif in ReadOnlySpan name, - out ").Append(enumToGenerate.FullyQualifiedName).Append(@" value) + out ").Append(fullyQualifiedName).Append(@" value) => TryParse(name, out value, false, false);"); sb.Append(@" /// /// Converts the span representation of the name or numeric value of - /// an to the equivalent instance. + /// an to the equivalent instance. /// The return value indicates whether the conversion succeeded. /// /// The span representation of the enumeration name or underlying value to convert /// When this method returns, contains an object of type - /// whose + /// whose /// value is represented by if the parse operation succeeds. /// If the parse operation fails, contains the default value of the underlying type - /// of . This parameter is passed uninitialized. + /// of . This parameter is passed uninitialized. /// true to read value in case insensitive mode; false to read value in case sensitive mode. /// true if the value parameter was converted successfully; otherwise, false. public static bool TryParse( @@ -487,7 +489,7 @@ public static bool TryParse( [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif in ReadOnlySpan name, - out ").Append(enumToGenerate.FullyQualifiedName).Append(@" value, + out ").Append(fullyQualifiedName).Append(@" value, bool ignoreCase) => TryParse(name, out value, ignoreCase, false);"); @@ -495,15 +497,15 @@ public static bool TryParse( /// /// Converts the span representation of the name or numeric value of - /// an to the equivalent instance. + /// an to the equivalent instance. /// The return value indicates whether the conversion succeeded. /// /// The span representation of the enumeration name or underlying value to convert /// When this method returns, contains an object of type - /// whose + /// whose /// value is represented by if the parse operation succeeds. /// If the parse operation fails, contains the default value of the underlying type - /// of . This parameter is passed uninitialized. + /// of . This parameter is passed uninitialized. /// true to read value in case insensitive mode; false to read value in case sensitive mode. /// If true, considers the value included in metadata attributes such as /// [Display] attribute when parsing, otherwise only considers the member names. @@ -513,7 +515,7 @@ public static bool TryParse( [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif in ReadOnlySpan name, - out ").Append(enumToGenerate.FullyQualifiedName).Append(@" result, + out ").Append(fullyQualifiedName).Append(@" result, bool ignoreCase, bool allowMatchingMetadataAttribute) {"); @@ -534,7 +536,7 @@ public static bool TryParse( sb.Append(@" case ReadOnlySpan current when current.Equals(""").Append(member.Value.DisplayName).Append( @""".AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): - result = ").Append(enumToGenerate.FullyQualifiedName).Append('.').Append(member.Key).Append(@"; + result = ").Append(fullyQualifiedName).Append('.').Append(member.Key).Append(@"; return true;"); } } @@ -554,7 +556,7 @@ public static bool TryParse( { sb.Append(@" case ReadOnlySpan current when current.Equals(""").Append(member.Value.DisplayName).Append(@""".AsSpan(), global::System.StringComparison.Ordinal): - result = ").Append(enumToGenerate.FullyQualifiedName).Append('.').Append(member.Key).Append(@"; + result = ").Append(fullyQualifiedName).Append('.').Append(member.Key).Append(@"; return true;"); } } @@ -576,15 +578,15 @@ public static bool TryParse( foreach (var member in enumToGenerate.Names) { sb.Append(@" - case ReadOnlySpan current when current.Equals(nameof(").Append(enumToGenerate.FullyQualifiedName).Append('.').Append(member.Key).Append( + case ReadOnlySpan current when current.Equals(nameof(").Append(fullyQualifiedName).Append('.').Append(member.Key).Append( @").AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): - result = ").Append(enumToGenerate.FullyQualifiedName).Append('.').Append(member.Key).Append(@"; + result = ").Append(fullyQualifiedName).Append('.').Append(member.Key).Append(@"; return true;"); } sb.Append(@" case ReadOnlySpan current when ").Append(enumToGenerate.UnderlyingType).Append(@".TryParse(name, out var numericResult): - result = (").Append(enumToGenerate.FullyQualifiedName).Append(@")numericResult; + result = (").Append(fullyQualifiedName).Append(@")numericResult; return true; default: result = default; @@ -598,15 +600,15 @@ public static bool TryParse( foreach (var member in enumToGenerate.Names) { sb.Append(@" - case ReadOnlySpan current when current.Equals(nameof(").Append(enumToGenerate.FullyQualifiedName).Append('.').Append(member.Key).Append( + case ReadOnlySpan current when current.Equals(nameof(").Append(fullyQualifiedName).Append('.').Append(member.Key).Append( @").AsSpan(), global::System.StringComparison.Ordinal): - result = ").Append(enumToGenerate.FullyQualifiedName).Append('.').Append(member.Key).Append(@"; + result = ").Append(fullyQualifiedName).Append('.').Append(member.Key).Append(@"; return true;"); } sb.Append(@" case ReadOnlySpan current when ").Append(enumToGenerate.UnderlyingType).Append(@".TryParse(name, out var numericResult): - result = (").Append(enumToGenerate.FullyQualifiedName).Append(@")numericResult; + result = (").Append(fullyQualifiedName).Append(@")numericResult; return true; default: result = default; @@ -620,19 +622,19 @@ public static bool TryParse( /// /// Retrieves an array of the values of the members defined in - /// . + /// . /// Note that this returns a new array with every invocation, so /// should be cached if appropriate. /// - /// An array of the values defined in - public static ").Append(enumToGenerate.FullyQualifiedName).Append(@"[] GetValues() + /// An array of the values defined in + public static ").Append(fullyQualifiedName).Append(@"[] GetValues() { return new[] {"); foreach (var member in enumToGenerate.Names) { sb.Append(@" - ").Append(enumToGenerate.FullyQualifiedName).Append('.').Append(member.Key).Append(','); + ").Append(fullyQualifiedName).Append('.').Append(member.Key).Append(','); } sb.Append(@" @@ -643,11 +645,11 @@ public static bool TryParse( /// /// Retrieves an array of the names of the members defined in - /// . + /// . /// Note that this returns a new array with every invocation, so /// should be cached if appropriate. /// - /// An array of the names of the members defined in + /// An array of the names of the members defined in public static string[] GetNames() { return new[] @@ -655,7 +657,7 @@ public static string[] GetNames() foreach (var member in enumToGenerate.Names) { sb.Append(@" - nameof(").Append(enumToGenerate.FullyQualifiedName).Append('.').Append(member.Key).Append("),"); + nameof(").Append(fullyQualifiedName).Append('.').Append(member.Key).Append("),"); } sb.Append(@" diff --git a/tests/NetEscapades.EnumGenerators.IntegrationTests/EnumInFooExtensionsTests.cs b/tests/NetEscapades.EnumGenerators.IntegrationTests/EnumInFooExtensionsTests.cs new file mode 100644 index 0000000..501ec10 --- /dev/null +++ b/tests/NetEscapades.EnumGenerators.IntegrationTests/EnumInFooExtensionsTests.cs @@ -0,0 +1,83 @@ +using System; +using Foo; +using Xunit; + +namespace NetEscapades.EnumGenerators.IntegrationTests; + +public class EnumInFooExtensionsTests : ExtensionTests +{ + public static TheoryData ValidEnumValues() => new() + { + EnumInFoo.First, + EnumInFoo.Second, + (EnumInFoo)3, + }; + + public static TheoryData ValuesToParse() => new() + { + "First", + "Second", + "2nd", + "2ND", + "first", + "SECOND", + "3", + "267", + "-267", + "2147483647", + "3000000000", + "Fourth", + "Fifth", + }; + + protected override string ToStringFast(EnumInFoo value) => value.ToStringFast(); + protected override bool IsDefined(EnumInFoo value) => EnumInFooExtensions.IsDefined(value); + protected override bool IsDefined(string name, bool allowMatchingMetadataAttribute) => EnumInFooExtensions.IsDefined(name, allowMatchingMetadataAttribute: false); +#if READONLYSPAN + protected override bool IsDefined(in ReadOnlySpan name, bool allowMatchingMetadataAttribute) => EnumInFooExtensions.IsDefined(name, allowMatchingMetadataAttribute: false); +#endif + protected override bool TryParse(string name, out EnumInFoo parsed, bool ignoreCase, bool allowMatchingMetadataAttribute) + => EnumInFooExtensions.TryParse(name, out parsed, ignoreCase); +#if READONLYSPAN + protected override bool TryParse(in ReadOnlySpan name, out EnumInFoo parsed, bool ignoreCase, bool allowMatchingMetadataAttribute) + => EnumInFooExtensions.TryParse(name, out parsed, ignoreCase); +#endif + + [Theory] + [MemberData(nameof(ValidEnumValues))] + public void GeneratesToStringFast(EnumInFoo value) => GeneratesToStringFastTest(value); + + [Theory] + [MemberData(nameof(ValidEnumValues))] + public void GeneratesIsDefined(EnumInFoo value) => GeneratesIsDefinedTest(value); + + [Theory] + [MemberData(nameof(ValuesToParse))] + public void GeneratesIsDefinedUsingName(string name) => GeneratesIsDefinedTest(name, allowMatchingMetadataAttribute: false); + +#if READONLYSPAN + [Theory] + [MemberData(nameof(ValuesToParse))] + public void GeneratesIsDefinedUsingNameAsSpan(string name) => GeneratesIsDefinedTest(name.AsSpan(), allowMatchingMetadataAttribute: false); +#endif + + [Theory] + [MemberData(nameof(ValuesToParse))] + public void GeneratesTryParse(string name) => GeneratesTryParseTest(name, ignoreCase: false, allowMatchingMetadataAttribute: false); + +#if READONLYSPAN + [Theory] + [MemberData(nameof(ValuesToParse))] + public void GeneratesTryParseUsingSpan(string name) => GeneratesTryParseTest(name.AsSpan(), ignoreCase: false, allowMatchingMetadataAttribute: false); +#endif + + [Theory] + [MemberData(nameof(ValuesToParse))] + public void GeneratesTryParseIgnoreCase(string name) => GeneratesTryParseTest(name, ignoreCase: true, allowMatchingMetadataAttribute: false); + + [Fact] + public void GeneratesGetValues() => GeneratesGetValuesTest(EnumInFooExtensions.GetValues()); + + [Fact] + public void GeneratesGetNames() => base.GeneratesGetNamesTest(EnumInFooExtensions.GetNames()); +} \ No newline at end of file diff --git a/tests/NetEscapades.EnumGenerators.IntegrationTests/Enums.cs b/tests/NetEscapades.EnumGenerators.IntegrationTests/Enums.cs index 4406b19..b8856e9 100644 --- a/tests/NetEscapades.EnumGenerators.IntegrationTests/Enums.cs +++ b/tests/NetEscapades.EnumGenerators.IntegrationTests/Enums.cs @@ -15,6 +15,26 @@ public enum EnumInSystem } } +namespace Foo +{ + using NetEscapades.EnumGenerators; + + // causes Error CS0426 : The type name 'TestEnum' does not exist in the type 'Foo'. + // workaround is to use global prefix + + public class Foo + { + } + + [EnumExtensions] + public enum EnumInFoo + { + First = 0, + Second = 1, + Third = 2, + } +} + namespace NetEscapades.EnumGenerators.IntegrationTests { [EnumExtensions] diff --git a/tests/NetEscapades.EnumGenerators.Tests/EnumGeneratorTests.cs b/tests/NetEscapades.EnumGenerators.Tests/EnumGeneratorTests.cs index 143725e..cc6c03c 100644 --- a/tests/NetEscapades.EnumGenerators.Tests/EnumGeneratorTests.cs +++ b/tests/NetEscapades.EnumGenerators.Tests/EnumGeneratorTests.cs @@ -292,4 +292,27 @@ public enum MyEnum .DisableRequireUniquePrefix() .UseDirectory("Snapshots"); } + + [Fact] + public Task CanHandleNamespaceAndClassNameAreTheSame() + { + const string input = @"using NetEscapades.EnumGenerators; +using System.ComponentModel.DataAnnotations; + +namespace Foo +{ + public class Foo {} + + [EnumExtensions] + public enum TestEnum + { + Value1 + } +}"; + var (diagnostics, output) = TestHelpers.GetGeneratedOutput(input); + + Assert.Empty(diagnostics); + return Verifier.Verify(output).UseDirectory("Snapshots"); + } + } \ No newline at end of file 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 1fa8294..b2d2542 100644 --- a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsForFlagsEnum_Params.verified.txt +++ b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsForFlagsEnum_Params.verified.txt @@ -15,7 +15,7 @@ using System; namespace MyTestNameSpace { /// - /// Extension methods for + /// Extension methods for /// public static partial class MyEnumExtensions { @@ -26,19 +26,19 @@ namespace MyTestNameSpace public const int Length = 3; /// - /// Returns the string representation of the value. + /// Returns the string representation of the value. /// If the attribute is decorated with a [Display] attribute, then /// uses the provided value. Otherwise uses the name of the member, equivalent to /// calling ToString() on . /// /// The value to retrieve the string value for /// The string representation of the value - public static string ToStringFast(this MyTestNameSpace.MyEnum value) + public static string ToStringFast(this global::MyTestNameSpace.MyEnum value) => value switch { - MyTestNameSpace.MyEnum.First => nameof(MyTestNameSpace.MyEnum.First), - MyTestNameSpace.MyEnum.Second => nameof(MyTestNameSpace.MyEnum.Second), - MyTestNameSpace.MyEnum.Third => nameof(MyTestNameSpace.MyEnum.Third), + global::MyTestNameSpace.MyEnum.First => nameof(global::MyTestNameSpace.MyEnum.First), + global::MyTestNameSpace.MyEnum.Second => nameof(global::MyTestNameSpace.MyEnum.Second), + global::MyTestNameSpace.MyEnum.Third => nameof(global::MyTestNameSpace.MyEnum.Third), _ => value.ToString(), }; @@ -51,7 +51,7 @@ namespace MyTestNameSpace /// true if the fields set in the flag are also set in the current instance; otherwise false. /// If the underlying value of is zero, the method returns true. /// This is consistent with the behaviour of - public static bool HasFlagFast(this MyTestNameSpace.MyEnum value, MyTestNameSpace.MyEnum flag) + public static bool HasFlagFast(this global::MyTestNameSpace.MyEnum value, global::MyTestNameSpace.MyEnum flag) => flag == 0 ? true : (value & flag) == flag; /// @@ -59,12 +59,12 @@ namespace MyTestNameSpace /// /// The value to check if it's defined /// true if the value exists in the enumeration, false otherwise - public static bool IsDefined(MyTestNameSpace.MyEnum value) + public static bool IsDefined(global::MyTestNameSpace.MyEnum value) => value switch { - MyTestNameSpace.MyEnum.First => true, - MyTestNameSpace.MyEnum.Second => true, - MyTestNameSpace.MyEnum.Third => true, + global::MyTestNameSpace.MyEnum.First => true, + global::MyTestNameSpace.MyEnum.Second => true, + global::MyTestNameSpace.MyEnum.Third => true, _ => false, }; @@ -88,9 +88,9 @@ namespace MyTestNameSpace { return name switch { - nameof(MyTestNameSpace.MyEnum.First) => true, - nameof(MyTestNameSpace.MyEnum.Second) => true, - nameof(MyTestNameSpace.MyEnum.Third) => true, + nameof(global::MyTestNameSpace.MyEnum.First) => true, + nameof(global::MyTestNameSpace.MyEnum.Second) => true, + nameof(global::MyTestNameSpace.MyEnum.Third) => true, _ => false, }; } @@ -117,9 +117,9 @@ namespace MyTestNameSpace { return name switch { - ReadOnlySpan current when current.Equals(nameof(MyTestNameSpace.MyEnum.First).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(MyTestNameSpace.MyEnum.Second).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(MyTestNameSpace.MyEnum.Third).AsSpan(), global::System.StringComparison.Ordinal) => true, + 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, _ => false, }; } @@ -127,35 +127,35 @@ namespace MyTestNameSpace /// /// Converts the string representation of the name or numeric value of - /// an to the equivalent instance. + /// an to the equivalent instance. /// The return value indicates whether the conversion succeeded. /// /// The case-sensitive string representation of the enumeration name or underlying value to convert /// When this method returns, contains an object of type - /// whose + /// whose /// value is represented by if the parse operation succeeds. /// If the parse operation fails, contains the default value of the underlying type - /// of . This parameter is passed uninitialized. + /// of . This parameter is passed uninitialized. /// true if the value parameter was converted successfully; otherwise, false. public static bool TryParse( #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif string? name, - out MyTestNameSpace.MyEnum value) + out global::MyTestNameSpace.MyEnum value) => TryParse(name, out value, false, false); /// /// Converts the string representation of the name or numeric value of - /// an to the equivalent instance. + /// an to the equivalent instance. /// The return value indicates whether the conversion succeeded. /// /// The string representation of the enumeration name or underlying value to convert /// When this method returns, contains an object of type - /// whose + /// whose /// value is represented by if the parse operation succeeds. /// If the parse operation fails, contains the default value of the underlying type - /// of . This parameter is passed uninitialized. + /// of . This parameter is passed uninitialized. /// true to read value in case insensitive mode; false to read value in case sensitive mode. /// true if the value parameter was converted successfully; otherwise, false. public static bool TryParse( @@ -163,21 +163,21 @@ namespace MyTestNameSpace [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif string? name, - out MyTestNameSpace.MyEnum value, + out global::MyTestNameSpace.MyEnum value, bool ignoreCase) => TryParse(name, out value, ignoreCase, false); /// /// Converts the string representation of the name or numeric value of - /// an to the equivalent instance. + /// an to the equivalent instance. /// The return value indicates whether the conversion succeeded. /// /// The string representation of the enumeration name or underlying value to convert /// When this method returns, contains an object of type - /// whose + /// whose /// value is represented by if the parse operation succeeds. /// If the parse operation fails, contains the default value of the underlying type - /// of . This parameter is passed uninitialized. + /// of . This parameter is passed uninitialized. /// true to read value in case insensitive mode; false to read value in case sensitive mode. /// If true, considers the value included in metadata attributes such as /// [Display] attribute when parsing, otherwise only considers the member names. @@ -187,7 +187,7 @@ namespace MyTestNameSpace [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif string? name, - out MyTestNameSpace.MyEnum value, + out global::MyTestNameSpace.MyEnum value, bool ignoreCase, bool allowMatchingMetadataAttribute) { @@ -195,17 +195,17 @@ namespace MyTestNameSpace { switch (name) { - case string s when s.Equals(nameof(MyTestNameSpace.MyEnum.First), global::System.StringComparison.OrdinalIgnoreCase): - value = MyTestNameSpace.MyEnum.First; + case string s when s.Equals(nameof(global::MyTestNameSpace.MyEnum.First), global::System.StringComparison.OrdinalIgnoreCase): + value = global::MyTestNameSpace.MyEnum.First; return true; - case string s when s.Equals(nameof(MyTestNameSpace.MyEnum.Second), global::System.StringComparison.OrdinalIgnoreCase): - value = MyTestNameSpace.MyEnum.Second; + case string s when s.Equals(nameof(global::MyTestNameSpace.MyEnum.Second), global::System.StringComparison.OrdinalIgnoreCase): + value = global::MyTestNameSpace.MyEnum.Second; return true; - case string s when s.Equals(nameof(MyTestNameSpace.MyEnum.Third), global::System.StringComparison.OrdinalIgnoreCase): - value = MyTestNameSpace.MyEnum.Third; + case string s when s.Equals(nameof(global::MyTestNameSpace.MyEnum.Third), global::System.StringComparison.OrdinalIgnoreCase): + value = global::MyTestNameSpace.MyEnum.Third; return true; case string s when int.TryParse(name, out var val): - value = (MyTestNameSpace.MyEnum)val; + value = (global::MyTestNameSpace.MyEnum)val; return true; default: value = default; @@ -216,17 +216,17 @@ namespace MyTestNameSpace { switch (name) { - case nameof(MyTestNameSpace.MyEnum.First): - value = MyTestNameSpace.MyEnum.First; + case nameof(global::MyTestNameSpace.MyEnum.First): + value = global::MyTestNameSpace.MyEnum.First; return true; - case nameof(MyTestNameSpace.MyEnum.Second): - value = MyTestNameSpace.MyEnum.Second; + case nameof(global::MyTestNameSpace.MyEnum.Second): + value = global::MyTestNameSpace.MyEnum.Second; return true; - case nameof(MyTestNameSpace.MyEnum.Third): - value = MyTestNameSpace.MyEnum.Third; + case nameof(global::MyTestNameSpace.MyEnum.Third): + value = global::MyTestNameSpace.MyEnum.Third; return true; case string s when int.TryParse(name, out var val): - value = (MyTestNameSpace.MyEnum)val; + value = (global::MyTestNameSpace.MyEnum)val; return true; default: value = default; @@ -238,35 +238,35 @@ namespace MyTestNameSpace #if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Converts the span representation of the name or numeric value of - /// an to the equivalent instance. + /// an to the equivalent instance. /// The return value indicates whether the conversion succeeded. /// /// The span representation of the enumeration name or underlying value to convert /// When this method returns, contains an object of type - /// whose + /// whose /// value is represented by if the parse operation succeeds. /// If the parse operation fails, contains the default value of the underlying type - /// of . This parameter is passed uninitialized. + /// of . This parameter is passed uninitialized. /// true if the value parameter was converted successfully; otherwise, false. public static bool TryParse( #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif in ReadOnlySpan name, - out MyTestNameSpace.MyEnum value) + out global::MyTestNameSpace.MyEnum value) => TryParse(name, out value, false, false); /// /// Converts the span representation of the name or numeric value of - /// an to the equivalent instance. + /// an to the equivalent instance. /// The return value indicates whether the conversion succeeded. /// /// The span representation of the enumeration name or underlying value to convert /// When this method returns, contains an object of type - /// whose + /// whose /// value is represented by if the parse operation succeeds. /// If the parse operation fails, contains the default value of the underlying type - /// of . This parameter is passed uninitialized. + /// of . This parameter is passed uninitialized. /// true to read value in case insensitive mode; false to read value in case sensitive mode. /// true if the value parameter was converted successfully; otherwise, false. public static bool TryParse( @@ -274,21 +274,21 @@ namespace MyTestNameSpace [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif in ReadOnlySpan name, - out MyTestNameSpace.MyEnum value, + out global::MyTestNameSpace.MyEnum value, bool ignoreCase) => TryParse(name, out value, ignoreCase, false); /// /// Converts the span representation of the name or numeric value of - /// an to the equivalent instance. + /// an to the equivalent instance. /// The return value indicates whether the conversion succeeded. /// /// The span representation of the enumeration name or underlying value to convert /// When this method returns, contains an object of type - /// whose + /// whose /// value is represented by if the parse operation succeeds. /// If the parse operation fails, contains the default value of the underlying type - /// of . This parameter is passed uninitialized. + /// of . This parameter is passed uninitialized. /// true to read value in case insensitive mode; false to read value in case sensitive mode. /// If true, considers the value included in metadata attributes such as /// [Display] attribute when parsing, otherwise only considers the member names. @@ -298,7 +298,7 @@ namespace MyTestNameSpace [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif in ReadOnlySpan name, - out MyTestNameSpace.MyEnum result, + out global::MyTestNameSpace.MyEnum result, bool ignoreCase, bool allowMatchingMetadataAttribute) { @@ -306,17 +306,17 @@ namespace MyTestNameSpace { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(MyTestNameSpace.MyEnum.First).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): - result = MyTestNameSpace.MyEnum.First; + case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.First).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + result = global::MyTestNameSpace.MyEnum.First; return true; - case ReadOnlySpan current when current.Equals(nameof(MyTestNameSpace.MyEnum.Second).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): - result = MyTestNameSpace.MyEnum.Second; + case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.Second).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + result = global::MyTestNameSpace.MyEnum.Second; return true; - case ReadOnlySpan current when current.Equals(nameof(MyTestNameSpace.MyEnum.Third).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): - result = MyTestNameSpace.MyEnum.Third; + case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.Third).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + result = global::MyTestNameSpace.MyEnum.Third; return true; case ReadOnlySpan current when int.TryParse(name, out var numericResult): - result = (MyTestNameSpace.MyEnum)numericResult; + result = (global::MyTestNameSpace.MyEnum)numericResult; return true; default: result = default; @@ -327,17 +327,17 @@ namespace MyTestNameSpace { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(MyTestNameSpace.MyEnum.First).AsSpan(), global::System.StringComparison.Ordinal): - result = MyTestNameSpace.MyEnum.First; + case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.First).AsSpan(), global::System.StringComparison.Ordinal): + result = global::MyTestNameSpace.MyEnum.First; return true; - case ReadOnlySpan current when current.Equals(nameof(MyTestNameSpace.MyEnum.Second).AsSpan(), global::System.StringComparison.Ordinal): - result = MyTestNameSpace.MyEnum.Second; + case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.Second).AsSpan(), global::System.StringComparison.Ordinal): + result = global::MyTestNameSpace.MyEnum.Second; return true; - case ReadOnlySpan current when current.Equals(nameof(MyTestNameSpace.MyEnum.Third).AsSpan(), global::System.StringComparison.Ordinal): - result = MyTestNameSpace.MyEnum.Third; + case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.Third).AsSpan(), global::System.StringComparison.Ordinal): + result = global::MyTestNameSpace.MyEnum.Third; return true; case ReadOnlySpan current when int.TryParse(name, out var numericResult): - result = (MyTestNameSpace.MyEnum)numericResult; + result = (global::MyTestNameSpace.MyEnum)numericResult; return true; default: result = default; @@ -349,35 +349,35 @@ namespace MyTestNameSpace /// /// Retrieves an array of the values of the members defined in - /// . + /// . /// Note that this returns a new array with every invocation, so /// should be cached if appropriate. /// - /// An array of the values defined in - public static MyTestNameSpace.MyEnum[] GetValues() + /// An array of the values defined in + public static global::MyTestNameSpace.MyEnum[] GetValues() { return new[] { - MyTestNameSpace.MyEnum.First, - MyTestNameSpace.MyEnum.Second, - MyTestNameSpace.MyEnum.Third, + global::MyTestNameSpace.MyEnum.First, + global::MyTestNameSpace.MyEnum.Second, + global::MyTestNameSpace.MyEnum.Third, }; } /// /// Retrieves an array of the names of the members defined in - /// . + /// . /// Note that this returns a new array with every invocation, so /// should be cached if appropriate. /// - /// An array of the names of the members defined in + /// An array of the names of the members defined in public static string[] GetNames() { return new[] { - nameof(MyTestNameSpace.MyEnum.First), - nameof(MyTestNameSpace.MyEnum.Second), - nameof(MyTestNameSpace.MyEnum.Third), + nameof(global::MyTestNameSpace.MyEnum.First), + nameof(global::MyTestNameSpace.MyEnum.Second), + nameof(global::MyTestNameSpace.MyEnum.Third), }; } } diff --git a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsInChildNamespace.verified.txt b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsInChildNamespace.verified.txt index cd11f81..2fb36c3 100644 --- a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsInChildNamespace.verified.txt +++ b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsInChildNamespace.verified.txt @@ -15,7 +15,7 @@ using System; namespace MyTestNameSpace { /// - /// Extension methods for + /// Extension methods for /// public static partial class MyEnumExtensions { @@ -26,18 +26,18 @@ namespace MyTestNameSpace public const int Length = 2; /// - /// Returns the string representation of the value. + /// Returns the string representation of the value. /// If the attribute is decorated with a [Display] attribute, then /// uses the provided value. Otherwise uses the name of the member, equivalent to /// calling ToString() on . /// /// The value to retrieve the string value for /// The string representation of the value - public static string ToStringFast(this MyTestNameSpace.MyEnum value) + public static string ToStringFast(this global::MyTestNameSpace.MyEnum value) => value switch { - MyTestNameSpace.MyEnum.First => nameof(MyTestNameSpace.MyEnum.First), - MyTestNameSpace.MyEnum.Second => nameof(MyTestNameSpace.MyEnum.Second), + global::MyTestNameSpace.MyEnum.First => nameof(global::MyTestNameSpace.MyEnum.First), + global::MyTestNameSpace.MyEnum.Second => nameof(global::MyTestNameSpace.MyEnum.Second), _ => value.ToString(), }; @@ -46,11 +46,11 @@ namespace MyTestNameSpace /// /// The value to check if it's defined /// true if the value exists in the enumeration, false otherwise - public static bool IsDefined(MyTestNameSpace.MyEnum value) + public static bool IsDefined(global::MyTestNameSpace.MyEnum value) => value switch { - MyTestNameSpace.MyEnum.First => true, - MyTestNameSpace.MyEnum.Second => true, + global::MyTestNameSpace.MyEnum.First => true, + global::MyTestNameSpace.MyEnum.Second => true, _ => false, }; @@ -74,8 +74,8 @@ namespace MyTestNameSpace { return name switch { - nameof(MyTestNameSpace.MyEnum.First) => true, - nameof(MyTestNameSpace.MyEnum.Second) => true, + nameof(global::MyTestNameSpace.MyEnum.First) => true, + nameof(global::MyTestNameSpace.MyEnum.Second) => true, _ => false, }; } @@ -102,8 +102,8 @@ namespace MyTestNameSpace { return name switch { - ReadOnlySpan current when current.Equals(nameof(MyTestNameSpace.MyEnum.First).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(MyTestNameSpace.MyEnum.Second).AsSpan(), global::System.StringComparison.Ordinal) => true, + 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, _ => false, }; } @@ -111,35 +111,35 @@ namespace MyTestNameSpace /// /// Converts the string representation of the name or numeric value of - /// an to the equivalent instance. + /// an to the equivalent instance. /// The return value indicates whether the conversion succeeded. /// /// The case-sensitive string representation of the enumeration name or underlying value to convert /// When this method returns, contains an object of type - /// whose + /// whose /// value is represented by if the parse operation succeeds. /// If the parse operation fails, contains the default value of the underlying type - /// of . This parameter is passed uninitialized. + /// of . This parameter is passed uninitialized. /// true if the value parameter was converted successfully; otherwise, false. public static bool TryParse( #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif string? name, - out MyTestNameSpace.MyEnum value) + out global::MyTestNameSpace.MyEnum value) => TryParse(name, out value, false, false); /// /// Converts the string representation of the name or numeric value of - /// an to the equivalent instance. + /// an to the equivalent instance. /// The return value indicates whether the conversion succeeded. /// /// The string representation of the enumeration name or underlying value to convert /// When this method returns, contains an object of type - /// whose + /// whose /// value is represented by if the parse operation succeeds. /// If the parse operation fails, contains the default value of the underlying type - /// of . This parameter is passed uninitialized. + /// of . This parameter is passed uninitialized. /// true to read value in case insensitive mode; false to read value in case sensitive mode. /// true if the value parameter was converted successfully; otherwise, false. public static bool TryParse( @@ -147,21 +147,21 @@ namespace MyTestNameSpace [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif string? name, - out MyTestNameSpace.MyEnum value, + out global::MyTestNameSpace.MyEnum value, bool ignoreCase) => TryParse(name, out value, ignoreCase, false); /// /// Converts the string representation of the name or numeric value of - /// an to the equivalent instance. + /// an to the equivalent instance. /// The return value indicates whether the conversion succeeded. /// /// The string representation of the enumeration name or underlying value to convert /// When this method returns, contains an object of type - /// whose + /// whose /// value is represented by if the parse operation succeeds. /// If the parse operation fails, contains the default value of the underlying type - /// of . This parameter is passed uninitialized. + /// of . This parameter is passed uninitialized. /// true to read value in case insensitive mode; false to read value in case sensitive mode. /// If true, considers the value included in metadata attributes such as /// [Display] attribute when parsing, otherwise only considers the member names. @@ -171,7 +171,7 @@ namespace MyTestNameSpace [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif string? name, - out MyTestNameSpace.MyEnum value, + out global::MyTestNameSpace.MyEnum value, bool ignoreCase, bool allowMatchingMetadataAttribute) { @@ -179,14 +179,14 @@ namespace MyTestNameSpace { switch (name) { - case string s when s.Equals(nameof(MyTestNameSpace.MyEnum.First), global::System.StringComparison.OrdinalIgnoreCase): - value = MyTestNameSpace.MyEnum.First; + case string s when s.Equals(nameof(global::MyTestNameSpace.MyEnum.First), global::System.StringComparison.OrdinalIgnoreCase): + value = global::MyTestNameSpace.MyEnum.First; return true; - case string s when s.Equals(nameof(MyTestNameSpace.MyEnum.Second), global::System.StringComparison.OrdinalIgnoreCase): - value = MyTestNameSpace.MyEnum.Second; + case string s when s.Equals(nameof(global::MyTestNameSpace.MyEnum.Second), global::System.StringComparison.OrdinalIgnoreCase): + value = global::MyTestNameSpace.MyEnum.Second; return true; case string s when int.TryParse(name, out var val): - value = (MyTestNameSpace.MyEnum)val; + value = (global::MyTestNameSpace.MyEnum)val; return true; default: value = default; @@ -197,14 +197,14 @@ namespace MyTestNameSpace { switch (name) { - case nameof(MyTestNameSpace.MyEnum.First): - value = MyTestNameSpace.MyEnum.First; + case nameof(global::MyTestNameSpace.MyEnum.First): + value = global::MyTestNameSpace.MyEnum.First; return true; - case nameof(MyTestNameSpace.MyEnum.Second): - value = MyTestNameSpace.MyEnum.Second; + case nameof(global::MyTestNameSpace.MyEnum.Second): + value = global::MyTestNameSpace.MyEnum.Second; return true; case string s when int.TryParse(name, out var val): - value = (MyTestNameSpace.MyEnum)val; + value = (global::MyTestNameSpace.MyEnum)val; return true; default: value = default; @@ -216,35 +216,35 @@ namespace MyTestNameSpace #if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Converts the span representation of the name or numeric value of - /// an to the equivalent instance. + /// an to the equivalent instance. /// The return value indicates whether the conversion succeeded. /// /// The span representation of the enumeration name or underlying value to convert /// When this method returns, contains an object of type - /// whose + /// whose /// value is represented by if the parse operation succeeds. /// If the parse operation fails, contains the default value of the underlying type - /// of . This parameter is passed uninitialized. + /// of . This parameter is passed uninitialized. /// true if the value parameter was converted successfully; otherwise, false. public static bool TryParse( #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif in ReadOnlySpan name, - out MyTestNameSpace.MyEnum value) + out global::MyTestNameSpace.MyEnum value) => TryParse(name, out value, false, false); /// /// Converts the span representation of the name or numeric value of - /// an to the equivalent instance. + /// an to the equivalent instance. /// The return value indicates whether the conversion succeeded. /// /// The span representation of the enumeration name or underlying value to convert /// When this method returns, contains an object of type - /// whose + /// whose /// value is represented by if the parse operation succeeds. /// If the parse operation fails, contains the default value of the underlying type - /// of . This parameter is passed uninitialized. + /// of . This parameter is passed uninitialized. /// true to read value in case insensitive mode; false to read value in case sensitive mode. /// true if the value parameter was converted successfully; otherwise, false. public static bool TryParse( @@ -252,21 +252,21 @@ namespace MyTestNameSpace [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif in ReadOnlySpan name, - out MyTestNameSpace.MyEnum value, + out global::MyTestNameSpace.MyEnum value, bool ignoreCase) => TryParse(name, out value, ignoreCase, false); /// /// Converts the span representation of the name or numeric value of - /// an to the equivalent instance. + /// an to the equivalent instance. /// The return value indicates whether the conversion succeeded. /// /// The span representation of the enumeration name or underlying value to convert /// When this method returns, contains an object of type - /// whose + /// whose /// value is represented by if the parse operation succeeds. /// If the parse operation fails, contains the default value of the underlying type - /// of . This parameter is passed uninitialized. + /// of . This parameter is passed uninitialized. /// true to read value in case insensitive mode; false to read value in case sensitive mode. /// If true, considers the value included in metadata attributes such as /// [Display] attribute when parsing, otherwise only considers the member names. @@ -276,7 +276,7 @@ namespace MyTestNameSpace [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif in ReadOnlySpan name, - out MyTestNameSpace.MyEnum result, + out global::MyTestNameSpace.MyEnum result, bool ignoreCase, bool allowMatchingMetadataAttribute) { @@ -284,14 +284,14 @@ namespace MyTestNameSpace { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(MyTestNameSpace.MyEnum.First).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): - result = MyTestNameSpace.MyEnum.First; + case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.First).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + result = global::MyTestNameSpace.MyEnum.First; return true; - case ReadOnlySpan current when current.Equals(nameof(MyTestNameSpace.MyEnum.Second).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): - result = MyTestNameSpace.MyEnum.Second; + case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.Second).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + result = global::MyTestNameSpace.MyEnum.Second; return true; case ReadOnlySpan current when int.TryParse(name, out var numericResult): - result = (MyTestNameSpace.MyEnum)numericResult; + result = (global::MyTestNameSpace.MyEnum)numericResult; return true; default: result = default; @@ -302,14 +302,14 @@ namespace MyTestNameSpace { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(MyTestNameSpace.MyEnum.First).AsSpan(), global::System.StringComparison.Ordinal): - result = MyTestNameSpace.MyEnum.First; + case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.First).AsSpan(), global::System.StringComparison.Ordinal): + result = global::MyTestNameSpace.MyEnum.First; return true; - case ReadOnlySpan current when current.Equals(nameof(MyTestNameSpace.MyEnum.Second).AsSpan(), global::System.StringComparison.Ordinal): - result = MyTestNameSpace.MyEnum.Second; + case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.Second).AsSpan(), global::System.StringComparison.Ordinal): + result = global::MyTestNameSpace.MyEnum.Second; return true; case ReadOnlySpan current when int.TryParse(name, out var numericResult): - result = (MyTestNameSpace.MyEnum)numericResult; + result = (global::MyTestNameSpace.MyEnum)numericResult; return true; default: result = default; @@ -321,33 +321,33 @@ namespace MyTestNameSpace /// /// Retrieves an array of the values of the members defined in - /// . + /// . /// Note that this returns a new array with every invocation, so /// should be cached if appropriate. /// - /// An array of the values defined in - public static MyTestNameSpace.MyEnum[] GetValues() + /// An array of the values defined in + public static global::MyTestNameSpace.MyEnum[] GetValues() { return new[] { - MyTestNameSpace.MyEnum.First, - MyTestNameSpace.MyEnum.Second, + global::MyTestNameSpace.MyEnum.First, + global::MyTestNameSpace.MyEnum.Second, }; } /// /// Retrieves an array of the names of the members defined in - /// . + /// . /// Note that this returns a new array with every invocation, so /// should be cached if appropriate. /// - /// An array of the names of the members defined in + /// An array of the names of the members defined in public static string[] GetNames() { return new[] { - nameof(MyTestNameSpace.MyEnum.First), - nameof(MyTestNameSpace.MyEnum.Second), + nameof(global::MyTestNameSpace.MyEnum.First), + nameof(global::MyTestNameSpace.MyEnum.Second), }; } } diff --git a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsInGlobalNamespace.verified.txt b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsInGlobalNamespace.verified.txt index 9fd10f3..306bdc6 100644 --- a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsInGlobalNamespace.verified.txt +++ b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsInGlobalNamespace.verified.txt @@ -13,7 +13,7 @@ using System; #endif /// - /// Extension methods for + /// Extension methods for /// public static partial class MyEnumExtensions { @@ -24,18 +24,18 @@ using System; public const int Length = 2; /// - /// Returns the string representation of the value. + /// Returns the string representation of the value. /// If the attribute is decorated with a [Display] attribute, then /// uses the provided value. Otherwise uses the name of the member, equivalent to /// calling ToString() on . /// /// The value to retrieve the string value for /// The string representation of the value - public static string ToStringFast(this MyEnum value) + public static string ToStringFast(this global::MyEnum value) => value switch { - MyEnum.First => nameof(MyEnum.First), - MyEnum.Second => nameof(MyEnum.Second), + global::MyEnum.First => nameof(global::MyEnum.First), + global::MyEnum.Second => nameof(global::MyEnum.Second), _ => value.ToString(), }; @@ -44,11 +44,11 @@ using System; /// /// The value to check if it's defined /// true if the value exists in the enumeration, false otherwise - public static bool IsDefined(MyEnum value) + public static bool IsDefined(global::MyEnum value) => value switch { - MyEnum.First => true, - MyEnum.Second => true, + global::MyEnum.First => true, + global::MyEnum.Second => true, _ => false, }; @@ -72,8 +72,8 @@ using System; { return name switch { - nameof(MyEnum.First) => true, - nameof(MyEnum.Second) => true, + nameof(global::MyEnum.First) => true, + nameof(global::MyEnum.Second) => true, _ => false, }; } @@ -100,8 +100,8 @@ using System; { return name switch { - ReadOnlySpan current when current.Equals(nameof(MyEnum.First).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(MyEnum.Second).AsSpan(), global::System.StringComparison.Ordinal) => true, + 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, _ => false, }; } @@ -109,35 +109,35 @@ using System; /// /// Converts the string representation of the name or numeric value of - /// an to the equivalent instance. + /// an to the equivalent instance. /// The return value indicates whether the conversion succeeded. /// /// The case-sensitive string representation of the enumeration name or underlying value to convert /// When this method returns, contains an object of type - /// whose + /// whose /// value is represented by if the parse operation succeeds. /// If the parse operation fails, contains the default value of the underlying type - /// of . This parameter is passed uninitialized. + /// of . This parameter is passed uninitialized. /// true if the value parameter was converted successfully; otherwise, false. public static bool TryParse( #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif string? name, - out MyEnum value) + out global::MyEnum value) => TryParse(name, out value, false, false); /// /// Converts the string representation of the name or numeric value of - /// an to the equivalent instance. + /// an to the equivalent instance. /// The return value indicates whether the conversion succeeded. /// /// The string representation of the enumeration name or underlying value to convert /// When this method returns, contains an object of type - /// whose + /// whose /// value is represented by if the parse operation succeeds. /// If the parse operation fails, contains the default value of the underlying type - /// of . This parameter is passed uninitialized. + /// of . This parameter is passed uninitialized. /// true to read value in case insensitive mode; false to read value in case sensitive mode. /// true if the value parameter was converted successfully; otherwise, false. public static bool TryParse( @@ -145,21 +145,21 @@ using System; [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif string? name, - out MyEnum value, + out global::MyEnum value, bool ignoreCase) => TryParse(name, out value, ignoreCase, false); /// /// Converts the string representation of the name or numeric value of - /// an to the equivalent instance. + /// an to the equivalent instance. /// The return value indicates whether the conversion succeeded. /// /// The string representation of the enumeration name or underlying value to convert /// When this method returns, contains an object of type - /// whose + /// whose /// value is represented by if the parse operation succeeds. /// If the parse operation fails, contains the default value of the underlying type - /// of . This parameter is passed uninitialized. + /// of . This parameter is passed uninitialized. /// true to read value in case insensitive mode; false to read value in case sensitive mode. /// If true, considers the value included in metadata attributes such as /// [Display] attribute when parsing, otherwise only considers the member names. @@ -169,7 +169,7 @@ using System; [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif string? name, - out MyEnum value, + out global::MyEnum value, bool ignoreCase, bool allowMatchingMetadataAttribute) { @@ -177,14 +177,14 @@ using System; { switch (name) { - case string s when s.Equals(nameof(MyEnum.First), global::System.StringComparison.OrdinalIgnoreCase): - value = MyEnum.First; + case string s when s.Equals(nameof(global::MyEnum.First), global::System.StringComparison.OrdinalIgnoreCase): + value = global::MyEnum.First; return true; - case string s when s.Equals(nameof(MyEnum.Second), global::System.StringComparison.OrdinalIgnoreCase): - value = MyEnum.Second; + case string s when s.Equals(nameof(global::MyEnum.Second), global::System.StringComparison.OrdinalIgnoreCase): + value = global::MyEnum.Second; return true; case string s when int.TryParse(name, out var val): - value = (MyEnum)val; + value = (global::MyEnum)val; return true; default: value = default; @@ -195,14 +195,14 @@ using System; { switch (name) { - case nameof(MyEnum.First): - value = MyEnum.First; + case nameof(global::MyEnum.First): + value = global::MyEnum.First; return true; - case nameof(MyEnum.Second): - value = MyEnum.Second; + case nameof(global::MyEnum.Second): + value = global::MyEnum.Second; return true; case string s when int.TryParse(name, out var val): - value = (MyEnum)val; + value = (global::MyEnum)val; return true; default: value = default; @@ -214,35 +214,35 @@ using System; #if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Converts the span representation of the name or numeric value of - /// an to the equivalent instance. + /// an to the equivalent instance. /// The return value indicates whether the conversion succeeded. /// /// The span representation of the enumeration name or underlying value to convert /// When this method returns, contains an object of type - /// whose + /// whose /// value is represented by if the parse operation succeeds. /// If the parse operation fails, contains the default value of the underlying type - /// of . This parameter is passed uninitialized. + /// of . This parameter is passed uninitialized. /// true if the value parameter was converted successfully; otherwise, false. public static bool TryParse( #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif in ReadOnlySpan name, - out MyEnum value) + out global::MyEnum value) => TryParse(name, out value, false, false); /// /// Converts the span representation of the name or numeric value of - /// an to the equivalent instance. + /// an to the equivalent instance. /// The return value indicates whether the conversion succeeded. /// /// The span representation of the enumeration name or underlying value to convert /// When this method returns, contains an object of type - /// whose + /// whose /// value is represented by if the parse operation succeeds. /// If the parse operation fails, contains the default value of the underlying type - /// of . This parameter is passed uninitialized. + /// of . This parameter is passed uninitialized. /// true to read value in case insensitive mode; false to read value in case sensitive mode. /// true if the value parameter was converted successfully; otherwise, false. public static bool TryParse( @@ -250,21 +250,21 @@ using System; [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif in ReadOnlySpan name, - out MyEnum value, + out global::MyEnum value, bool ignoreCase) => TryParse(name, out value, ignoreCase, false); /// /// Converts the span representation of the name or numeric value of - /// an to the equivalent instance. + /// an to the equivalent instance. /// The return value indicates whether the conversion succeeded. /// /// The span representation of the enumeration name or underlying value to convert /// When this method returns, contains an object of type - /// whose + /// whose /// value is represented by if the parse operation succeeds. /// If the parse operation fails, contains the default value of the underlying type - /// of . This parameter is passed uninitialized. + /// of . This parameter is passed uninitialized. /// true to read value in case insensitive mode; false to read value in case sensitive mode. /// If true, considers the value included in metadata attributes such as /// [Display] attribute when parsing, otherwise only considers the member names. @@ -274,7 +274,7 @@ using System; [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif in ReadOnlySpan name, - out MyEnum result, + out global::MyEnum result, bool ignoreCase, bool allowMatchingMetadataAttribute) { @@ -282,14 +282,14 @@ using System; { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(MyEnum.First).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): - result = MyEnum.First; + case ReadOnlySpan current when current.Equals(nameof(global::MyEnum.First).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + result = global::MyEnum.First; return true; - case ReadOnlySpan current when current.Equals(nameof(MyEnum.Second).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): - result = MyEnum.Second; + case ReadOnlySpan current when current.Equals(nameof(global::MyEnum.Second).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + result = global::MyEnum.Second; return true; case ReadOnlySpan current when int.TryParse(name, out var numericResult): - result = (MyEnum)numericResult; + result = (global::MyEnum)numericResult; return true; default: result = default; @@ -300,14 +300,14 @@ using System; { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(MyEnum.First).AsSpan(), global::System.StringComparison.Ordinal): - result = MyEnum.First; + case ReadOnlySpan current when current.Equals(nameof(global::MyEnum.First).AsSpan(), global::System.StringComparison.Ordinal): + result = global::MyEnum.First; return true; - case ReadOnlySpan current when current.Equals(nameof(MyEnum.Second).AsSpan(), global::System.StringComparison.Ordinal): - result = MyEnum.Second; + case ReadOnlySpan current when current.Equals(nameof(global::MyEnum.Second).AsSpan(), global::System.StringComparison.Ordinal): + result = global::MyEnum.Second; return true; case ReadOnlySpan current when int.TryParse(name, out var numericResult): - result = (MyEnum)numericResult; + result = (global::MyEnum)numericResult; return true; default: result = default; @@ -319,33 +319,33 @@ using System; /// /// Retrieves an array of the values of the members defined in - /// . + /// . /// Note that this returns a new array with every invocation, so /// should be cached if appropriate. /// - /// An array of the values defined in - public static MyEnum[] GetValues() + /// An array of the values defined in + public static global::MyEnum[] GetValues() { return new[] { - MyEnum.First, - MyEnum.Second, + global::MyEnum.First, + global::MyEnum.Second, }; } /// /// Retrieves an array of the names of the members defined in - /// . + /// . /// Note that this returns a new array with every invocation, so /// should be cached if appropriate. /// - /// An array of the names of the members defined in + /// An array of the names of the members defined in public static string[] GetNames() { return new[] { - nameof(MyEnum.First), - nameof(MyEnum.Second), + nameof(global::MyEnum.First), + nameof(global::MyEnum.Second), }; } } \ No newline at end of file diff --git a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsInNestedClass.verified.txt b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsInNestedClass.verified.txt index d539c23..91ca6e6 100644 --- a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsInNestedClass.verified.txt +++ b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsInNestedClass.verified.txt @@ -15,7 +15,7 @@ using System; namespace MyTestNameSpace { /// - /// Extension methods for + /// Extension methods for /// internal static partial class MyEnumExtensions { @@ -26,18 +26,18 @@ namespace MyTestNameSpace public const int Length = 2; /// - /// Returns the string representation of the value. + /// Returns the string representation of the value. /// If the attribute is decorated with a [Display] attribute, then /// uses the provided value. Otherwise uses the name of the member, equivalent to /// calling ToString() on . /// /// The value to retrieve the string value for /// The string representation of the value - public static string ToStringFast(this MyTestNameSpace.InnerClass.MyEnum value) + public static string ToStringFast(this global::MyTestNameSpace.InnerClass.MyEnum value) => value switch { - MyTestNameSpace.InnerClass.MyEnum.First => nameof(MyTestNameSpace.InnerClass.MyEnum.First), - MyTestNameSpace.InnerClass.MyEnum.Second => nameof(MyTestNameSpace.InnerClass.MyEnum.Second), + global::MyTestNameSpace.InnerClass.MyEnum.First => nameof(global::MyTestNameSpace.InnerClass.MyEnum.First), + global::MyTestNameSpace.InnerClass.MyEnum.Second => nameof(global::MyTestNameSpace.InnerClass.MyEnum.Second), _ => value.ToString(), }; @@ -46,11 +46,11 @@ namespace MyTestNameSpace /// /// The value to check if it's defined /// true if the value exists in the enumeration, false otherwise - public static bool IsDefined(MyTestNameSpace.InnerClass.MyEnum value) + public static bool IsDefined(global::MyTestNameSpace.InnerClass.MyEnum value) => value switch { - MyTestNameSpace.InnerClass.MyEnum.First => true, - MyTestNameSpace.InnerClass.MyEnum.Second => true, + global::MyTestNameSpace.InnerClass.MyEnum.First => true, + global::MyTestNameSpace.InnerClass.MyEnum.Second => true, _ => false, }; @@ -74,8 +74,8 @@ namespace MyTestNameSpace { return name switch { - nameof(MyTestNameSpace.InnerClass.MyEnum.First) => true, - nameof(MyTestNameSpace.InnerClass.MyEnum.Second) => true, + nameof(global::MyTestNameSpace.InnerClass.MyEnum.First) => true, + nameof(global::MyTestNameSpace.InnerClass.MyEnum.Second) => true, _ => false, }; } @@ -102,8 +102,8 @@ namespace MyTestNameSpace { return name switch { - ReadOnlySpan current when current.Equals(nameof(MyTestNameSpace.InnerClass.MyEnum.First).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(MyTestNameSpace.InnerClass.MyEnum.Second).AsSpan(), global::System.StringComparison.Ordinal) => true, + 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, _ => false, }; } @@ -111,35 +111,35 @@ namespace MyTestNameSpace /// /// Converts the string representation of the name or numeric value of - /// an to the equivalent instance. + /// an to the equivalent instance. /// The return value indicates whether the conversion succeeded. /// /// The case-sensitive string representation of the enumeration name or underlying value to convert /// When this method returns, contains an object of type - /// whose + /// whose /// value is represented by if the parse operation succeeds. /// If the parse operation fails, contains the default value of the underlying type - /// of . This parameter is passed uninitialized. + /// of . This parameter is passed uninitialized. /// true if the value parameter was converted successfully; otherwise, false. public static bool TryParse( #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif string? name, - out MyTestNameSpace.InnerClass.MyEnum value) + out global::MyTestNameSpace.InnerClass.MyEnum value) => TryParse(name, out value, false, false); /// /// Converts the string representation of the name or numeric value of - /// an to the equivalent instance. + /// an to the equivalent instance. /// The return value indicates whether the conversion succeeded. /// /// The string representation of the enumeration name or underlying value to convert /// When this method returns, contains an object of type - /// whose + /// whose /// value is represented by if the parse operation succeeds. /// If the parse operation fails, contains the default value of the underlying type - /// of . This parameter is passed uninitialized. + /// of . This parameter is passed uninitialized. /// true to read value in case insensitive mode; false to read value in case sensitive mode. /// true if the value parameter was converted successfully; otherwise, false. public static bool TryParse( @@ -147,21 +147,21 @@ namespace MyTestNameSpace [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif string? name, - out MyTestNameSpace.InnerClass.MyEnum value, + out global::MyTestNameSpace.InnerClass.MyEnum value, bool ignoreCase) => TryParse(name, out value, ignoreCase, false); /// /// Converts the string representation of the name or numeric value of - /// an to the equivalent instance. + /// an to the equivalent instance. /// The return value indicates whether the conversion succeeded. /// /// The string representation of the enumeration name or underlying value to convert /// When this method returns, contains an object of type - /// whose + /// whose /// value is represented by if the parse operation succeeds. /// If the parse operation fails, contains the default value of the underlying type - /// of . This parameter is passed uninitialized. + /// of . This parameter is passed uninitialized. /// true to read value in case insensitive mode; false to read value in case sensitive mode. /// If true, considers the value included in metadata attributes such as /// [Display] attribute when parsing, otherwise only considers the member names. @@ -171,7 +171,7 @@ namespace MyTestNameSpace [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif string? name, - out MyTestNameSpace.InnerClass.MyEnum value, + out global::MyTestNameSpace.InnerClass.MyEnum value, bool ignoreCase, bool allowMatchingMetadataAttribute) { @@ -179,14 +179,14 @@ namespace MyTestNameSpace { switch (name) { - case string s when s.Equals(nameof(MyTestNameSpace.InnerClass.MyEnum.First), global::System.StringComparison.OrdinalIgnoreCase): - value = MyTestNameSpace.InnerClass.MyEnum.First; + case string s when s.Equals(nameof(global::MyTestNameSpace.InnerClass.MyEnum.First), global::System.StringComparison.OrdinalIgnoreCase): + value = global::MyTestNameSpace.InnerClass.MyEnum.First; return true; - case string s when s.Equals(nameof(MyTestNameSpace.InnerClass.MyEnum.Second), global::System.StringComparison.OrdinalIgnoreCase): - value = MyTestNameSpace.InnerClass.MyEnum.Second; + case string s when s.Equals(nameof(global::MyTestNameSpace.InnerClass.MyEnum.Second), global::System.StringComparison.OrdinalIgnoreCase): + value = global::MyTestNameSpace.InnerClass.MyEnum.Second; return true; case string s when int.TryParse(name, out var val): - value = (MyTestNameSpace.InnerClass.MyEnum)val; + value = (global::MyTestNameSpace.InnerClass.MyEnum)val; return true; default: value = default; @@ -197,14 +197,14 @@ namespace MyTestNameSpace { switch (name) { - case nameof(MyTestNameSpace.InnerClass.MyEnum.First): - value = MyTestNameSpace.InnerClass.MyEnum.First; + case nameof(global::MyTestNameSpace.InnerClass.MyEnum.First): + value = global::MyTestNameSpace.InnerClass.MyEnum.First; return true; - case nameof(MyTestNameSpace.InnerClass.MyEnum.Second): - value = MyTestNameSpace.InnerClass.MyEnum.Second; + case nameof(global::MyTestNameSpace.InnerClass.MyEnum.Second): + value = global::MyTestNameSpace.InnerClass.MyEnum.Second; return true; case string s when int.TryParse(name, out var val): - value = (MyTestNameSpace.InnerClass.MyEnum)val; + value = (global::MyTestNameSpace.InnerClass.MyEnum)val; return true; default: value = default; @@ -216,35 +216,35 @@ namespace MyTestNameSpace #if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Converts the span representation of the name or numeric value of - /// an to the equivalent instance. + /// an to the equivalent instance. /// The return value indicates whether the conversion succeeded. /// /// The span representation of the enumeration name or underlying value to convert /// When this method returns, contains an object of type - /// whose + /// whose /// value is represented by if the parse operation succeeds. /// If the parse operation fails, contains the default value of the underlying type - /// of . This parameter is passed uninitialized. + /// of . This parameter is passed uninitialized. /// true if the value parameter was converted successfully; otherwise, false. public static bool TryParse( #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif in ReadOnlySpan name, - out MyTestNameSpace.InnerClass.MyEnum value) + out global::MyTestNameSpace.InnerClass.MyEnum value) => TryParse(name, out value, false, false); /// /// Converts the span representation of the name or numeric value of - /// an to the equivalent instance. + /// an to the equivalent instance. /// The return value indicates whether the conversion succeeded. /// /// The span representation of the enumeration name or underlying value to convert /// When this method returns, contains an object of type - /// whose + /// whose /// value is represented by if the parse operation succeeds. /// If the parse operation fails, contains the default value of the underlying type - /// of . This parameter is passed uninitialized. + /// of . This parameter is passed uninitialized. /// true to read value in case insensitive mode; false to read value in case sensitive mode. /// true if the value parameter was converted successfully; otherwise, false. public static bool TryParse( @@ -252,21 +252,21 @@ namespace MyTestNameSpace [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif in ReadOnlySpan name, - out MyTestNameSpace.InnerClass.MyEnum value, + out global::MyTestNameSpace.InnerClass.MyEnum value, bool ignoreCase) => TryParse(name, out value, ignoreCase, false); /// /// Converts the span representation of the name or numeric value of - /// an to the equivalent instance. + /// an to the equivalent instance. /// The return value indicates whether the conversion succeeded. /// /// The span representation of the enumeration name or underlying value to convert /// When this method returns, contains an object of type - /// whose + /// whose /// value is represented by if the parse operation succeeds. /// If the parse operation fails, contains the default value of the underlying type - /// of . This parameter is passed uninitialized. + /// of . This parameter is passed uninitialized. /// true to read value in case insensitive mode; false to read value in case sensitive mode. /// If true, considers the value included in metadata attributes such as /// [Display] attribute when parsing, otherwise only considers the member names. @@ -276,7 +276,7 @@ namespace MyTestNameSpace [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif in ReadOnlySpan name, - out MyTestNameSpace.InnerClass.MyEnum result, + out global::MyTestNameSpace.InnerClass.MyEnum result, bool ignoreCase, bool allowMatchingMetadataAttribute) { @@ -284,14 +284,14 @@ namespace MyTestNameSpace { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(MyTestNameSpace.InnerClass.MyEnum.First).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): - result = MyTestNameSpace.InnerClass.MyEnum.First; + case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.InnerClass.MyEnum.First).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + result = global::MyTestNameSpace.InnerClass.MyEnum.First; return true; - case ReadOnlySpan current when current.Equals(nameof(MyTestNameSpace.InnerClass.MyEnum.Second).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): - result = MyTestNameSpace.InnerClass.MyEnum.Second; + case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.InnerClass.MyEnum.Second).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + result = global::MyTestNameSpace.InnerClass.MyEnum.Second; return true; case ReadOnlySpan current when int.TryParse(name, out var numericResult): - result = (MyTestNameSpace.InnerClass.MyEnum)numericResult; + result = (global::MyTestNameSpace.InnerClass.MyEnum)numericResult; return true; default: result = default; @@ -302,14 +302,14 @@ namespace MyTestNameSpace { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(MyTestNameSpace.InnerClass.MyEnum.First).AsSpan(), global::System.StringComparison.Ordinal): - result = MyTestNameSpace.InnerClass.MyEnum.First; + case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.InnerClass.MyEnum.First).AsSpan(), global::System.StringComparison.Ordinal): + result = global::MyTestNameSpace.InnerClass.MyEnum.First; return true; - case ReadOnlySpan current when current.Equals(nameof(MyTestNameSpace.InnerClass.MyEnum.Second).AsSpan(), global::System.StringComparison.Ordinal): - result = MyTestNameSpace.InnerClass.MyEnum.Second; + case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.InnerClass.MyEnum.Second).AsSpan(), global::System.StringComparison.Ordinal): + result = global::MyTestNameSpace.InnerClass.MyEnum.Second; return true; case ReadOnlySpan current when int.TryParse(name, out var numericResult): - result = (MyTestNameSpace.InnerClass.MyEnum)numericResult; + result = (global::MyTestNameSpace.InnerClass.MyEnum)numericResult; return true; default: result = default; @@ -321,33 +321,33 @@ namespace MyTestNameSpace /// /// Retrieves an array of the values of the members defined in - /// . + /// . /// Note that this returns a new array with every invocation, so /// should be cached if appropriate. /// - /// An array of the values defined in - public static MyTestNameSpace.InnerClass.MyEnum[] GetValues() + /// An array of the values defined in + public static global::MyTestNameSpace.InnerClass.MyEnum[] GetValues() { return new[] { - MyTestNameSpace.InnerClass.MyEnum.First, - MyTestNameSpace.InnerClass.MyEnum.Second, + global::MyTestNameSpace.InnerClass.MyEnum.First, + global::MyTestNameSpace.InnerClass.MyEnum.Second, }; } /// /// Retrieves an array of the names of the members defined in - /// . + /// . /// Note that this returns a new array with every invocation, so /// should be cached if appropriate. /// - /// An array of the names of the members defined in + /// An array of the names of the members defined in public static string[] GetNames() { return new[] { - nameof(MyTestNameSpace.InnerClass.MyEnum.First), - nameof(MyTestNameSpace.InnerClass.MyEnum.Second), + nameof(global::MyTestNameSpace.InnerClass.MyEnum.First), + nameof(global::MyTestNameSpace.InnerClass.MyEnum.Second), }; } } diff --git a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsWithCustomName.verified.txt b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsWithCustomName.verified.txt index 0573669..768f535 100644 --- a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsWithCustomName.verified.txt +++ b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsWithCustomName.verified.txt @@ -15,7 +15,7 @@ using System; namespace MyTestNameSpace { /// - /// Extension methods for + /// Extension methods for /// internal static partial class A { @@ -26,18 +26,18 @@ namespace MyTestNameSpace public const int Length = 2; /// - /// Returns the string representation of the value. + /// Returns the string representation of the value. /// If the attribute is decorated with a [Display] attribute, then /// uses the provided value. Otherwise uses the name of the member, equivalent to /// calling ToString() on . /// /// The value to retrieve the string value for /// The string representation of the value - public static string ToStringFast(this MyTestNameSpace.MyEnum value) + public static string ToStringFast(this global::MyTestNameSpace.MyEnum value) => value switch { - MyTestNameSpace.MyEnum.First => nameof(MyTestNameSpace.MyEnum.First), - MyTestNameSpace.MyEnum.Second => nameof(MyTestNameSpace.MyEnum.Second), + global::MyTestNameSpace.MyEnum.First => nameof(global::MyTestNameSpace.MyEnum.First), + global::MyTestNameSpace.MyEnum.Second => nameof(global::MyTestNameSpace.MyEnum.Second), _ => value.ToString(), }; @@ -46,11 +46,11 @@ namespace MyTestNameSpace /// /// The value to check if it's defined /// true if the value exists in the enumeration, false otherwise - public static bool IsDefined(MyTestNameSpace.MyEnum value) + public static bool IsDefined(global::MyTestNameSpace.MyEnum value) => value switch { - MyTestNameSpace.MyEnum.First => true, - MyTestNameSpace.MyEnum.Second => true, + global::MyTestNameSpace.MyEnum.First => true, + global::MyTestNameSpace.MyEnum.Second => true, _ => false, }; @@ -74,8 +74,8 @@ namespace MyTestNameSpace { return name switch { - nameof(MyTestNameSpace.MyEnum.First) => true, - nameof(MyTestNameSpace.MyEnum.Second) => true, + nameof(global::MyTestNameSpace.MyEnum.First) => true, + nameof(global::MyTestNameSpace.MyEnum.Second) => true, _ => false, }; } @@ -102,8 +102,8 @@ namespace MyTestNameSpace { return name switch { - ReadOnlySpan current when current.Equals(nameof(MyTestNameSpace.MyEnum.First).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(MyTestNameSpace.MyEnum.Second).AsSpan(), global::System.StringComparison.Ordinal) => true, + 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, _ => false, }; } @@ -111,35 +111,35 @@ namespace MyTestNameSpace /// /// Converts the string representation of the name or numeric value of - /// an to the equivalent instance. + /// an to the equivalent instance. /// The return value indicates whether the conversion succeeded. /// /// The case-sensitive string representation of the enumeration name or underlying value to convert /// When this method returns, contains an object of type - /// whose + /// whose /// value is represented by if the parse operation succeeds. /// If the parse operation fails, contains the default value of the underlying type - /// of . This parameter is passed uninitialized. + /// of . This parameter is passed uninitialized. /// true if the value parameter was converted successfully; otherwise, false. public static bool TryParse( #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif string? name, - out MyTestNameSpace.MyEnum value) + out global::MyTestNameSpace.MyEnum value) => TryParse(name, out value, false, false); /// /// Converts the string representation of the name or numeric value of - /// an to the equivalent instance. + /// an to the equivalent instance. /// The return value indicates whether the conversion succeeded. /// /// The string representation of the enumeration name or underlying value to convert /// When this method returns, contains an object of type - /// whose + /// whose /// value is represented by if the parse operation succeeds. /// If the parse operation fails, contains the default value of the underlying type - /// of . This parameter is passed uninitialized. + /// of . This parameter is passed uninitialized. /// true to read value in case insensitive mode; false to read value in case sensitive mode. /// true if the value parameter was converted successfully; otherwise, false. public static bool TryParse( @@ -147,21 +147,21 @@ namespace MyTestNameSpace [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif string? name, - out MyTestNameSpace.MyEnum value, + out global::MyTestNameSpace.MyEnum value, bool ignoreCase) => TryParse(name, out value, ignoreCase, false); /// /// Converts the string representation of the name or numeric value of - /// an to the equivalent instance. + /// an to the equivalent instance. /// The return value indicates whether the conversion succeeded. /// /// The string representation of the enumeration name or underlying value to convert /// When this method returns, contains an object of type - /// whose + /// whose /// value is represented by if the parse operation succeeds. /// If the parse operation fails, contains the default value of the underlying type - /// of . This parameter is passed uninitialized. + /// of . This parameter is passed uninitialized. /// true to read value in case insensitive mode; false to read value in case sensitive mode. /// If true, considers the value included in metadata attributes such as /// [Display] attribute when parsing, otherwise only considers the member names. @@ -171,7 +171,7 @@ namespace MyTestNameSpace [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif string? name, - out MyTestNameSpace.MyEnum value, + out global::MyTestNameSpace.MyEnum value, bool ignoreCase, bool allowMatchingMetadataAttribute) { @@ -179,14 +179,14 @@ namespace MyTestNameSpace { switch (name) { - case string s when s.Equals(nameof(MyTestNameSpace.MyEnum.First), global::System.StringComparison.OrdinalIgnoreCase): - value = MyTestNameSpace.MyEnum.First; + case string s when s.Equals(nameof(global::MyTestNameSpace.MyEnum.First), global::System.StringComparison.OrdinalIgnoreCase): + value = global::MyTestNameSpace.MyEnum.First; return true; - case string s when s.Equals(nameof(MyTestNameSpace.MyEnum.Second), global::System.StringComparison.OrdinalIgnoreCase): - value = MyTestNameSpace.MyEnum.Second; + case string s when s.Equals(nameof(global::MyTestNameSpace.MyEnum.Second), global::System.StringComparison.OrdinalIgnoreCase): + value = global::MyTestNameSpace.MyEnum.Second; return true; case string s when int.TryParse(name, out var val): - value = (MyTestNameSpace.MyEnum)val; + value = (global::MyTestNameSpace.MyEnum)val; return true; default: value = default; @@ -197,14 +197,14 @@ namespace MyTestNameSpace { switch (name) { - case nameof(MyTestNameSpace.MyEnum.First): - value = MyTestNameSpace.MyEnum.First; + case nameof(global::MyTestNameSpace.MyEnum.First): + value = global::MyTestNameSpace.MyEnum.First; return true; - case nameof(MyTestNameSpace.MyEnum.Second): - value = MyTestNameSpace.MyEnum.Second; + case nameof(global::MyTestNameSpace.MyEnum.Second): + value = global::MyTestNameSpace.MyEnum.Second; return true; case string s when int.TryParse(name, out var val): - value = (MyTestNameSpace.MyEnum)val; + value = (global::MyTestNameSpace.MyEnum)val; return true; default: value = default; @@ -216,35 +216,35 @@ namespace MyTestNameSpace #if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Converts the span representation of the name or numeric value of - /// an to the equivalent instance. + /// an to the equivalent instance. /// The return value indicates whether the conversion succeeded. /// /// The span representation of the enumeration name or underlying value to convert /// When this method returns, contains an object of type - /// whose + /// whose /// value is represented by if the parse operation succeeds. /// If the parse operation fails, contains the default value of the underlying type - /// of . This parameter is passed uninitialized. + /// of . This parameter is passed uninitialized. /// true if the value parameter was converted successfully; otherwise, false. public static bool TryParse( #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif in ReadOnlySpan name, - out MyTestNameSpace.MyEnum value) + out global::MyTestNameSpace.MyEnum value) => TryParse(name, out value, false, false); /// /// Converts the span representation of the name or numeric value of - /// an to the equivalent instance. + /// an to the equivalent instance. /// The return value indicates whether the conversion succeeded. /// /// The span representation of the enumeration name or underlying value to convert /// When this method returns, contains an object of type - /// whose + /// whose /// value is represented by if the parse operation succeeds. /// If the parse operation fails, contains the default value of the underlying type - /// of . This parameter is passed uninitialized. + /// of . This parameter is passed uninitialized. /// true to read value in case insensitive mode; false to read value in case sensitive mode. /// true if the value parameter was converted successfully; otherwise, false. public static bool TryParse( @@ -252,21 +252,21 @@ namespace MyTestNameSpace [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif in ReadOnlySpan name, - out MyTestNameSpace.MyEnum value, + out global::MyTestNameSpace.MyEnum value, bool ignoreCase) => TryParse(name, out value, ignoreCase, false); /// /// Converts the span representation of the name or numeric value of - /// an to the equivalent instance. + /// an to the equivalent instance. /// The return value indicates whether the conversion succeeded. /// /// The span representation of the enumeration name or underlying value to convert /// When this method returns, contains an object of type - /// whose + /// whose /// value is represented by if the parse operation succeeds. /// If the parse operation fails, contains the default value of the underlying type - /// of . This parameter is passed uninitialized. + /// of . This parameter is passed uninitialized. /// true to read value in case insensitive mode; false to read value in case sensitive mode. /// If true, considers the value included in metadata attributes such as /// [Display] attribute when parsing, otherwise only considers the member names. @@ -276,7 +276,7 @@ namespace MyTestNameSpace [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif in ReadOnlySpan name, - out MyTestNameSpace.MyEnum result, + out global::MyTestNameSpace.MyEnum result, bool ignoreCase, bool allowMatchingMetadataAttribute) { @@ -284,14 +284,14 @@ namespace MyTestNameSpace { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(MyTestNameSpace.MyEnum.First).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): - result = MyTestNameSpace.MyEnum.First; + case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.First).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + result = global::MyTestNameSpace.MyEnum.First; return true; - case ReadOnlySpan current when current.Equals(nameof(MyTestNameSpace.MyEnum.Second).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): - result = MyTestNameSpace.MyEnum.Second; + case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.Second).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + result = global::MyTestNameSpace.MyEnum.Second; return true; case ReadOnlySpan current when int.TryParse(name, out var numericResult): - result = (MyTestNameSpace.MyEnum)numericResult; + result = (global::MyTestNameSpace.MyEnum)numericResult; return true; default: result = default; @@ -302,14 +302,14 @@ namespace MyTestNameSpace { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(MyTestNameSpace.MyEnum.First).AsSpan(), global::System.StringComparison.Ordinal): - result = MyTestNameSpace.MyEnum.First; + case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.First).AsSpan(), global::System.StringComparison.Ordinal): + result = global::MyTestNameSpace.MyEnum.First; return true; - case ReadOnlySpan current when current.Equals(nameof(MyTestNameSpace.MyEnum.Second).AsSpan(), global::System.StringComparison.Ordinal): - result = MyTestNameSpace.MyEnum.Second; + case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.Second).AsSpan(), global::System.StringComparison.Ordinal): + result = global::MyTestNameSpace.MyEnum.Second; return true; case ReadOnlySpan current when int.TryParse(name, out var numericResult): - result = (MyTestNameSpace.MyEnum)numericResult; + result = (global::MyTestNameSpace.MyEnum)numericResult; return true; default: result = default; @@ -321,33 +321,33 @@ namespace MyTestNameSpace /// /// Retrieves an array of the values of the members defined in - /// . + /// . /// Note that this returns a new array with every invocation, so /// should be cached if appropriate. /// - /// An array of the values defined in - public static MyTestNameSpace.MyEnum[] GetValues() + /// An array of the values defined in + public static global::MyTestNameSpace.MyEnum[] GetValues() { return new[] { - MyTestNameSpace.MyEnum.First, - MyTestNameSpace.MyEnum.Second, + global::MyTestNameSpace.MyEnum.First, + global::MyTestNameSpace.MyEnum.Second, }; } /// /// Retrieves an array of the names of the members defined in - /// . + /// . /// Note that this returns a new array with every invocation, so /// should be cached if appropriate. /// - /// An array of the names of the members defined in + /// An array of the names of the members defined in public static string[] GetNames() { return new[] { - nameof(MyTestNameSpace.MyEnum.First), - nameof(MyTestNameSpace.MyEnum.Second), + nameof(global::MyTestNameSpace.MyEnum.First), + nameof(global::MyTestNameSpace.MyEnum.Second), }; } } diff --git a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsWithCustomNames.verified.txt b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsWithCustomNames.verified.txt index 084533c..ff7d4c2 100644 --- a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsWithCustomNames.verified.txt +++ b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsWithCustomNames.verified.txt @@ -15,7 +15,7 @@ using System; namespace MyTestNameSpace { /// - /// Extension methods for + /// Extension methods for /// public static partial class MyEnumExtensions { @@ -26,20 +26,20 @@ namespace MyTestNameSpace public const int Length = 4; /// - /// Returns the string representation of the value. + /// Returns the string representation of the value. /// If the attribute is decorated with a [Display] attribute, then /// uses the provided value. Otherwise uses the name of the member, equivalent to /// calling ToString() on . /// /// The value to retrieve the string value for /// The string representation of the value - public static string ToStringFast(this MyTestNameSpace.MyEnum value) + public static string ToStringFast(this global::MyTestNameSpace.MyEnum value) => value switch { - MyTestNameSpace.MyEnum.First => nameof(MyTestNameSpace.MyEnum.First), - MyTestNameSpace.MyEnum.Second => "2nd", - MyTestNameSpace.MyEnum.Third => nameof(MyTestNameSpace.MyEnum.Third), - MyTestNameSpace.MyEnum.Fourth => "4th", + global::MyTestNameSpace.MyEnum.First => nameof(global::MyTestNameSpace.MyEnum.First), + global::MyTestNameSpace.MyEnum.Second => "2nd", + global::MyTestNameSpace.MyEnum.Third => nameof(global::MyTestNameSpace.MyEnum.Third), + global::MyTestNameSpace.MyEnum.Fourth => "4th", _ => value.ToString(), }; @@ -48,13 +48,13 @@ namespace MyTestNameSpace /// /// The value to check if it's defined /// true if the value exists in the enumeration, false otherwise - public static bool IsDefined(MyTestNameSpace.MyEnum value) + public static bool IsDefined(global::MyTestNameSpace.MyEnum value) => value switch { - MyTestNameSpace.MyEnum.First => true, - MyTestNameSpace.MyEnum.Second => true, - MyTestNameSpace.MyEnum.Third => true, - MyTestNameSpace.MyEnum.Fourth => true, + global::MyTestNameSpace.MyEnum.First => true, + global::MyTestNameSpace.MyEnum.Second => true, + global::MyTestNameSpace.MyEnum.Third => true, + global::MyTestNameSpace.MyEnum.Fourth => true, _ => false, }; @@ -95,10 +95,10 @@ namespace MyTestNameSpace return name switch { - nameof(MyTestNameSpace.MyEnum.First) => true, - nameof(MyTestNameSpace.MyEnum.Second) => true, - nameof(MyTestNameSpace.MyEnum.Third) => true, - nameof(MyTestNameSpace.MyEnum.Fourth) => true, + nameof(global::MyTestNameSpace.MyEnum.First) => true, + nameof(global::MyTestNameSpace.MyEnum.Second) => true, + nameof(global::MyTestNameSpace.MyEnum.Third) => true, + nameof(global::MyTestNameSpace.MyEnum.Fourth) => true, _ => false, }; } @@ -141,10 +141,10 @@ namespace MyTestNameSpace return name switch { - ReadOnlySpan current when current.Equals(nameof(MyTestNameSpace.MyEnum.First).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(MyTestNameSpace.MyEnum.Second).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(MyTestNameSpace.MyEnum.Third).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(MyTestNameSpace.MyEnum.Fourth).AsSpan(), global::System.StringComparison.Ordinal) => true, + 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, _ => false, }; } @@ -152,35 +152,35 @@ namespace MyTestNameSpace /// /// Converts the string representation of the name or numeric value of - /// an to the equivalent instance. + /// an to the equivalent instance. /// The return value indicates whether the conversion succeeded. /// /// The case-sensitive string representation of the enumeration name or underlying value to convert /// When this method returns, contains an object of type - /// whose + /// whose /// value is represented by if the parse operation succeeds. /// If the parse operation fails, contains the default value of the underlying type - /// of . This parameter is passed uninitialized. + /// of . This parameter is passed uninitialized. /// true if the value parameter was converted successfully; otherwise, false. public static bool TryParse( #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif string? name, - out MyTestNameSpace.MyEnum value) + out global::MyTestNameSpace.MyEnum value) => TryParse(name, out value, false, false); /// /// Converts the string representation of the name or numeric value of - /// an to the equivalent instance. + /// an to the equivalent instance. /// The return value indicates whether the conversion succeeded. /// /// The string representation of the enumeration name or underlying value to convert /// When this method returns, contains an object of type - /// whose + /// whose /// value is represented by if the parse operation succeeds. /// If the parse operation fails, contains the default value of the underlying type - /// of . This parameter is passed uninitialized. + /// of . This parameter is passed uninitialized. /// true to read value in case insensitive mode; false to read value in case sensitive mode. /// true if the value parameter was converted successfully; otherwise, false. public static bool TryParse( @@ -188,21 +188,21 @@ namespace MyTestNameSpace [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif string? name, - out MyTestNameSpace.MyEnum value, + out global::MyTestNameSpace.MyEnum value, bool ignoreCase) => TryParse(name, out value, ignoreCase, false); /// /// Converts the string representation of the name or numeric value of - /// an to the equivalent instance. + /// an to the equivalent instance. /// The return value indicates whether the conversion succeeded. /// /// The string representation of the enumeration name or underlying value to convert /// When this method returns, contains an object of type - /// whose + /// whose /// value is represented by if the parse operation succeeds. /// If the parse operation fails, contains the default value of the underlying type - /// of . This parameter is passed uninitialized. + /// of . This parameter is passed uninitialized. /// true to read value in case insensitive mode; false to read value in case sensitive mode. /// If true, considers the value included in metadata attributes such as /// [Display] attribute when parsing, otherwise only considers the member names. @@ -212,7 +212,7 @@ namespace MyTestNameSpace [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif string? name, - out MyTestNameSpace.MyEnum value, + out global::MyTestNameSpace.MyEnum value, bool ignoreCase, bool allowMatchingMetadataAttribute) { @@ -223,10 +223,10 @@ namespace MyTestNameSpace switch (name) { case string s when s.Equals("2nd", global::System.StringComparison.OrdinalIgnoreCase): - value = MyTestNameSpace.MyEnum.Second; + value = global::MyTestNameSpace.MyEnum.Second; return true; case string s when s.Equals("4th", global::System.StringComparison.OrdinalIgnoreCase): - value = MyTestNameSpace.MyEnum.Fourth; + value = global::MyTestNameSpace.MyEnum.Fourth; return true; default: break; @@ -237,10 +237,10 @@ namespace MyTestNameSpace switch (name) { case "2nd": - value = MyTestNameSpace.MyEnum.Second; + value = global::MyTestNameSpace.MyEnum.Second; return true; case "4th": - value = MyTestNameSpace.MyEnum.Fourth; + value = global::MyTestNameSpace.MyEnum.Fourth; return true; default: break; @@ -252,20 +252,20 @@ namespace MyTestNameSpace { switch (name) { - case string s when s.Equals(nameof(MyTestNameSpace.MyEnum.First), global::System.StringComparison.OrdinalIgnoreCase): - value = MyTestNameSpace.MyEnum.First; + case string s when s.Equals(nameof(global::MyTestNameSpace.MyEnum.First), global::System.StringComparison.OrdinalIgnoreCase): + value = global::MyTestNameSpace.MyEnum.First; return true; - case string s when s.Equals(nameof(MyTestNameSpace.MyEnum.Second), global::System.StringComparison.OrdinalIgnoreCase): - value = MyTestNameSpace.MyEnum.Second; + case string s when s.Equals(nameof(global::MyTestNameSpace.MyEnum.Second), global::System.StringComparison.OrdinalIgnoreCase): + value = global::MyTestNameSpace.MyEnum.Second; return true; - case string s when s.Equals(nameof(MyTestNameSpace.MyEnum.Third), global::System.StringComparison.OrdinalIgnoreCase): - value = MyTestNameSpace.MyEnum.Third; + case string s when s.Equals(nameof(global::MyTestNameSpace.MyEnum.Third), global::System.StringComparison.OrdinalIgnoreCase): + value = global::MyTestNameSpace.MyEnum.Third; return true; - case string s when s.Equals(nameof(MyTestNameSpace.MyEnum.Fourth), global::System.StringComparison.OrdinalIgnoreCase): - value = MyTestNameSpace.MyEnum.Fourth; + case string s when s.Equals(nameof(global::MyTestNameSpace.MyEnum.Fourth), global::System.StringComparison.OrdinalIgnoreCase): + value = global::MyTestNameSpace.MyEnum.Fourth; return true; case string s when int.TryParse(name, out var val): - value = (MyTestNameSpace.MyEnum)val; + value = (global::MyTestNameSpace.MyEnum)val; return true; default: value = default; @@ -276,20 +276,20 @@ namespace MyTestNameSpace { switch (name) { - case nameof(MyTestNameSpace.MyEnum.First): - value = MyTestNameSpace.MyEnum.First; + case nameof(global::MyTestNameSpace.MyEnum.First): + value = global::MyTestNameSpace.MyEnum.First; return true; - case nameof(MyTestNameSpace.MyEnum.Second): - value = MyTestNameSpace.MyEnum.Second; + case nameof(global::MyTestNameSpace.MyEnum.Second): + value = global::MyTestNameSpace.MyEnum.Second; return true; - case nameof(MyTestNameSpace.MyEnum.Third): - value = MyTestNameSpace.MyEnum.Third; + case nameof(global::MyTestNameSpace.MyEnum.Third): + value = global::MyTestNameSpace.MyEnum.Third; return true; - case nameof(MyTestNameSpace.MyEnum.Fourth): - value = MyTestNameSpace.MyEnum.Fourth; + case nameof(global::MyTestNameSpace.MyEnum.Fourth): + value = global::MyTestNameSpace.MyEnum.Fourth; return true; case string s when int.TryParse(name, out var val): - value = (MyTestNameSpace.MyEnum)val; + value = (global::MyTestNameSpace.MyEnum)val; return true; default: value = default; @@ -301,35 +301,35 @@ namespace MyTestNameSpace #if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Converts the span representation of the name or numeric value of - /// an to the equivalent instance. + /// an to the equivalent instance. /// The return value indicates whether the conversion succeeded. /// /// The span representation of the enumeration name or underlying value to convert /// When this method returns, contains an object of type - /// whose + /// whose /// value is represented by if the parse operation succeeds. /// If the parse operation fails, contains the default value of the underlying type - /// of . This parameter is passed uninitialized. + /// of . This parameter is passed uninitialized. /// true if the value parameter was converted successfully; otherwise, false. public static bool TryParse( #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif in ReadOnlySpan name, - out MyTestNameSpace.MyEnum value) + out global::MyTestNameSpace.MyEnum value) => TryParse(name, out value, false, false); /// /// Converts the span representation of the name or numeric value of - /// an to the equivalent instance. + /// an to the equivalent instance. /// The return value indicates whether the conversion succeeded. /// /// The span representation of the enumeration name or underlying value to convert /// When this method returns, contains an object of type - /// whose + /// whose /// value is represented by if the parse operation succeeds. /// If the parse operation fails, contains the default value of the underlying type - /// of . This parameter is passed uninitialized. + /// of . This parameter is passed uninitialized. /// true to read value in case insensitive mode; false to read value in case sensitive mode. /// true if the value parameter was converted successfully; otherwise, false. public static bool TryParse( @@ -337,21 +337,21 @@ namespace MyTestNameSpace [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif in ReadOnlySpan name, - out MyTestNameSpace.MyEnum value, + out global::MyTestNameSpace.MyEnum value, bool ignoreCase) => TryParse(name, out value, ignoreCase, false); /// /// Converts the span representation of the name or numeric value of - /// an to the equivalent instance. + /// an to the equivalent instance. /// The return value indicates whether the conversion succeeded. /// /// The span representation of the enumeration name or underlying value to convert /// When this method returns, contains an object of type - /// whose + /// whose /// value is represented by if the parse operation succeeds. /// If the parse operation fails, contains the default value of the underlying type - /// of . This parameter is passed uninitialized. + /// of . This parameter is passed uninitialized. /// true to read value in case insensitive mode; false to read value in case sensitive mode. /// If true, considers the value included in metadata attributes such as /// [Display] attribute when parsing, otherwise only considers the member names. @@ -361,7 +361,7 @@ namespace MyTestNameSpace [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif in ReadOnlySpan name, - out MyTestNameSpace.MyEnum result, + out global::MyTestNameSpace.MyEnum result, bool ignoreCase, bool allowMatchingMetadataAttribute) { @@ -372,10 +372,10 @@ namespace MyTestNameSpace switch (name) { case ReadOnlySpan current when current.Equals("2nd".AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): - result = MyTestNameSpace.MyEnum.Second; + result = global::MyTestNameSpace.MyEnum.Second; return true; case ReadOnlySpan current when current.Equals("4th".AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): - result = MyTestNameSpace.MyEnum.Fourth; + result = global::MyTestNameSpace.MyEnum.Fourth; return true; default: break; @@ -386,10 +386,10 @@ namespace MyTestNameSpace switch (name) { case ReadOnlySpan current when current.Equals("2nd".AsSpan(), global::System.StringComparison.Ordinal): - result = MyTestNameSpace.MyEnum.Second; + result = global::MyTestNameSpace.MyEnum.Second; return true; case ReadOnlySpan current when current.Equals("4th".AsSpan(), global::System.StringComparison.Ordinal): - result = MyTestNameSpace.MyEnum.Fourth; + result = global::MyTestNameSpace.MyEnum.Fourth; return true; default: break; @@ -401,20 +401,20 @@ namespace MyTestNameSpace { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(MyTestNameSpace.MyEnum.First).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): - result = MyTestNameSpace.MyEnum.First; + case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.First).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + result = global::MyTestNameSpace.MyEnum.First; return true; - case ReadOnlySpan current when current.Equals(nameof(MyTestNameSpace.MyEnum.Second).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): - result = MyTestNameSpace.MyEnum.Second; + case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.Second).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + result = global::MyTestNameSpace.MyEnum.Second; return true; - case ReadOnlySpan current when current.Equals(nameof(MyTestNameSpace.MyEnum.Third).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): - result = MyTestNameSpace.MyEnum.Third; + case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.Third).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + result = global::MyTestNameSpace.MyEnum.Third; return true; - case ReadOnlySpan current when current.Equals(nameof(MyTestNameSpace.MyEnum.Fourth).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): - result = MyTestNameSpace.MyEnum.Fourth; + case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.Fourth).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + result = global::MyTestNameSpace.MyEnum.Fourth; return true; case ReadOnlySpan current when int.TryParse(name, out var numericResult): - result = (MyTestNameSpace.MyEnum)numericResult; + result = (global::MyTestNameSpace.MyEnum)numericResult; return true; default: result = default; @@ -425,20 +425,20 @@ namespace MyTestNameSpace { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(MyTestNameSpace.MyEnum.First).AsSpan(), global::System.StringComparison.Ordinal): - result = MyTestNameSpace.MyEnum.First; + case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.First).AsSpan(), global::System.StringComparison.Ordinal): + result = global::MyTestNameSpace.MyEnum.First; return true; - case ReadOnlySpan current when current.Equals(nameof(MyTestNameSpace.MyEnum.Second).AsSpan(), global::System.StringComparison.Ordinal): - result = MyTestNameSpace.MyEnum.Second; + case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.Second).AsSpan(), global::System.StringComparison.Ordinal): + result = global::MyTestNameSpace.MyEnum.Second; return true; - case ReadOnlySpan current when current.Equals(nameof(MyTestNameSpace.MyEnum.Third).AsSpan(), global::System.StringComparison.Ordinal): - result = MyTestNameSpace.MyEnum.Third; + case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.Third).AsSpan(), global::System.StringComparison.Ordinal): + result = global::MyTestNameSpace.MyEnum.Third; return true; - case ReadOnlySpan current when current.Equals(nameof(MyTestNameSpace.MyEnum.Fourth).AsSpan(), global::System.StringComparison.Ordinal): - result = MyTestNameSpace.MyEnum.Fourth; + case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.Fourth).AsSpan(), global::System.StringComparison.Ordinal): + result = global::MyTestNameSpace.MyEnum.Fourth; return true; case ReadOnlySpan current when int.TryParse(name, out var numericResult): - result = (MyTestNameSpace.MyEnum)numericResult; + result = (global::MyTestNameSpace.MyEnum)numericResult; return true; default: result = default; @@ -450,37 +450,37 @@ namespace MyTestNameSpace /// /// Retrieves an array of the values of the members defined in - /// . + /// . /// Note that this returns a new array with every invocation, so /// should be cached if appropriate. /// - /// An array of the values defined in - public static MyTestNameSpace.MyEnum[] GetValues() + /// An array of the values defined in + public static global::MyTestNameSpace.MyEnum[] GetValues() { return new[] { - MyTestNameSpace.MyEnum.First, - MyTestNameSpace.MyEnum.Second, - MyTestNameSpace.MyEnum.Third, - MyTestNameSpace.MyEnum.Fourth, + global::MyTestNameSpace.MyEnum.First, + global::MyTestNameSpace.MyEnum.Second, + global::MyTestNameSpace.MyEnum.Third, + global::MyTestNameSpace.MyEnum.Fourth, }; } /// /// Retrieves an array of the names of the members defined in - /// . + /// . /// Note that this returns a new array with every invocation, so /// should be cached if appropriate. /// - /// An array of the names of the members defined in + /// An array of the names of the members defined in public static string[] GetNames() { return new[] { - nameof(MyTestNameSpace.MyEnum.First), - nameof(MyTestNameSpace.MyEnum.Second), - nameof(MyTestNameSpace.MyEnum.Third), - nameof(MyTestNameSpace.MyEnum.Fourth), + nameof(global::MyTestNameSpace.MyEnum.First), + nameof(global::MyTestNameSpace.MyEnum.Second), + nameof(global::MyTestNameSpace.MyEnum.Third), + nameof(global::MyTestNameSpace.MyEnum.Fourth), }; } } diff --git a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsWithCustomNamespace.verified.txt b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsWithCustomNamespace.verified.txt index f934615..bc906d0 100644 --- a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsWithCustomNamespace.verified.txt +++ b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsWithCustomNamespace.verified.txt @@ -15,7 +15,7 @@ using System; namespace A.B { /// - /// Extension methods for + /// Extension methods for /// internal static partial class MyEnumExtensions { @@ -26,18 +26,18 @@ namespace A.B public const int Length = 2; /// - /// Returns the string representation of the value. + /// Returns the string representation of the value. /// If the attribute is decorated with a [Display] attribute, then /// uses the provided value. Otherwise uses the name of the member, equivalent to /// calling ToString() on . /// /// The value to retrieve the string value for /// The string representation of the value - public static string ToStringFast(this MyTestNameSpace.MyEnum value) + public static string ToStringFast(this global::MyTestNameSpace.MyEnum value) => value switch { - MyTestNameSpace.MyEnum.First => nameof(MyTestNameSpace.MyEnum.First), - MyTestNameSpace.MyEnum.Second => nameof(MyTestNameSpace.MyEnum.Second), + global::MyTestNameSpace.MyEnum.First => nameof(global::MyTestNameSpace.MyEnum.First), + global::MyTestNameSpace.MyEnum.Second => nameof(global::MyTestNameSpace.MyEnum.Second), _ => value.ToString(), }; @@ -46,11 +46,11 @@ namespace A.B /// /// The value to check if it's defined /// true if the value exists in the enumeration, false otherwise - public static bool IsDefined(MyTestNameSpace.MyEnum value) + public static bool IsDefined(global::MyTestNameSpace.MyEnum value) => value switch { - MyTestNameSpace.MyEnum.First => true, - MyTestNameSpace.MyEnum.Second => true, + global::MyTestNameSpace.MyEnum.First => true, + global::MyTestNameSpace.MyEnum.Second => true, _ => false, }; @@ -74,8 +74,8 @@ namespace A.B { return name switch { - nameof(MyTestNameSpace.MyEnum.First) => true, - nameof(MyTestNameSpace.MyEnum.Second) => true, + nameof(global::MyTestNameSpace.MyEnum.First) => true, + nameof(global::MyTestNameSpace.MyEnum.Second) => true, _ => false, }; } @@ -102,8 +102,8 @@ namespace A.B { return name switch { - ReadOnlySpan current when current.Equals(nameof(MyTestNameSpace.MyEnum.First).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(MyTestNameSpace.MyEnum.Second).AsSpan(), global::System.StringComparison.Ordinal) => true, + 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, _ => false, }; } @@ -111,35 +111,35 @@ namespace A.B /// /// Converts the string representation of the name or numeric value of - /// an to the equivalent instance. + /// an to the equivalent instance. /// The return value indicates whether the conversion succeeded. /// /// The case-sensitive string representation of the enumeration name or underlying value to convert /// When this method returns, contains an object of type - /// whose + /// whose /// value is represented by if the parse operation succeeds. /// If the parse operation fails, contains the default value of the underlying type - /// of . This parameter is passed uninitialized. + /// of . This parameter is passed uninitialized. /// true if the value parameter was converted successfully; otherwise, false. public static bool TryParse( #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif string? name, - out MyTestNameSpace.MyEnum value) + out global::MyTestNameSpace.MyEnum value) => TryParse(name, out value, false, false); /// /// Converts the string representation of the name or numeric value of - /// an to the equivalent instance. + /// an to the equivalent instance. /// The return value indicates whether the conversion succeeded. /// /// The string representation of the enumeration name or underlying value to convert /// When this method returns, contains an object of type - /// whose + /// whose /// value is represented by if the parse operation succeeds. /// If the parse operation fails, contains the default value of the underlying type - /// of . This parameter is passed uninitialized. + /// of . This parameter is passed uninitialized. /// true to read value in case insensitive mode; false to read value in case sensitive mode. /// true if the value parameter was converted successfully; otherwise, false. public static bool TryParse( @@ -147,21 +147,21 @@ namespace A.B [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif string? name, - out MyTestNameSpace.MyEnum value, + out global::MyTestNameSpace.MyEnum value, bool ignoreCase) => TryParse(name, out value, ignoreCase, false); /// /// Converts the string representation of the name or numeric value of - /// an to the equivalent instance. + /// an to the equivalent instance. /// The return value indicates whether the conversion succeeded. /// /// The string representation of the enumeration name or underlying value to convert /// When this method returns, contains an object of type - /// whose + /// whose /// value is represented by if the parse operation succeeds. /// If the parse operation fails, contains the default value of the underlying type - /// of . This parameter is passed uninitialized. + /// of . This parameter is passed uninitialized. /// true to read value in case insensitive mode; false to read value in case sensitive mode. /// If true, considers the value included in metadata attributes such as /// [Display] attribute when parsing, otherwise only considers the member names. @@ -171,7 +171,7 @@ namespace A.B [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif string? name, - out MyTestNameSpace.MyEnum value, + out global::MyTestNameSpace.MyEnum value, bool ignoreCase, bool allowMatchingMetadataAttribute) { @@ -179,14 +179,14 @@ namespace A.B { switch (name) { - case string s when s.Equals(nameof(MyTestNameSpace.MyEnum.First), global::System.StringComparison.OrdinalIgnoreCase): - value = MyTestNameSpace.MyEnum.First; + case string s when s.Equals(nameof(global::MyTestNameSpace.MyEnum.First), global::System.StringComparison.OrdinalIgnoreCase): + value = global::MyTestNameSpace.MyEnum.First; return true; - case string s when s.Equals(nameof(MyTestNameSpace.MyEnum.Second), global::System.StringComparison.OrdinalIgnoreCase): - value = MyTestNameSpace.MyEnum.Second; + case string s when s.Equals(nameof(global::MyTestNameSpace.MyEnum.Second), global::System.StringComparison.OrdinalIgnoreCase): + value = global::MyTestNameSpace.MyEnum.Second; return true; case string s when int.TryParse(name, out var val): - value = (MyTestNameSpace.MyEnum)val; + value = (global::MyTestNameSpace.MyEnum)val; return true; default: value = default; @@ -197,14 +197,14 @@ namespace A.B { switch (name) { - case nameof(MyTestNameSpace.MyEnum.First): - value = MyTestNameSpace.MyEnum.First; + case nameof(global::MyTestNameSpace.MyEnum.First): + value = global::MyTestNameSpace.MyEnum.First; return true; - case nameof(MyTestNameSpace.MyEnum.Second): - value = MyTestNameSpace.MyEnum.Second; + case nameof(global::MyTestNameSpace.MyEnum.Second): + value = global::MyTestNameSpace.MyEnum.Second; return true; case string s when int.TryParse(name, out var val): - value = (MyTestNameSpace.MyEnum)val; + value = (global::MyTestNameSpace.MyEnum)val; return true; default: value = default; @@ -216,35 +216,35 @@ namespace A.B #if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Converts the span representation of the name or numeric value of - /// an to the equivalent instance. + /// an to the equivalent instance. /// The return value indicates whether the conversion succeeded. /// /// The span representation of the enumeration name or underlying value to convert /// When this method returns, contains an object of type - /// whose + /// whose /// value is represented by if the parse operation succeeds. /// If the parse operation fails, contains the default value of the underlying type - /// of . This parameter is passed uninitialized. + /// of . This parameter is passed uninitialized. /// true if the value parameter was converted successfully; otherwise, false. public static bool TryParse( #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif in ReadOnlySpan name, - out MyTestNameSpace.MyEnum value) + out global::MyTestNameSpace.MyEnum value) => TryParse(name, out value, false, false); /// /// Converts the span representation of the name or numeric value of - /// an to the equivalent instance. + /// an to the equivalent instance. /// The return value indicates whether the conversion succeeded. /// /// The span representation of the enumeration name or underlying value to convert /// When this method returns, contains an object of type - /// whose + /// whose /// value is represented by if the parse operation succeeds. /// If the parse operation fails, contains the default value of the underlying type - /// of . This parameter is passed uninitialized. + /// of . This parameter is passed uninitialized. /// true to read value in case insensitive mode; false to read value in case sensitive mode. /// true if the value parameter was converted successfully; otherwise, false. public static bool TryParse( @@ -252,21 +252,21 @@ namespace A.B [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif in ReadOnlySpan name, - out MyTestNameSpace.MyEnum value, + out global::MyTestNameSpace.MyEnum value, bool ignoreCase) => TryParse(name, out value, ignoreCase, false); /// /// Converts the span representation of the name or numeric value of - /// an to the equivalent instance. + /// an to the equivalent instance. /// The return value indicates whether the conversion succeeded. /// /// The span representation of the enumeration name or underlying value to convert /// When this method returns, contains an object of type - /// whose + /// whose /// value is represented by if the parse operation succeeds. /// If the parse operation fails, contains the default value of the underlying type - /// of . This parameter is passed uninitialized. + /// of . This parameter is passed uninitialized. /// true to read value in case insensitive mode; false to read value in case sensitive mode. /// If true, considers the value included in metadata attributes such as /// [Display] attribute when parsing, otherwise only considers the member names. @@ -276,7 +276,7 @@ namespace A.B [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif in ReadOnlySpan name, - out MyTestNameSpace.MyEnum result, + out global::MyTestNameSpace.MyEnum result, bool ignoreCase, bool allowMatchingMetadataAttribute) { @@ -284,14 +284,14 @@ namespace A.B { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(MyTestNameSpace.MyEnum.First).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): - result = MyTestNameSpace.MyEnum.First; + case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.First).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + result = global::MyTestNameSpace.MyEnum.First; return true; - case ReadOnlySpan current when current.Equals(nameof(MyTestNameSpace.MyEnum.Second).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): - result = MyTestNameSpace.MyEnum.Second; + case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.Second).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + result = global::MyTestNameSpace.MyEnum.Second; return true; case ReadOnlySpan current when int.TryParse(name, out var numericResult): - result = (MyTestNameSpace.MyEnum)numericResult; + result = (global::MyTestNameSpace.MyEnum)numericResult; return true; default: result = default; @@ -302,14 +302,14 @@ namespace A.B { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(MyTestNameSpace.MyEnum.First).AsSpan(), global::System.StringComparison.Ordinal): - result = MyTestNameSpace.MyEnum.First; + case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.First).AsSpan(), global::System.StringComparison.Ordinal): + result = global::MyTestNameSpace.MyEnum.First; return true; - case ReadOnlySpan current when current.Equals(nameof(MyTestNameSpace.MyEnum.Second).AsSpan(), global::System.StringComparison.Ordinal): - result = MyTestNameSpace.MyEnum.Second; + case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.Second).AsSpan(), global::System.StringComparison.Ordinal): + result = global::MyTestNameSpace.MyEnum.Second; return true; case ReadOnlySpan current when int.TryParse(name, out var numericResult): - result = (MyTestNameSpace.MyEnum)numericResult; + result = (global::MyTestNameSpace.MyEnum)numericResult; return true; default: result = default; @@ -321,33 +321,33 @@ namespace A.B /// /// Retrieves an array of the values of the members defined in - /// . + /// . /// Note that this returns a new array with every invocation, so /// should be cached if appropriate. /// - /// An array of the values defined in - public static MyTestNameSpace.MyEnum[] GetValues() + /// An array of the values defined in + public static global::MyTestNameSpace.MyEnum[] GetValues() { return new[] { - MyTestNameSpace.MyEnum.First, - MyTestNameSpace.MyEnum.Second, + global::MyTestNameSpace.MyEnum.First, + global::MyTestNameSpace.MyEnum.Second, }; } /// /// Retrieves an array of the names of the members defined in - /// . + /// . /// Note that this returns a new array with every invocation, so /// should be cached if appropriate. /// - /// An array of the names of the members defined in + /// An array of the names of the members defined in public static string[] GetNames() { return new[] { - nameof(MyTestNameSpace.MyEnum.First), - nameof(MyTestNameSpace.MyEnum.Second), + nameof(global::MyTestNameSpace.MyEnum.First), + nameof(global::MyTestNameSpace.MyEnum.Second), }; } } diff --git a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsWithCustomNamespaceAndName.verified.txt b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsWithCustomNamespaceAndName.verified.txt index b93a3ec..fe92b06 100644 --- a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsWithCustomNamespaceAndName.verified.txt +++ b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsWithCustomNamespaceAndName.verified.txt @@ -15,7 +15,7 @@ using System; namespace A.B { /// - /// Extension methods for + /// Extension methods for /// internal static partial class C { @@ -26,18 +26,18 @@ namespace A.B public const int Length = 2; /// - /// Returns the string representation of the value. + /// Returns the string representation of the value. /// If the attribute is decorated with a [Display] attribute, then /// uses the provided value. Otherwise uses the name of the member, equivalent to /// calling ToString() on . /// /// The value to retrieve the string value for /// The string representation of the value - public static string ToStringFast(this MyTestNameSpace.MyEnum value) + public static string ToStringFast(this global::MyTestNameSpace.MyEnum value) => value switch { - MyTestNameSpace.MyEnum.First => nameof(MyTestNameSpace.MyEnum.First), - MyTestNameSpace.MyEnum.Second => nameof(MyTestNameSpace.MyEnum.Second), + global::MyTestNameSpace.MyEnum.First => nameof(global::MyTestNameSpace.MyEnum.First), + global::MyTestNameSpace.MyEnum.Second => nameof(global::MyTestNameSpace.MyEnum.Second), _ => value.ToString(), }; @@ -46,11 +46,11 @@ namespace A.B /// /// The value to check if it's defined /// true if the value exists in the enumeration, false otherwise - public static bool IsDefined(MyTestNameSpace.MyEnum value) + public static bool IsDefined(global::MyTestNameSpace.MyEnum value) => value switch { - MyTestNameSpace.MyEnum.First => true, - MyTestNameSpace.MyEnum.Second => true, + global::MyTestNameSpace.MyEnum.First => true, + global::MyTestNameSpace.MyEnum.Second => true, _ => false, }; @@ -74,8 +74,8 @@ namespace A.B { return name switch { - nameof(MyTestNameSpace.MyEnum.First) => true, - nameof(MyTestNameSpace.MyEnum.Second) => true, + nameof(global::MyTestNameSpace.MyEnum.First) => true, + nameof(global::MyTestNameSpace.MyEnum.Second) => true, _ => false, }; } @@ -102,8 +102,8 @@ namespace A.B { return name switch { - ReadOnlySpan current when current.Equals(nameof(MyTestNameSpace.MyEnum.First).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(MyTestNameSpace.MyEnum.Second).AsSpan(), global::System.StringComparison.Ordinal) => true, + 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, _ => false, }; } @@ -111,35 +111,35 @@ namespace A.B /// /// Converts the string representation of the name or numeric value of - /// an to the equivalent instance. + /// an to the equivalent instance. /// The return value indicates whether the conversion succeeded. /// /// The case-sensitive string representation of the enumeration name or underlying value to convert /// When this method returns, contains an object of type - /// whose + /// whose /// value is represented by if the parse operation succeeds. /// If the parse operation fails, contains the default value of the underlying type - /// of . This parameter is passed uninitialized. + /// of . This parameter is passed uninitialized. /// true if the value parameter was converted successfully; otherwise, false. public static bool TryParse( #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif string? name, - out MyTestNameSpace.MyEnum value) + out global::MyTestNameSpace.MyEnum value) => TryParse(name, out value, false, false); /// /// Converts the string representation of the name or numeric value of - /// an to the equivalent instance. + /// an to the equivalent instance. /// The return value indicates whether the conversion succeeded. /// /// The string representation of the enumeration name or underlying value to convert /// When this method returns, contains an object of type - /// whose + /// whose /// value is represented by if the parse operation succeeds. /// If the parse operation fails, contains the default value of the underlying type - /// of . This parameter is passed uninitialized. + /// of . This parameter is passed uninitialized. /// true to read value in case insensitive mode; false to read value in case sensitive mode. /// true if the value parameter was converted successfully; otherwise, false. public static bool TryParse( @@ -147,21 +147,21 @@ namespace A.B [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif string? name, - out MyTestNameSpace.MyEnum value, + out global::MyTestNameSpace.MyEnum value, bool ignoreCase) => TryParse(name, out value, ignoreCase, false); /// /// Converts the string representation of the name or numeric value of - /// an to the equivalent instance. + /// an to the equivalent instance. /// The return value indicates whether the conversion succeeded. /// /// The string representation of the enumeration name or underlying value to convert /// When this method returns, contains an object of type - /// whose + /// whose /// value is represented by if the parse operation succeeds. /// If the parse operation fails, contains the default value of the underlying type - /// of . This parameter is passed uninitialized. + /// of . This parameter is passed uninitialized. /// true to read value in case insensitive mode; false to read value in case sensitive mode. /// If true, considers the value included in metadata attributes such as /// [Display] attribute when parsing, otherwise only considers the member names. @@ -171,7 +171,7 @@ namespace A.B [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif string? name, - out MyTestNameSpace.MyEnum value, + out global::MyTestNameSpace.MyEnum value, bool ignoreCase, bool allowMatchingMetadataAttribute) { @@ -179,14 +179,14 @@ namespace A.B { switch (name) { - case string s when s.Equals(nameof(MyTestNameSpace.MyEnum.First), global::System.StringComparison.OrdinalIgnoreCase): - value = MyTestNameSpace.MyEnum.First; + case string s when s.Equals(nameof(global::MyTestNameSpace.MyEnum.First), global::System.StringComparison.OrdinalIgnoreCase): + value = global::MyTestNameSpace.MyEnum.First; return true; - case string s when s.Equals(nameof(MyTestNameSpace.MyEnum.Second), global::System.StringComparison.OrdinalIgnoreCase): - value = MyTestNameSpace.MyEnum.Second; + case string s when s.Equals(nameof(global::MyTestNameSpace.MyEnum.Second), global::System.StringComparison.OrdinalIgnoreCase): + value = global::MyTestNameSpace.MyEnum.Second; return true; case string s when int.TryParse(name, out var val): - value = (MyTestNameSpace.MyEnum)val; + value = (global::MyTestNameSpace.MyEnum)val; return true; default: value = default; @@ -197,14 +197,14 @@ namespace A.B { switch (name) { - case nameof(MyTestNameSpace.MyEnum.First): - value = MyTestNameSpace.MyEnum.First; + case nameof(global::MyTestNameSpace.MyEnum.First): + value = global::MyTestNameSpace.MyEnum.First; return true; - case nameof(MyTestNameSpace.MyEnum.Second): - value = MyTestNameSpace.MyEnum.Second; + case nameof(global::MyTestNameSpace.MyEnum.Second): + value = global::MyTestNameSpace.MyEnum.Second; return true; case string s when int.TryParse(name, out var val): - value = (MyTestNameSpace.MyEnum)val; + value = (global::MyTestNameSpace.MyEnum)val; return true; default: value = default; @@ -216,35 +216,35 @@ namespace A.B #if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Converts the span representation of the name or numeric value of - /// an to the equivalent instance. + /// an to the equivalent instance. /// The return value indicates whether the conversion succeeded. /// /// The span representation of the enumeration name or underlying value to convert /// When this method returns, contains an object of type - /// whose + /// whose /// value is represented by if the parse operation succeeds. /// If the parse operation fails, contains the default value of the underlying type - /// of . This parameter is passed uninitialized. + /// of . This parameter is passed uninitialized. /// true if the value parameter was converted successfully; otherwise, false. public static bool TryParse( #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif in ReadOnlySpan name, - out MyTestNameSpace.MyEnum value) + out global::MyTestNameSpace.MyEnum value) => TryParse(name, out value, false, false); /// /// Converts the span representation of the name or numeric value of - /// an to the equivalent instance. + /// an to the equivalent instance. /// The return value indicates whether the conversion succeeded. /// /// The span representation of the enumeration name or underlying value to convert /// When this method returns, contains an object of type - /// whose + /// whose /// value is represented by if the parse operation succeeds. /// If the parse operation fails, contains the default value of the underlying type - /// of . This parameter is passed uninitialized. + /// of . This parameter is passed uninitialized. /// true to read value in case insensitive mode; false to read value in case sensitive mode. /// true if the value parameter was converted successfully; otherwise, false. public static bool TryParse( @@ -252,21 +252,21 @@ namespace A.B [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif in ReadOnlySpan name, - out MyTestNameSpace.MyEnum value, + out global::MyTestNameSpace.MyEnum value, bool ignoreCase) => TryParse(name, out value, ignoreCase, false); /// /// Converts the span representation of the name or numeric value of - /// an to the equivalent instance. + /// an to the equivalent instance. /// The return value indicates whether the conversion succeeded. /// /// The span representation of the enumeration name or underlying value to convert /// When this method returns, contains an object of type - /// whose + /// whose /// value is represented by if the parse operation succeeds. /// If the parse operation fails, contains the default value of the underlying type - /// of . This parameter is passed uninitialized. + /// of . This parameter is passed uninitialized. /// true to read value in case insensitive mode; false to read value in case sensitive mode. /// If true, considers the value included in metadata attributes such as /// [Display] attribute when parsing, otherwise only considers the member names. @@ -276,7 +276,7 @@ namespace A.B [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif in ReadOnlySpan name, - out MyTestNameSpace.MyEnum result, + out global::MyTestNameSpace.MyEnum result, bool ignoreCase, bool allowMatchingMetadataAttribute) { @@ -284,14 +284,14 @@ namespace A.B { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(MyTestNameSpace.MyEnum.First).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): - result = MyTestNameSpace.MyEnum.First; + case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.First).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + result = global::MyTestNameSpace.MyEnum.First; return true; - case ReadOnlySpan current when current.Equals(nameof(MyTestNameSpace.MyEnum.Second).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): - result = MyTestNameSpace.MyEnum.Second; + case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.Second).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + result = global::MyTestNameSpace.MyEnum.Second; return true; case ReadOnlySpan current when int.TryParse(name, out var numericResult): - result = (MyTestNameSpace.MyEnum)numericResult; + result = (global::MyTestNameSpace.MyEnum)numericResult; return true; default: result = default; @@ -302,14 +302,14 @@ namespace A.B { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(MyTestNameSpace.MyEnum.First).AsSpan(), global::System.StringComparison.Ordinal): - result = MyTestNameSpace.MyEnum.First; + case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.First).AsSpan(), global::System.StringComparison.Ordinal): + result = global::MyTestNameSpace.MyEnum.First; return true; - case ReadOnlySpan current when current.Equals(nameof(MyTestNameSpace.MyEnum.Second).AsSpan(), global::System.StringComparison.Ordinal): - result = MyTestNameSpace.MyEnum.Second; + case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.Second).AsSpan(), global::System.StringComparison.Ordinal): + result = global::MyTestNameSpace.MyEnum.Second; return true; case ReadOnlySpan current when int.TryParse(name, out var numericResult): - result = (MyTestNameSpace.MyEnum)numericResult; + result = (global::MyTestNameSpace.MyEnum)numericResult; return true; default: result = default; @@ -321,33 +321,33 @@ namespace A.B /// /// Retrieves an array of the values of the members defined in - /// . + /// . /// Note that this returns a new array with every invocation, so /// should be cached if appropriate. /// - /// An array of the values defined in - public static MyTestNameSpace.MyEnum[] GetValues() + /// An array of the values defined in + public static global::MyTestNameSpace.MyEnum[] GetValues() { return new[] { - MyTestNameSpace.MyEnum.First, - MyTestNameSpace.MyEnum.Second, + global::MyTestNameSpace.MyEnum.First, + global::MyTestNameSpace.MyEnum.Second, }; } /// /// Retrieves an array of the names of the members defined in - /// . + /// . /// Note that this returns a new array with every invocation, so /// should be cached if appropriate. /// - /// An array of the names of the members defined in + /// An array of the names of the members defined in public static string[] GetNames() { return new[] { - nameof(MyTestNameSpace.MyEnum.First), - nameof(MyTestNameSpace.MyEnum.Second), + nameof(global::MyTestNameSpace.MyEnum.First), + nameof(global::MyTestNameSpace.MyEnum.Second), }; } } diff --git a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsWithSameDisplayName.verified.txt b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsWithSameDisplayName.verified.txt index 179d252..dfadd01 100644 --- a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsWithSameDisplayName.verified.txt +++ b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsWithSameDisplayName.verified.txt @@ -15,7 +15,7 @@ using System; namespace MyTestNameSpace { /// - /// Extension methods for + /// Extension methods for /// public static partial class MyEnumExtensions { @@ -26,20 +26,20 @@ namespace MyTestNameSpace public const int Length = 4; /// - /// Returns the string representation of the value. + /// Returns the string representation of the value. /// If the attribute is decorated with a [Display] attribute, then /// uses the provided value. Otherwise uses the name of the member, equivalent to /// calling ToString() on . /// /// The value to retrieve the string value for /// The string representation of the value - public static string ToStringFast(this MyTestNameSpace.MyEnum value) + public static string ToStringFast(this global::MyTestNameSpace.MyEnum value) => value switch { - MyTestNameSpace.MyEnum.First => nameof(MyTestNameSpace.MyEnum.First), - MyTestNameSpace.MyEnum.Second => "2nd", - MyTestNameSpace.MyEnum.Third => nameof(MyTestNameSpace.MyEnum.Third), - MyTestNameSpace.MyEnum.Fourth => "2nd", + global::MyTestNameSpace.MyEnum.First => nameof(global::MyTestNameSpace.MyEnum.First), + global::MyTestNameSpace.MyEnum.Second => "2nd", + global::MyTestNameSpace.MyEnum.Third => nameof(global::MyTestNameSpace.MyEnum.Third), + global::MyTestNameSpace.MyEnum.Fourth => "2nd", _ => value.ToString(), }; @@ -48,13 +48,13 @@ namespace MyTestNameSpace /// /// The value to check if it's defined /// true if the value exists in the enumeration, false otherwise - public static bool IsDefined(MyTestNameSpace.MyEnum value) + public static bool IsDefined(global::MyTestNameSpace.MyEnum value) => value switch { - MyTestNameSpace.MyEnum.First => true, - MyTestNameSpace.MyEnum.Second => true, - MyTestNameSpace.MyEnum.Third => true, - MyTestNameSpace.MyEnum.Fourth => true, + global::MyTestNameSpace.MyEnum.First => true, + global::MyTestNameSpace.MyEnum.Second => true, + global::MyTestNameSpace.MyEnum.Third => true, + global::MyTestNameSpace.MyEnum.Fourth => true, _ => false, }; @@ -94,10 +94,10 @@ namespace MyTestNameSpace return name switch { - nameof(MyTestNameSpace.MyEnum.First) => true, - nameof(MyTestNameSpace.MyEnum.Second) => true, - nameof(MyTestNameSpace.MyEnum.Third) => true, - nameof(MyTestNameSpace.MyEnum.Fourth) => true, + nameof(global::MyTestNameSpace.MyEnum.First) => true, + nameof(global::MyTestNameSpace.MyEnum.Second) => true, + nameof(global::MyTestNameSpace.MyEnum.Third) => true, + nameof(global::MyTestNameSpace.MyEnum.Fourth) => true, _ => false, }; } @@ -139,10 +139,10 @@ namespace MyTestNameSpace return name switch { - ReadOnlySpan current when current.Equals(nameof(MyTestNameSpace.MyEnum.First).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(MyTestNameSpace.MyEnum.Second).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(MyTestNameSpace.MyEnum.Third).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(MyTestNameSpace.MyEnum.Fourth).AsSpan(), global::System.StringComparison.Ordinal) => true, + 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, _ => false, }; } @@ -150,35 +150,35 @@ namespace MyTestNameSpace /// /// Converts the string representation of the name or numeric value of - /// an to the equivalent instance. + /// an to the equivalent instance. /// The return value indicates whether the conversion succeeded. /// /// The case-sensitive string representation of the enumeration name or underlying value to convert /// When this method returns, contains an object of type - /// whose + /// whose /// value is represented by if the parse operation succeeds. /// If the parse operation fails, contains the default value of the underlying type - /// of . This parameter is passed uninitialized. + /// of . This parameter is passed uninitialized. /// true if the value parameter was converted successfully; otherwise, false. public static bool TryParse( #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif string? name, - out MyTestNameSpace.MyEnum value) + out global::MyTestNameSpace.MyEnum value) => TryParse(name, out value, false, false); /// /// Converts the string representation of the name or numeric value of - /// an to the equivalent instance. + /// an to the equivalent instance. /// The return value indicates whether the conversion succeeded. /// /// The string representation of the enumeration name or underlying value to convert /// When this method returns, contains an object of type - /// whose + /// whose /// value is represented by if the parse operation succeeds. /// If the parse operation fails, contains the default value of the underlying type - /// of . This parameter is passed uninitialized. + /// of . This parameter is passed uninitialized. /// true to read value in case insensitive mode; false to read value in case sensitive mode. /// true if the value parameter was converted successfully; otherwise, false. public static bool TryParse( @@ -186,21 +186,21 @@ namespace MyTestNameSpace [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif string? name, - out MyTestNameSpace.MyEnum value, + out global::MyTestNameSpace.MyEnum value, bool ignoreCase) => TryParse(name, out value, ignoreCase, false); /// /// Converts the string representation of the name or numeric value of - /// an to the equivalent instance. + /// an to the equivalent instance. /// The return value indicates whether the conversion succeeded. /// /// The string representation of the enumeration name or underlying value to convert /// When this method returns, contains an object of type - /// whose + /// whose /// value is represented by if the parse operation succeeds. /// If the parse operation fails, contains the default value of the underlying type - /// of . This parameter is passed uninitialized. + /// of . This parameter is passed uninitialized. /// true to read value in case insensitive mode; false to read value in case sensitive mode. /// If true, considers the value included in metadata attributes such as /// [Display] attribute when parsing, otherwise only considers the member names. @@ -210,7 +210,7 @@ namespace MyTestNameSpace [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif string? name, - out MyTestNameSpace.MyEnum value, + out global::MyTestNameSpace.MyEnum value, bool ignoreCase, bool allowMatchingMetadataAttribute) { @@ -221,7 +221,7 @@ namespace MyTestNameSpace switch (name) { case string s when s.Equals("2nd", global::System.StringComparison.OrdinalIgnoreCase): - value = MyTestNameSpace.MyEnum.Second; + value = global::MyTestNameSpace.MyEnum.Second; return true; default: break; @@ -232,7 +232,7 @@ namespace MyTestNameSpace switch (name) { case "2nd": - value = MyTestNameSpace.MyEnum.Second; + value = global::MyTestNameSpace.MyEnum.Second; return true; default: break; @@ -244,20 +244,20 @@ namespace MyTestNameSpace { switch (name) { - case string s when s.Equals(nameof(MyTestNameSpace.MyEnum.First), global::System.StringComparison.OrdinalIgnoreCase): - value = MyTestNameSpace.MyEnum.First; + case string s when s.Equals(nameof(global::MyTestNameSpace.MyEnum.First), global::System.StringComparison.OrdinalIgnoreCase): + value = global::MyTestNameSpace.MyEnum.First; return true; - case string s when s.Equals(nameof(MyTestNameSpace.MyEnum.Second), global::System.StringComparison.OrdinalIgnoreCase): - value = MyTestNameSpace.MyEnum.Second; + case string s when s.Equals(nameof(global::MyTestNameSpace.MyEnum.Second), global::System.StringComparison.OrdinalIgnoreCase): + value = global::MyTestNameSpace.MyEnum.Second; return true; - case string s when s.Equals(nameof(MyTestNameSpace.MyEnum.Third), global::System.StringComparison.OrdinalIgnoreCase): - value = MyTestNameSpace.MyEnum.Third; + case string s when s.Equals(nameof(global::MyTestNameSpace.MyEnum.Third), global::System.StringComparison.OrdinalIgnoreCase): + value = global::MyTestNameSpace.MyEnum.Third; return true; - case string s when s.Equals(nameof(MyTestNameSpace.MyEnum.Fourth), global::System.StringComparison.OrdinalIgnoreCase): - value = MyTestNameSpace.MyEnum.Fourth; + case string s when s.Equals(nameof(global::MyTestNameSpace.MyEnum.Fourth), global::System.StringComparison.OrdinalIgnoreCase): + value = global::MyTestNameSpace.MyEnum.Fourth; return true; case string s when int.TryParse(name, out var val): - value = (MyTestNameSpace.MyEnum)val; + value = (global::MyTestNameSpace.MyEnum)val; return true; default: value = default; @@ -268,20 +268,20 @@ namespace MyTestNameSpace { switch (name) { - case nameof(MyTestNameSpace.MyEnum.First): - value = MyTestNameSpace.MyEnum.First; + case nameof(global::MyTestNameSpace.MyEnum.First): + value = global::MyTestNameSpace.MyEnum.First; return true; - case nameof(MyTestNameSpace.MyEnum.Second): - value = MyTestNameSpace.MyEnum.Second; + case nameof(global::MyTestNameSpace.MyEnum.Second): + value = global::MyTestNameSpace.MyEnum.Second; return true; - case nameof(MyTestNameSpace.MyEnum.Third): - value = MyTestNameSpace.MyEnum.Third; + case nameof(global::MyTestNameSpace.MyEnum.Third): + value = global::MyTestNameSpace.MyEnum.Third; return true; - case nameof(MyTestNameSpace.MyEnum.Fourth): - value = MyTestNameSpace.MyEnum.Fourth; + case nameof(global::MyTestNameSpace.MyEnum.Fourth): + value = global::MyTestNameSpace.MyEnum.Fourth; return true; case string s when int.TryParse(name, out var val): - value = (MyTestNameSpace.MyEnum)val; + value = (global::MyTestNameSpace.MyEnum)val; return true; default: value = default; @@ -293,35 +293,35 @@ namespace MyTestNameSpace #if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Converts the span representation of the name or numeric value of - /// an to the equivalent instance. + /// an to the equivalent instance. /// The return value indicates whether the conversion succeeded. /// /// The span representation of the enumeration name or underlying value to convert /// When this method returns, contains an object of type - /// whose + /// whose /// value is represented by if the parse operation succeeds. /// If the parse operation fails, contains the default value of the underlying type - /// of . This parameter is passed uninitialized. + /// of . This parameter is passed uninitialized. /// true if the value parameter was converted successfully; otherwise, false. public static bool TryParse( #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif in ReadOnlySpan name, - out MyTestNameSpace.MyEnum value) + out global::MyTestNameSpace.MyEnum value) => TryParse(name, out value, false, false); /// /// Converts the span representation of the name or numeric value of - /// an to the equivalent instance. + /// an to the equivalent instance. /// The return value indicates whether the conversion succeeded. /// /// The span representation of the enumeration name or underlying value to convert /// When this method returns, contains an object of type - /// whose + /// whose /// value is represented by if the parse operation succeeds. /// If the parse operation fails, contains the default value of the underlying type - /// of . This parameter is passed uninitialized. + /// of . This parameter is passed uninitialized. /// true to read value in case insensitive mode; false to read value in case sensitive mode. /// true if the value parameter was converted successfully; otherwise, false. public static bool TryParse( @@ -329,21 +329,21 @@ namespace MyTestNameSpace [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif in ReadOnlySpan name, - out MyTestNameSpace.MyEnum value, + out global::MyTestNameSpace.MyEnum value, bool ignoreCase) => TryParse(name, out value, ignoreCase, false); /// /// Converts the span representation of the name or numeric value of - /// an to the equivalent instance. + /// an to the equivalent instance. /// The return value indicates whether the conversion succeeded. /// /// The span representation of the enumeration name or underlying value to convert /// When this method returns, contains an object of type - /// whose + /// whose /// value is represented by if the parse operation succeeds. /// If the parse operation fails, contains the default value of the underlying type - /// of . This parameter is passed uninitialized. + /// of . This parameter is passed uninitialized. /// true to read value in case insensitive mode; false to read value in case sensitive mode. /// If true, considers the value included in metadata attributes such as /// [Display] attribute when parsing, otherwise only considers the member names. @@ -353,7 +353,7 @@ namespace MyTestNameSpace [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif in ReadOnlySpan name, - out MyTestNameSpace.MyEnum result, + out global::MyTestNameSpace.MyEnum result, bool ignoreCase, bool allowMatchingMetadataAttribute) { @@ -364,7 +364,7 @@ namespace MyTestNameSpace switch (name) { case ReadOnlySpan current when current.Equals("2nd".AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): - result = MyTestNameSpace.MyEnum.Second; + result = global::MyTestNameSpace.MyEnum.Second; return true; default: break; @@ -375,7 +375,7 @@ namespace MyTestNameSpace switch (name) { case ReadOnlySpan current when current.Equals("2nd".AsSpan(), global::System.StringComparison.Ordinal): - result = MyTestNameSpace.MyEnum.Second; + result = global::MyTestNameSpace.MyEnum.Second; return true; default: break; @@ -387,20 +387,20 @@ namespace MyTestNameSpace { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(MyTestNameSpace.MyEnum.First).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): - result = MyTestNameSpace.MyEnum.First; + case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.First).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + result = global::MyTestNameSpace.MyEnum.First; return true; - case ReadOnlySpan current when current.Equals(nameof(MyTestNameSpace.MyEnum.Second).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): - result = MyTestNameSpace.MyEnum.Second; + case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.Second).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + result = global::MyTestNameSpace.MyEnum.Second; return true; - case ReadOnlySpan current when current.Equals(nameof(MyTestNameSpace.MyEnum.Third).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): - result = MyTestNameSpace.MyEnum.Third; + case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.Third).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + result = global::MyTestNameSpace.MyEnum.Third; return true; - case ReadOnlySpan current when current.Equals(nameof(MyTestNameSpace.MyEnum.Fourth).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): - result = MyTestNameSpace.MyEnum.Fourth; + case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.Fourth).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + result = global::MyTestNameSpace.MyEnum.Fourth; return true; case ReadOnlySpan current when int.TryParse(name, out var numericResult): - result = (MyTestNameSpace.MyEnum)numericResult; + result = (global::MyTestNameSpace.MyEnum)numericResult; return true; default: result = default; @@ -411,20 +411,20 @@ namespace MyTestNameSpace { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(MyTestNameSpace.MyEnum.First).AsSpan(), global::System.StringComparison.Ordinal): - result = MyTestNameSpace.MyEnum.First; + case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.First).AsSpan(), global::System.StringComparison.Ordinal): + result = global::MyTestNameSpace.MyEnum.First; return true; - case ReadOnlySpan current when current.Equals(nameof(MyTestNameSpace.MyEnum.Second).AsSpan(), global::System.StringComparison.Ordinal): - result = MyTestNameSpace.MyEnum.Second; + case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.Second).AsSpan(), global::System.StringComparison.Ordinal): + result = global::MyTestNameSpace.MyEnum.Second; return true; - case ReadOnlySpan current when current.Equals(nameof(MyTestNameSpace.MyEnum.Third).AsSpan(), global::System.StringComparison.Ordinal): - result = MyTestNameSpace.MyEnum.Third; + case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.Third).AsSpan(), global::System.StringComparison.Ordinal): + result = global::MyTestNameSpace.MyEnum.Third; return true; - case ReadOnlySpan current when current.Equals(nameof(MyTestNameSpace.MyEnum.Fourth).AsSpan(), global::System.StringComparison.Ordinal): - result = MyTestNameSpace.MyEnum.Fourth; + case ReadOnlySpan current when current.Equals(nameof(global::MyTestNameSpace.MyEnum.Fourth).AsSpan(), global::System.StringComparison.Ordinal): + result = global::MyTestNameSpace.MyEnum.Fourth; return true; case ReadOnlySpan current when int.TryParse(name, out var numericResult): - result = (MyTestNameSpace.MyEnum)numericResult; + result = (global::MyTestNameSpace.MyEnum)numericResult; return true; default: result = default; @@ -436,37 +436,37 @@ namespace MyTestNameSpace /// /// Retrieves an array of the values of the members defined in - /// . + /// . /// Note that this returns a new array with every invocation, so /// should be cached if appropriate. /// - /// An array of the values defined in - public static MyTestNameSpace.MyEnum[] GetValues() + /// An array of the values defined in + public static global::MyTestNameSpace.MyEnum[] GetValues() { return new[] { - MyTestNameSpace.MyEnum.First, - MyTestNameSpace.MyEnum.Second, - MyTestNameSpace.MyEnum.Third, - MyTestNameSpace.MyEnum.Fourth, + global::MyTestNameSpace.MyEnum.First, + global::MyTestNameSpace.MyEnum.Second, + global::MyTestNameSpace.MyEnum.Third, + global::MyTestNameSpace.MyEnum.Fourth, }; } /// /// Retrieves an array of the names of the members defined in - /// . + /// . /// Note that this returns a new array with every invocation, so /// should be cached if appropriate. /// - /// An array of the names of the members defined in + /// An array of the names of the members defined in public static string[] GetNames() { return new[] { - nameof(MyTestNameSpace.MyEnum.First), - nameof(MyTestNameSpace.MyEnum.Second), - nameof(MyTestNameSpace.MyEnum.Third), - nameof(MyTestNameSpace.MyEnum.Fourth), + nameof(global::MyTestNameSpace.MyEnum.First), + nameof(global::MyTestNameSpace.MyEnum.Second), + nameof(global::MyTestNameSpace.MyEnum.Third), + nameof(global::MyTestNameSpace.MyEnum.Fourth), }; } } diff --git a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanHandleNamespaceAndClassNameAreTheSame.verified.txt b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanHandleNamespaceAndClassNameAreTheSame.verified.txt new file mode 100644 index 0000000..63cb56d --- /dev/null +++ b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanHandleNamespaceAndClassNameAreTheSame.verified.txt @@ -0,0 +1,336 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the NetEscapades.EnumGenerators source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#nullable enable +#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 +using System; +#endif + +namespace Foo +{ + /// + /// Extension methods for + /// + public static partial class TestEnumExtensions + { + /// + /// The number of members in the enum. + /// This is a non-distinct count of defined names. + /// + public const int Length = 1; + + /// + /// Returns the string representation of the value. + /// If the attribute is decorated with a [Display] attribute, then + /// uses the provided value. Otherwise uses the name of the member, equivalent to + /// calling ToString() on . + /// + /// The value to retrieve the string value for + /// The string representation of the value + public static string ToStringFast(this global::Foo.TestEnum value) + => value switch + { + global::Foo.TestEnum.Value1 => nameof(global::Foo.TestEnum.Value1), + _ => value.ToString(), + }; + + /// + /// Returns a boolean telling whether the given enum value exists in the enumeration. + /// + /// The value to check if it's defined + /// true if the value exists in the enumeration, false otherwise + public static bool IsDefined(global::Foo.TestEnum value) + => value switch + { + global::Foo.TestEnum.Value1 => true, + _ => false, + }; + + /// + /// Returns a boolean telling whether an enum with the given name exists in the enumeration. + /// + /// 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(string name) => IsDefined(name, allowMatchingMetadataAttribute: false); + + /// + /// Returns a boolean telling whether an enum with the given name exists in the enumeration, + /// or if a member decorated with a [Display] attribute + /// with the required name exists. + /// + /// The name to check if it's defined + /// 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(string name, bool allowMatchingMetadataAttribute) + { + return name switch + { + nameof(global::Foo.TestEnum.Value1) => true, + _ => false, + }; + } + +#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 + /// + /// Returns a boolean telling whether an enum with the given name exists in the enumeration + /// + /// 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); + + /// + /// Returns a boolean telling whether an enum with the given name exists in the enumeration, + /// or optionally if a member decorated with a [Display] attribute + /// with the required name exists. + /// Slower then the overload, but doesn't allocate memory./> + /// + /// The name to check if it's defined + /// 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) + { + return name switch + { + ReadOnlySpan current when current.Equals(nameof(global::Foo.TestEnum.Value1).AsSpan(), global::System.StringComparison.Ordinal) => true, + _ => false, + }; + } +#endif + + /// + /// Converts the string representation of the name or numeric value of + /// an to the equivalent instance. + /// The return value indicates whether the conversion succeeded. + /// + /// The case-sensitive string representation of the enumeration name or underlying value to convert + /// When this method returns, contains an object of type + /// whose + /// value is represented by if the parse operation succeeds. + /// If the parse operation fails, contains the default value of the underlying type + /// of . This parameter is passed uninitialized. + /// true if the value parameter was converted successfully; otherwise, false. + public static bool TryParse( +#if NETCOREAPP3_0_OR_GREATER + [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] +#endif + string? name, + out global::Foo.TestEnum value) + => TryParse(name, out value, false, false); + + /// + /// Converts the string representation of the name or numeric value of + /// an to the equivalent instance. + /// The return value indicates whether the conversion succeeded. + /// + /// The string representation of the enumeration name or underlying value to convert + /// When this method returns, contains an object of type + /// whose + /// value is represented by if the parse operation succeeds. + /// If the parse operation fails, contains the default value of the underlying type + /// of . This parameter is passed uninitialized. + /// true to read value in case insensitive mode; false to read value in case sensitive mode. + /// true if the value parameter was converted successfully; otherwise, false. + public static bool TryParse( +#if NETCOREAPP3_0_OR_GREATER + [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] +#endif + string? name, + out global::Foo.TestEnum value, + bool ignoreCase) + => TryParse(name, out value, ignoreCase, false); + + /// + /// Converts the string representation of the name or numeric value of + /// an to the equivalent instance. + /// The return value indicates whether the conversion succeeded. + /// + /// The string representation of the enumeration name or underlying value to convert + /// When this method returns, contains an object of type + /// whose + /// value is represented by if the parse operation succeeds. + /// If the parse operation fails, contains the default value of the underlying type + /// of . This parameter is passed uninitialized. + /// true to read value in case insensitive mode; false to read value in case sensitive mode. + /// If true, considers the value included in metadata attributes such as + /// [Display] attribute when parsing, otherwise only considers the member names. + /// true if the value parameter was converted successfully; otherwise, false. + public static bool TryParse( +#if NETCOREAPP3_0_OR_GREATER + [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] +#endif + string? name, + out global::Foo.TestEnum value, + bool ignoreCase, + bool allowMatchingMetadataAttribute) + { + if (ignoreCase) + { + switch (name) + { + case string s when s.Equals(nameof(global::Foo.TestEnum.Value1), global::System.StringComparison.OrdinalIgnoreCase): + value = global::Foo.TestEnum.Value1; + return true; + case string s when int.TryParse(name, out var val): + value = (global::Foo.TestEnum)val; + return true; + default: + value = default; + return false; + } + } + else + { + switch (name) + { + case nameof(global::Foo.TestEnum.Value1): + value = global::Foo.TestEnum.Value1; + return true; + case string s when int.TryParse(name, out var val): + value = (global::Foo.TestEnum)val; + return true; + default: + value = default; + return false; + } + } + } + +#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 + /// + /// Converts the span representation of the name or numeric value of + /// an to the equivalent instance. + /// The return value indicates whether the conversion succeeded. + /// + /// The span representation of the enumeration name or underlying value to convert + /// When this method returns, contains an object of type + /// whose + /// value is represented by if the parse operation succeeds. + /// If the parse operation fails, contains the default value of the underlying type + /// of . This parameter is passed uninitialized. + /// true if the value parameter was converted successfully; otherwise, false. + public static bool TryParse( +#if NETCOREAPP3_0_OR_GREATER + [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] +#endif + in ReadOnlySpan name, + out global::Foo.TestEnum value) + => TryParse(name, out value, false, false); + + /// + /// Converts the span representation of the name or numeric value of + /// an to the equivalent instance. + /// The return value indicates whether the conversion succeeded. + /// + /// The span representation of the enumeration name or underlying value to convert + /// When this method returns, contains an object of type + /// whose + /// value is represented by if the parse operation succeeds. + /// If the parse operation fails, contains the default value of the underlying type + /// of . This parameter is passed uninitialized. + /// true to read value in case insensitive mode; false to read value in case sensitive mode. + /// true if the value parameter was converted successfully; otherwise, false. + public static bool TryParse( +#if NETCOREAPP3_0_OR_GREATER + [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] +#endif + in ReadOnlySpan name, + out global::Foo.TestEnum value, + bool ignoreCase) + => TryParse(name, out value, ignoreCase, false); + + /// + /// Converts the span representation of the name or numeric value of + /// an to the equivalent instance. + /// The return value indicates whether the conversion succeeded. + /// + /// The span representation of the enumeration name or underlying value to convert + /// When this method returns, contains an object of type + /// whose + /// value is represented by if the parse operation succeeds. + /// If the parse operation fails, contains the default value of the underlying type + /// of . This parameter is passed uninitialized. + /// true to read value in case insensitive mode; false to read value in case sensitive mode. + /// If true, considers the value included in metadata attributes such as + /// [Display] attribute when parsing, otherwise only considers the member names. + /// true if the value parameter was converted successfully; otherwise, false. + public static bool TryParse( +#if NETCOREAPP3_0_OR_GREATER + [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] +#endif + in ReadOnlySpan name, + out global::Foo.TestEnum result, + bool ignoreCase, + bool allowMatchingMetadataAttribute) + { + if (ignoreCase) + { + switch (name) + { + case ReadOnlySpan current when current.Equals(nameof(global::Foo.TestEnum.Value1).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + result = global::Foo.TestEnum.Value1; + return true; + case ReadOnlySpan current when int.TryParse(name, out var numericResult): + result = (global::Foo.TestEnum)numericResult; + return true; + default: + result = default; + return false; + } + } + else + { + switch (name) + { + case ReadOnlySpan current when current.Equals(nameof(global::Foo.TestEnum.Value1).AsSpan(), global::System.StringComparison.Ordinal): + result = global::Foo.TestEnum.Value1; + return true; + case ReadOnlySpan current when int.TryParse(name, out var numericResult): + result = (global::Foo.TestEnum)numericResult; + return true; + default: + result = default; + return false; + } + } + } +#endif + + /// + /// Retrieves an array of the values of the members defined in + /// . + /// Note that this returns a new array with every invocation, so + /// should be cached if appropriate. + /// + /// An array of the values defined in + public static global::Foo.TestEnum[] GetValues() + { + return new[] + { + global::Foo.TestEnum.Value1, + }; + } + + /// + /// Retrieves an array of the names of the members defined in + /// . + /// Note that this returns a new array with every invocation, so + /// should be cached if appropriate. + /// + /// An array of the names of the members defined in + public static string[] GetNames() + { + return new[] + { + nameof(global::Foo.TestEnum.Value1), + }; + } + } +} \ No newline at end of file diff --git a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesEnumCorrectly.verified.txt b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesEnumCorrectly.verified.txt index a65cdb9..1c6c361 100644 --- a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesEnumCorrectly.verified.txt +++ b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesEnumCorrectly.verified.txt @@ -15,7 +15,7 @@ using System; namespace Something.Blah { /// - /// Extension methods for + /// Extension methods for /// public static partial class ShortName { @@ -26,18 +26,18 @@ namespace Something.Blah public const int Length = 2; /// - /// Returns the string representation of the value. + /// Returns the string representation of the value. /// If the attribute is decorated with a [Display] attribute, then /// uses the provided value. Otherwise uses the name of the member, equivalent to /// calling ToString() on . /// /// The value to retrieve the string value for /// The string representation of the value - public static string ToStringFast(this Something.Blah.ShortName value) + public static string ToStringFast(this global::Something.Blah.ShortName value) => value switch { - Something.Blah.ShortName.First => nameof(Something.Blah.ShortName.First), - Something.Blah.ShortName.Second => nameof(Something.Blah.ShortName.Second), + global::Something.Blah.ShortName.First => nameof(global::Something.Blah.ShortName.First), + global::Something.Blah.ShortName.Second => nameof(global::Something.Blah.ShortName.Second), _ => value.ToString(), }; @@ -46,11 +46,11 @@ namespace Something.Blah /// /// The value to check if it's defined /// true if the value exists in the enumeration, false otherwise - public static bool IsDefined(Something.Blah.ShortName value) + public static bool IsDefined(global::Something.Blah.ShortName value) => value switch { - Something.Blah.ShortName.First => true, - Something.Blah.ShortName.Second => true, + global::Something.Blah.ShortName.First => true, + global::Something.Blah.ShortName.Second => true, _ => false, }; @@ -74,8 +74,8 @@ namespace Something.Blah { return name switch { - nameof(Something.Blah.ShortName.First) => true, - nameof(Something.Blah.ShortName.Second) => true, + nameof(global::Something.Blah.ShortName.First) => true, + nameof(global::Something.Blah.ShortName.Second) => true, _ => false, }; } @@ -102,8 +102,8 @@ namespace Something.Blah { return name switch { - ReadOnlySpan current when current.Equals(nameof(Something.Blah.ShortName.First).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(Something.Blah.ShortName.Second).AsSpan(), global::System.StringComparison.Ordinal) => true, + 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, _ => false, }; } @@ -111,35 +111,35 @@ namespace Something.Blah /// /// Converts the string representation of the name or numeric value of - /// an to the equivalent instance. + /// an to the equivalent instance. /// The return value indicates whether the conversion succeeded. /// /// The case-sensitive string representation of the enumeration name or underlying value to convert /// When this method returns, contains an object of type - /// whose + /// whose /// value is represented by if the parse operation succeeds. /// If the parse operation fails, contains the default value of the underlying type - /// of . This parameter is passed uninitialized. + /// of . This parameter is passed uninitialized. /// true if the value parameter was converted successfully; otherwise, false. public static bool TryParse( #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif string? name, - out Something.Blah.ShortName value) + out global::Something.Blah.ShortName value) => TryParse(name, out value, false, false); /// /// Converts the string representation of the name or numeric value of - /// an to the equivalent instance. + /// an to the equivalent instance. /// The return value indicates whether the conversion succeeded. /// /// The string representation of the enumeration name or underlying value to convert /// When this method returns, contains an object of type - /// whose + /// whose /// value is represented by if the parse operation succeeds. /// If the parse operation fails, contains the default value of the underlying type - /// of . This parameter is passed uninitialized. + /// of . This parameter is passed uninitialized. /// true to read value in case insensitive mode; false to read value in case sensitive mode. /// true if the value parameter was converted successfully; otherwise, false. public static bool TryParse( @@ -147,21 +147,21 @@ namespace Something.Blah [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif string? name, - out Something.Blah.ShortName value, + out global::Something.Blah.ShortName value, bool ignoreCase) => TryParse(name, out value, ignoreCase, false); /// /// Converts the string representation of the name or numeric value of - /// an to the equivalent instance. + /// an to the equivalent instance. /// The return value indicates whether the conversion succeeded. /// /// The string representation of the enumeration name or underlying value to convert /// When this method returns, contains an object of type - /// whose + /// whose /// value is represented by if the parse operation succeeds. /// If the parse operation fails, contains the default value of the underlying type - /// of . This parameter is passed uninitialized. + /// of . This parameter is passed uninitialized. /// true to read value in case insensitive mode; false to read value in case sensitive mode. /// If true, considers the value included in metadata attributes such as /// [Display] attribute when parsing, otherwise only considers the member names. @@ -171,7 +171,7 @@ namespace Something.Blah [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif string? name, - out Something.Blah.ShortName value, + out global::Something.Blah.ShortName value, bool ignoreCase, bool allowMatchingMetadataAttribute) { @@ -179,14 +179,14 @@ namespace Something.Blah { switch (name) { - case string s when s.Equals(nameof(Something.Blah.ShortName.First), global::System.StringComparison.OrdinalIgnoreCase): - value = Something.Blah.ShortName.First; + case string s when s.Equals(nameof(global::Something.Blah.ShortName.First), global::System.StringComparison.OrdinalIgnoreCase): + value = global::Something.Blah.ShortName.First; return true; - case string s when s.Equals(nameof(Something.Blah.ShortName.Second), global::System.StringComparison.OrdinalIgnoreCase): - value = Something.Blah.ShortName.Second; + case string s when s.Equals(nameof(global::Something.Blah.ShortName.Second), global::System.StringComparison.OrdinalIgnoreCase): + value = global::Something.Blah.ShortName.Second; return true; case string s when int.TryParse(name, out var val): - value = (Something.Blah.ShortName)val; + value = (global::Something.Blah.ShortName)val; return true; default: value = default; @@ -197,14 +197,14 @@ namespace Something.Blah { switch (name) { - case nameof(Something.Blah.ShortName.First): - value = Something.Blah.ShortName.First; + case nameof(global::Something.Blah.ShortName.First): + value = global::Something.Blah.ShortName.First; return true; - case nameof(Something.Blah.ShortName.Second): - value = Something.Blah.ShortName.Second; + case nameof(global::Something.Blah.ShortName.Second): + value = global::Something.Blah.ShortName.Second; return true; case string s when int.TryParse(name, out var val): - value = (Something.Blah.ShortName)val; + value = (global::Something.Blah.ShortName)val; return true; default: value = default; @@ -216,35 +216,35 @@ namespace Something.Blah #if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Converts the span representation of the name or numeric value of - /// an to the equivalent instance. + /// an to the equivalent instance. /// The return value indicates whether the conversion succeeded. /// /// The span representation of the enumeration name or underlying value to convert /// When this method returns, contains an object of type - /// whose + /// whose /// value is represented by if the parse operation succeeds. /// If the parse operation fails, contains the default value of the underlying type - /// of . This parameter is passed uninitialized. + /// of . This parameter is passed uninitialized. /// true if the value parameter was converted successfully; otherwise, false. public static bool TryParse( #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif in ReadOnlySpan name, - out Something.Blah.ShortName value) + out global::Something.Blah.ShortName value) => TryParse(name, out value, false, false); /// /// Converts the span representation of the name or numeric value of - /// an to the equivalent instance. + /// an to the equivalent instance. /// The return value indicates whether the conversion succeeded. /// /// The span representation of the enumeration name or underlying value to convert /// When this method returns, contains an object of type - /// whose + /// whose /// value is represented by if the parse operation succeeds. /// If the parse operation fails, contains the default value of the underlying type - /// of . This parameter is passed uninitialized. + /// of . This parameter is passed uninitialized. /// true to read value in case insensitive mode; false to read value in case sensitive mode. /// true if the value parameter was converted successfully; otherwise, false. public static bool TryParse( @@ -252,21 +252,21 @@ namespace Something.Blah [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif in ReadOnlySpan name, - out Something.Blah.ShortName value, + out global::Something.Blah.ShortName value, bool ignoreCase) => TryParse(name, out value, ignoreCase, false); /// /// Converts the span representation of the name or numeric value of - /// an to the equivalent instance. + /// an to the equivalent instance. /// The return value indicates whether the conversion succeeded. /// /// The span representation of the enumeration name or underlying value to convert /// When this method returns, contains an object of type - /// whose + /// whose /// value is represented by if the parse operation succeeds. /// If the parse operation fails, contains the default value of the underlying type - /// of . This parameter is passed uninitialized. + /// of . This parameter is passed uninitialized. /// true to read value in case insensitive mode; false to read value in case sensitive mode. /// If true, considers the value included in metadata attributes such as /// [Display] attribute when parsing, otherwise only considers the member names. @@ -276,7 +276,7 @@ namespace Something.Blah [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif in ReadOnlySpan name, - out Something.Blah.ShortName result, + out global::Something.Blah.ShortName result, bool ignoreCase, bool allowMatchingMetadataAttribute) { @@ -284,14 +284,14 @@ namespace Something.Blah { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(Something.Blah.ShortName.First).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): - result = Something.Blah.ShortName.First; + case ReadOnlySpan current when current.Equals(nameof(global::Something.Blah.ShortName.First).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + result = global::Something.Blah.ShortName.First; return true; - case ReadOnlySpan current when current.Equals(nameof(Something.Blah.ShortName.Second).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): - result = Something.Blah.ShortName.Second; + case ReadOnlySpan current when current.Equals(nameof(global::Something.Blah.ShortName.Second).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + result = global::Something.Blah.ShortName.Second; return true; case ReadOnlySpan current when int.TryParse(name, out var numericResult): - result = (Something.Blah.ShortName)numericResult; + result = (global::Something.Blah.ShortName)numericResult; return true; default: result = default; @@ -302,14 +302,14 @@ namespace Something.Blah { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(Something.Blah.ShortName.First).AsSpan(), global::System.StringComparison.Ordinal): - result = Something.Blah.ShortName.First; + case ReadOnlySpan current when current.Equals(nameof(global::Something.Blah.ShortName.First).AsSpan(), global::System.StringComparison.Ordinal): + result = global::Something.Blah.ShortName.First; return true; - case ReadOnlySpan current when current.Equals(nameof(Something.Blah.ShortName.Second).AsSpan(), global::System.StringComparison.Ordinal): - result = Something.Blah.ShortName.Second; + case ReadOnlySpan current when current.Equals(nameof(global::Something.Blah.ShortName.Second).AsSpan(), global::System.StringComparison.Ordinal): + result = global::Something.Blah.ShortName.Second; return true; case ReadOnlySpan current when int.TryParse(name, out var numericResult): - result = (Something.Blah.ShortName)numericResult; + result = (global::Something.Blah.ShortName)numericResult; return true; default: result = default; @@ -321,33 +321,33 @@ namespace Something.Blah /// /// Retrieves an array of the values of the members defined in - /// . + /// . /// Note that this returns a new array with every invocation, so /// should be cached if appropriate. /// - /// An array of the values defined in - public static Something.Blah.ShortName[] GetValues() + /// An array of the values defined in + public static global::Something.Blah.ShortName[] GetValues() { return new[] { - Something.Blah.ShortName.First, - Something.Blah.ShortName.Second, + global::Something.Blah.ShortName.First, + global::Something.Blah.ShortName.Second, }; } /// /// Retrieves an array of the names of the members defined in - /// . + /// . /// Note that this returns a new array with every invocation, so /// should be cached if appropriate. /// - /// An array of the names of the members defined in + /// An array of the names of the members defined in public static string[] GetNames() { return new[] { - nameof(Something.Blah.ShortName.First), - nameof(Something.Blah.ShortName.Second), + nameof(global::Something.Blah.ShortName.First), + nameof(global::Something.Blah.ShortName.Second), }; } } diff --git a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFlagsEnumCorrectly.verified.txt b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFlagsEnumCorrectly.verified.txt index 34c617a..2969514 100644 --- a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFlagsEnumCorrectly.verified.txt +++ b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFlagsEnumCorrectly.verified.txt @@ -15,7 +15,7 @@ using System; namespace Something.Blah { /// - /// Extension methods for + /// Extension methods for /// public static partial class ShortName { @@ -26,18 +26,18 @@ namespace Something.Blah public const int Length = 2; /// - /// Returns the string representation of the value. + /// Returns the string representation of the value. /// If the attribute is decorated with a [Display] attribute, then /// uses the provided value. Otherwise uses the name of the member, equivalent to /// calling ToString() on . /// /// The value to retrieve the string value for /// The string representation of the value - public static string ToStringFast(this Something.Blah.ShortName value) + public static string ToStringFast(this global::Something.Blah.ShortName value) => value switch { - Something.Blah.ShortName.First => nameof(Something.Blah.ShortName.First), - Something.Blah.ShortName.Second => nameof(Something.Blah.ShortName.Second), + global::Something.Blah.ShortName.First => nameof(global::Something.Blah.ShortName.First), + global::Something.Blah.ShortName.Second => nameof(global::Something.Blah.ShortName.Second), _ => value.ToString(), }; @@ -50,7 +50,7 @@ namespace Something.Blah /// true if the fields set in the flag are also set in the current instance; otherwise false. /// If the underlying value of is zero, the method returns true. /// This is consistent with the behaviour of - public static bool HasFlagFast(this Something.Blah.ShortName value, Something.Blah.ShortName flag) + public static bool HasFlagFast(this global::Something.Blah.ShortName value, global::Something.Blah.ShortName flag) => flag == 0 ? true : (value & flag) == flag; /// @@ -58,11 +58,11 @@ namespace Something.Blah /// /// The value to check if it's defined /// true if the value exists in the enumeration, false otherwise - public static bool IsDefined(Something.Blah.ShortName value) + public static bool IsDefined(global::Something.Blah.ShortName value) => value switch { - Something.Blah.ShortName.First => true, - Something.Blah.ShortName.Second => true, + global::Something.Blah.ShortName.First => true, + global::Something.Blah.ShortName.Second => true, _ => false, }; @@ -86,8 +86,8 @@ namespace Something.Blah { return name switch { - nameof(Something.Blah.ShortName.First) => true, - nameof(Something.Blah.ShortName.Second) => true, + nameof(global::Something.Blah.ShortName.First) => true, + nameof(global::Something.Blah.ShortName.Second) => true, _ => false, }; } @@ -114,8 +114,8 @@ namespace Something.Blah { return name switch { - ReadOnlySpan current when current.Equals(nameof(Something.Blah.ShortName.First).AsSpan(), global::System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals(nameof(Something.Blah.ShortName.Second).AsSpan(), global::System.StringComparison.Ordinal) => true, + 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, _ => false, }; } @@ -123,35 +123,35 @@ namespace Something.Blah /// /// Converts the string representation of the name or numeric value of - /// an to the equivalent instance. + /// an to the equivalent instance. /// The return value indicates whether the conversion succeeded. /// /// The case-sensitive string representation of the enumeration name or underlying value to convert /// When this method returns, contains an object of type - /// whose + /// whose /// value is represented by if the parse operation succeeds. /// If the parse operation fails, contains the default value of the underlying type - /// of . This parameter is passed uninitialized. + /// of . This parameter is passed uninitialized. /// true if the value parameter was converted successfully; otherwise, false. public static bool TryParse( #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif string? name, - out Something.Blah.ShortName value) + out global::Something.Blah.ShortName value) => TryParse(name, out value, false, false); /// /// Converts the string representation of the name or numeric value of - /// an to the equivalent instance. + /// an to the equivalent instance. /// The return value indicates whether the conversion succeeded. /// /// The string representation of the enumeration name or underlying value to convert /// When this method returns, contains an object of type - /// whose + /// whose /// value is represented by if the parse operation succeeds. /// If the parse operation fails, contains the default value of the underlying type - /// of . This parameter is passed uninitialized. + /// of . This parameter is passed uninitialized. /// true to read value in case insensitive mode; false to read value in case sensitive mode. /// true if the value parameter was converted successfully; otherwise, false. public static bool TryParse( @@ -159,21 +159,21 @@ namespace Something.Blah [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif string? name, - out Something.Blah.ShortName value, + out global::Something.Blah.ShortName value, bool ignoreCase) => TryParse(name, out value, ignoreCase, false); /// /// Converts the string representation of the name or numeric value of - /// an to the equivalent instance. + /// an to the equivalent instance. /// The return value indicates whether the conversion succeeded. /// /// The string representation of the enumeration name or underlying value to convert /// When this method returns, contains an object of type - /// whose + /// whose /// value is represented by if the parse operation succeeds. /// If the parse operation fails, contains the default value of the underlying type - /// of . This parameter is passed uninitialized. + /// of . This parameter is passed uninitialized. /// true to read value in case insensitive mode; false to read value in case sensitive mode. /// If true, considers the value included in metadata attributes such as /// [Display] attribute when parsing, otherwise only considers the member names. @@ -183,7 +183,7 @@ namespace Something.Blah [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif string? name, - out Something.Blah.ShortName value, + out global::Something.Blah.ShortName value, bool ignoreCase, bool allowMatchingMetadataAttribute) { @@ -191,14 +191,14 @@ namespace Something.Blah { switch (name) { - case string s when s.Equals(nameof(Something.Blah.ShortName.First), global::System.StringComparison.OrdinalIgnoreCase): - value = Something.Blah.ShortName.First; + case string s when s.Equals(nameof(global::Something.Blah.ShortName.First), global::System.StringComparison.OrdinalIgnoreCase): + value = global::Something.Blah.ShortName.First; return true; - case string s when s.Equals(nameof(Something.Blah.ShortName.Second), global::System.StringComparison.OrdinalIgnoreCase): - value = Something.Blah.ShortName.Second; + case string s when s.Equals(nameof(global::Something.Blah.ShortName.Second), global::System.StringComparison.OrdinalIgnoreCase): + value = global::Something.Blah.ShortName.Second; return true; case string s when int.TryParse(name, out var val): - value = (Something.Blah.ShortName)val; + value = (global::Something.Blah.ShortName)val; return true; default: value = default; @@ -209,14 +209,14 @@ namespace Something.Blah { switch (name) { - case nameof(Something.Blah.ShortName.First): - value = Something.Blah.ShortName.First; + case nameof(global::Something.Blah.ShortName.First): + value = global::Something.Blah.ShortName.First; return true; - case nameof(Something.Blah.ShortName.Second): - value = Something.Blah.ShortName.Second; + case nameof(global::Something.Blah.ShortName.Second): + value = global::Something.Blah.ShortName.Second; return true; case string s when int.TryParse(name, out var val): - value = (Something.Blah.ShortName)val; + value = (global::Something.Blah.ShortName)val; return true; default: value = default; @@ -228,35 +228,35 @@ namespace Something.Blah #if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 /// /// Converts the span representation of the name or numeric value of - /// an to the equivalent instance. + /// an to the equivalent instance. /// The return value indicates whether the conversion succeeded. /// /// The span representation of the enumeration name or underlying value to convert /// When this method returns, contains an object of type - /// whose + /// whose /// value is represented by if the parse operation succeeds. /// If the parse operation fails, contains the default value of the underlying type - /// of . This parameter is passed uninitialized. + /// of . This parameter is passed uninitialized. /// true if the value parameter was converted successfully; otherwise, false. public static bool TryParse( #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif in ReadOnlySpan name, - out Something.Blah.ShortName value) + out global::Something.Blah.ShortName value) => TryParse(name, out value, false, false); /// /// Converts the span representation of the name or numeric value of - /// an to the equivalent instance. + /// an to the equivalent instance. /// The return value indicates whether the conversion succeeded. /// /// The span representation of the enumeration name or underlying value to convert /// When this method returns, contains an object of type - /// whose + /// whose /// value is represented by if the parse operation succeeds. /// If the parse operation fails, contains the default value of the underlying type - /// of . This parameter is passed uninitialized. + /// of . This parameter is passed uninitialized. /// true to read value in case insensitive mode; false to read value in case sensitive mode. /// true if the value parameter was converted successfully; otherwise, false. public static bool TryParse( @@ -264,21 +264,21 @@ namespace Something.Blah [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif in ReadOnlySpan name, - out Something.Blah.ShortName value, + out global::Something.Blah.ShortName value, bool ignoreCase) => TryParse(name, out value, ignoreCase, false); /// /// Converts the span representation of the name or numeric value of - /// an to the equivalent instance. + /// an to the equivalent instance. /// The return value indicates whether the conversion succeeded. /// /// The span representation of the enumeration name or underlying value to convert /// When this method returns, contains an object of type - /// whose + /// whose /// value is represented by if the parse operation succeeds. /// If the parse operation fails, contains the default value of the underlying type - /// of . This parameter is passed uninitialized. + /// of . This parameter is passed uninitialized. /// true to read value in case insensitive mode; false to read value in case sensitive mode. /// If true, considers the value included in metadata attributes such as /// [Display] attribute when parsing, otherwise only considers the member names. @@ -288,7 +288,7 @@ namespace Something.Blah [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif in ReadOnlySpan name, - out Something.Blah.ShortName result, + out global::Something.Blah.ShortName result, bool ignoreCase, bool allowMatchingMetadataAttribute) { @@ -296,14 +296,14 @@ namespace Something.Blah { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(Something.Blah.ShortName.First).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): - result = Something.Blah.ShortName.First; + case ReadOnlySpan current when current.Equals(nameof(global::Something.Blah.ShortName.First).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + result = global::Something.Blah.ShortName.First; return true; - case ReadOnlySpan current when current.Equals(nameof(Something.Blah.ShortName.Second).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): - result = Something.Blah.ShortName.Second; + case ReadOnlySpan current when current.Equals(nameof(global::Something.Blah.ShortName.Second).AsSpan(), global::System.StringComparison.OrdinalIgnoreCase): + result = global::Something.Blah.ShortName.Second; return true; case ReadOnlySpan current when int.TryParse(name, out var numericResult): - result = (Something.Blah.ShortName)numericResult; + result = (global::Something.Blah.ShortName)numericResult; return true; default: result = default; @@ -314,14 +314,14 @@ namespace Something.Blah { switch (name) { - case ReadOnlySpan current when current.Equals(nameof(Something.Blah.ShortName.First).AsSpan(), global::System.StringComparison.Ordinal): - result = Something.Blah.ShortName.First; + case ReadOnlySpan current when current.Equals(nameof(global::Something.Blah.ShortName.First).AsSpan(), global::System.StringComparison.Ordinal): + result = global::Something.Blah.ShortName.First; return true; - case ReadOnlySpan current when current.Equals(nameof(Something.Blah.ShortName.Second).AsSpan(), global::System.StringComparison.Ordinal): - result = Something.Blah.ShortName.Second; + case ReadOnlySpan current when current.Equals(nameof(global::Something.Blah.ShortName.Second).AsSpan(), global::System.StringComparison.Ordinal): + result = global::Something.Blah.ShortName.Second; return true; case ReadOnlySpan current when int.TryParse(name, out var numericResult): - result = (Something.Blah.ShortName)numericResult; + result = (global::Something.Blah.ShortName)numericResult; return true; default: result = default; @@ -333,33 +333,33 @@ namespace Something.Blah /// /// Retrieves an array of the values of the members defined in - /// . + /// . /// Note that this returns a new array with every invocation, so /// should be cached if appropriate. /// - /// An array of the values defined in - public static Something.Blah.ShortName[] GetValues() + /// An array of the values defined in + public static global::Something.Blah.ShortName[] GetValues() { return new[] { - Something.Blah.ShortName.First, - Something.Blah.ShortName.Second, + global::Something.Blah.ShortName.First, + global::Something.Blah.ShortName.Second, }; } /// /// Retrieves an array of the names of the members defined in - /// . + /// . /// Note that this returns a new array with every invocation, so /// should be cached if appropriate. /// - /// An array of the names of the members defined in + /// An array of the names of the members defined in public static string[] GetNames() { return new[] { - nameof(Something.Blah.ShortName.First), - nameof(Something.Blah.ShortName.Second), + nameof(global::Something.Blah.ShortName.First), + nameof(global::Something.Blah.ShortName.Second), }; } }