diff --git a/src/NetEscapades.EnumGenerators/SourceGenerationHelper.cs b/src/NetEscapades.EnumGenerators/SourceGenerationHelper.cs index 8e41103..e547835 100644 --- a/src/NetEscapades.EnumGenerators/SourceGenerationHelper.cs +++ b/src/NetEscapades.EnumGenerators/SourceGenerationHelper.cs @@ -62,6 +62,9 @@ namespace ").Append(enumToGenerate.Namespace).Append(@" } sb.Append(@" + /// + /// Extension methods for + /// ").Append(enumToGenerate.IsPublic ? "public" : "internal").Append(@" static partial class ").Append(enumToGenerate.Name).Append(@" { /// @@ -70,6 +73,14 @@ namespace ").Append(enumToGenerate.Namespace).Append(@" /// public const int Length = ").Append(enumToGenerate.Names.Count).Append(";").Append(@" + /// + /// Returns the string representation of the value. + /// If the attribute is decorated with a , 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) => value switch {"); @@ -97,6 +108,13 @@ public static string ToStringFast(this ").Append(enumToGenerate.FullyQualifiedNa { sb.Append(@" + /// + /// Determines whether one or more bit fields are set in the current instance. + /// Equivalent to calling value.HasFlag(flag) + /// + /// The value of the instance to investiage + /// The flag to check for + /// true if the fields set in the flag are also set in the current instance; otherwise false. public static bool HasFlag(this ").Append(enumToGenerate.FullyQualifiedName).Append(@" value, ").Append(enumToGenerate.FullyQualifiedName).Append(@" flag) => value switch { @@ -107,6 +125,11 @@ public static bool HasFlag(this ").Append(enumToGenerate.FullyQualifiedName).App sb.Append(@" + /// + /// 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(").Append(enumToGenerate.FullyQualifiedName).Append(@" value) => value switch {"); @@ -123,8 +146,22 @@ public static bool IsDefined(").Append(enumToGenerate.FullyQualifiedName).Append sb.Append(@" + /// + /// 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 + /// 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 with the name, false otherwise public static bool IsDefined(string name, bool allowMatchingMetadataAttribute) {"); if (enumToGenerate.IsDisplayAttributeUsed) @@ -138,7 +175,7 @@ public static bool IsDefined(string name, bool allowMatchingMetadataAttribute) foreach (var member in enumToGenerate.Names) { if (member.Value.DisplayName is not null && member.Value.IsDisplayNameTheFirstPresence) - { + { sb.Append(@" """).Append(member.Value.DisplayName).Append(@""" => true,"); } @@ -156,12 +193,13 @@ public static bool IsDefined(string name, bool allowMatchingMetadataAttribute) "); } + sb.Append(@" return name switch {"); foreach (var member in enumToGenerate.Names) - { - sb.Append(@" + { + sb.Append(@" nameof(").Append(enumToGenerate.FullyQualifiedName).Append('.').Append(member.Key).Append(@") => true,"); } @@ -173,15 +211,23 @@ public static bool IsDefined(string name, bool allowMatchingMetadataAttribute) sb.Append(@" #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); /// - /// Slower then the ReadOnlySpan can't be cached like a string, tho it doesn't allocate memory./> + /// Returns a boolean telling whether an enum with the given name exists in the enumeration, + /// or optionally if a member decorated with a + /// with the required name exists. + /// Slower then the overload, but doesn't allocate memory./> /// - /// - /// - /// true if defined, otherwise false + /// 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 with the name, false otherwise public static bool IsDefined(in ReadOnlySpan name, bool allowMatchingMetadataAttribute) {"); @@ -198,7 +244,7 @@ public static bool IsDefined(in ReadOnlySpan name, bool allowMatchingMetad if (member.Value.DisplayName is not null && member.Value.IsDisplayNameTheFirstPresence) { sb.Append(@" - ReadOnlySpan current when current.Equals(""").Append(member.Value.DisplayName).Append(@""".AsSpan(), System.StringComparison.Ordinal) => true,"); + ReadOnlySpan current when current.Equals(""").Append(member.Value.DisplayName).Append(@""".AsSpan(), System.StringComparison.Ordinal) => true,"); } } @@ -220,7 +266,8 @@ 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).Append(@").AsSpan(), System.StringComparison.Ordinal) => true,"); + ReadOnlySpan current when current.Equals(nameof(").Append(enumToGenerate.FullyQualifiedName).Append('.').Append(member.Key) + .Append(@").AsSpan(), System.StringComparison.Ordinal) => true,"); } sb.Append(@" @@ -231,6 +278,18 @@ public static bool IsDefined(in ReadOnlySpan name, bool allowMatchingMetad sb.Append(@" + /// + /// 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 [System.Diagnostics.CodeAnalysis.NotNullWhen(true)] @@ -240,6 +299,19 @@ public static bool TryParse( => TryParse(name, out value, false, false);"); sb.Append(@" + /// + /// 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 [System.Diagnostics.CodeAnalysis.NotNullWhen(true)] @@ -250,6 +322,21 @@ public static bool TryParse( => TryParse(name, out value, ignoreCase, false);"); sb.Append(@" + /// + /// 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 + /// 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 [System.Diagnostics.CodeAnalysis.NotNullWhen(true)] @@ -317,7 +404,8 @@ 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(@"), System.StringComparison.OrdinalIgnoreCase): + case string s when s.Equals(nameof(").Append(enumToGenerate.FullyQualifiedName).Append('.').Append(member.Key).Append( + @"), System.StringComparison.OrdinalIgnoreCase): value = ").Append(enumToGenerate.FullyQualifiedName).Append('.').Append(member.Key).Append(@"; return true;"); } @@ -357,6 +445,18 @@ public static bool TryParse( sb.Append(@" #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 [System.Diagnostics.CodeAnalysis.NotNullWhen(true)] @@ -366,6 +466,19 @@ public static bool TryParse( => TryParse(name, out value, false, false);"); sb.Append(@" + /// + /// 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 [System.Diagnostics.CodeAnalysis.NotNullWhen(true)] @@ -378,14 +491,20 @@ public static bool TryParse( sb.Append(@" /// - /// Slower then the , - /// bacause the ReadOnlySpan can't be cached like a string, tho it doesn't allocate memory./> + /// 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 + /// 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 [System.Diagnostics.CodeAnalysis.NotNullWhen(true)] @@ -410,7 +529,8 @@ public static bool TryParse( if (member.Value.DisplayName is not null && member.Value.IsDisplayNameTheFirstPresence) { sb.Append(@" - case ReadOnlySpan current when current.Equals(""").Append(member.Value.DisplayName).Append(@""".AsSpan(), System.StringComparison.OrdinalIgnoreCase): + case ReadOnlySpan current when current.Equals(""").Append(member.Value.DisplayName).Append( + @""".AsSpan(), System.StringComparison.OrdinalIgnoreCase): result = ").Append(enumToGenerate.FullyQualifiedName).Append('.').Append(member.Key).Append(@"; return true;"); } @@ -444,20 +564,22 @@ public static bool TryParse( } "); } - sb.Append(@" + + sb.Append(@" if (ignoreCase) { switch (name) {"); - foreach (var member in enumToGenerate.Names) - { - sb.Append(@" - case ReadOnlySpan current when current.Equals(nameof(").Append(enumToGenerate.FullyQualifiedName).Append('.').Append(member.Key).Append(@").AsSpan(), System.StringComparison.OrdinalIgnoreCase): + foreach (var member in enumToGenerate.Names) + { + sb.Append(@" + case ReadOnlySpan current when current.Equals(nameof(").Append(enumToGenerate.FullyQualifiedName).Append('.').Append(member.Key).Append( + @").AsSpan(), System.StringComparison.OrdinalIgnoreCase): result = ").Append(enumToGenerate.FullyQualifiedName).Append('.').Append(member.Key).Append(@"; return true;"); - } + } - sb.Append(@" + sb.Append(@" case ReadOnlySpan current when ").Append(enumToGenerate.UnderlyingType).Append(@".TryParse(name, out var numericResult): result = (").Append(enumToGenerate.FullyQualifiedName).Append(@")numericResult; return true; @@ -470,15 +592,16 @@ public static bool TryParse( { switch (name) {"); - foreach (var member in enumToGenerate.Names) - { - sb.Append(@" - case ReadOnlySpan current when current.Equals(nameof(").Append(enumToGenerate.FullyQualifiedName).Append('.').Append(member.Key).Append(@").AsSpan(), System.StringComparison.Ordinal): + foreach (var member in enumToGenerate.Names) + { + sb.Append(@" + case ReadOnlySpan current when current.Equals(nameof(").Append(enumToGenerate.FullyQualifiedName).Append('.').Append(member.Key).Append( + @").AsSpan(), System.StringComparison.Ordinal): result = ").Append(enumToGenerate.FullyQualifiedName).Append('.').Append(member.Key).Append(@"; return true;"); - } + } - sb.Append(@" + sb.Append(@" case ReadOnlySpan current when ").Append(enumToGenerate.UnderlyingType).Append(@".TryParse(name, out var numericResult): result = (").Append(enumToGenerate.FullyQualifiedName).Append(@")numericResult; return true; @@ -492,6 +615,13 @@ public static bool TryParse( sb.Append(@" + /// + /// 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() { return new[] @@ -508,6 +638,13 @@ public static bool TryParse( sb.Append(@" + /// + /// 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[] diff --git a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsInChildNamespace.verified.txt b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsInChildNamespace.verified.txt index 5601bf7..19bae67 100644 --- a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsInChildNamespace.verified.txt +++ b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsInChildNamespace.verified.txt @@ -1,4 +1,4 @@ -//------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ // // This code was generated by the NetEscapades.EnumGenerators source generator // @@ -14,6 +14,9 @@ using System; namespace MyTestNameSpace { + /// + /// Extension methods for + /// public static partial class MyEnumExtensions { /// @@ -22,6 +25,14 @@ namespace MyTestNameSpace /// public const int Length = 2; + /// + /// Returns the string representation of the value. + /// If the attribute is decorated with a , 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) => value switch { @@ -30,6 +41,11 @@ namespace MyTestNameSpace _ => 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(MyTestNameSpace.MyEnum value) => value switch { @@ -38,8 +54,22 @@ namespace MyTestNameSpace _ => 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 + /// 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 with the name, false otherwise public static bool IsDefined(string name, bool allowMatchingMetadataAttribute) { return name switch @@ -51,15 +81,23 @@ namespace MyTestNameSpace } #if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 + /// + /// Returns a boolean telling whether an enum with the given name exists in the enumeration + /// + /// 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); /// - /// Slower then the ReadOnlySpan can't be cached like a string, tho it doesn't allocate memory./> + /// Returns a boolean telling whether an enum with the given name exists in the enumeration, + /// or optionally if a member decorated with a + /// with the required name exists. + /// Slower then the overload, but doesn't allocate memory./> /// - /// - /// - /// true if defined, otherwise false + /// 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 with the name, false otherwise public static bool IsDefined(in ReadOnlySpan name, bool allowMatchingMetadataAttribute) { return name switch @@ -71,6 +109,18 @@ namespace MyTestNameSpace } #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 [System.Diagnostics.CodeAnalysis.NotNullWhen(true)] @@ -79,6 +129,19 @@ namespace MyTestNameSpace out 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. + /// 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 [System.Diagnostics.CodeAnalysis.NotNullWhen(true)] @@ -88,6 +151,21 @@ namespace MyTestNameSpace 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 + /// 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 [System.Diagnostics.CodeAnalysis.NotNullWhen(true)] @@ -136,6 +214,18 @@ 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. + /// 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 [System.Diagnostics.CodeAnalysis.NotNullWhen(true)] @@ -144,6 +234,19 @@ namespace MyTestNameSpace out 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. + /// 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 [System.Diagnostics.CodeAnalysis.NotNullWhen(true)] @@ -154,14 +257,20 @@ namespace MyTestNameSpace => TryParse(name, out value, ignoreCase, false); /// - /// Slower then the , - /// bacause the ReadOnlySpan can't be cached like a string, tho it doesn't allocate memory./> + /// 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 + /// 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 [System.Diagnostics.CodeAnalysis.NotNullWhen(true)] @@ -210,6 +319,13 @@ namespace MyTestNameSpace } #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 MyTestNameSpace.MyEnum[] GetValues() { return new[] @@ -219,6 +335,13 @@ namespace MyTestNameSpace }; } + /// + /// 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[] diff --git a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsInGlobalNamespace.verified.txt b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsInGlobalNamespace.verified.txt index 23b92e8..4282d0f 100644 --- a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsInGlobalNamespace.verified.txt +++ b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsInGlobalNamespace.verified.txt @@ -1,4 +1,4 @@ -//------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ // // This code was generated by the NetEscapades.EnumGenerators source generator // @@ -12,6 +12,9 @@ using System; #endif + /// + /// Extension methods for + /// public static partial class MyEnumExtensions { /// @@ -20,6 +23,14 @@ using System; /// public const int Length = 2; + /// + /// Returns the string representation of the value. + /// If the attribute is decorated with a , 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) => value switch { @@ -28,6 +39,11 @@ using System; _ => 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(MyEnum value) => value switch { @@ -36,8 +52,22 @@ using System; _ => 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 + /// 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 with the name, false otherwise public static bool IsDefined(string name, bool allowMatchingMetadataAttribute) { return name switch @@ -49,15 +79,23 @@ using System; } #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); /// - /// Slower then the ReadOnlySpan can't be cached like a string, tho it doesn't allocate memory./> + /// Returns a boolean telling whether an enum with the given name exists in the enumeration, + /// or optionally if a member decorated with a + /// with the required name exists. + /// Slower then the overload, but doesn't allocate memory./> /// - /// - /// - /// true if defined, otherwise false + /// 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 with the name, false otherwise public static bool IsDefined(in ReadOnlySpan name, bool allowMatchingMetadataAttribute) { return name switch @@ -69,6 +107,18 @@ using System; } #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 [System.Diagnostics.CodeAnalysis.NotNullWhen(true)] @@ -77,6 +127,19 @@ using System; out MyEnum 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 [System.Diagnostics.CodeAnalysis.NotNullWhen(true)] @@ -86,6 +149,21 @@ using System; 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 + /// 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 [System.Diagnostics.CodeAnalysis.NotNullWhen(true)] @@ -134,6 +212,18 @@ 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. + /// 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 [System.Diagnostics.CodeAnalysis.NotNullWhen(true)] @@ -142,6 +232,19 @@ using System; out MyEnum 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 [System.Diagnostics.CodeAnalysis.NotNullWhen(true)] @@ -152,14 +255,20 @@ using System; => TryParse(name, out value, ignoreCase, false); /// - /// Slower then the , - /// bacause the ReadOnlySpan can't be cached like a string, tho it doesn't allocate memory./> + /// 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 + /// 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 [System.Diagnostics.CodeAnalysis.NotNullWhen(true)] @@ -208,6 +317,13 @@ using System; } #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 MyEnum[] GetValues() { return new[] @@ -217,6 +333,13 @@ using System; }; } + /// + /// 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[] diff --git a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsInNestedClass.verified.txt b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsInNestedClass.verified.txt index c6b5b39..2688135 100644 --- a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsInNestedClass.verified.txt +++ b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsInNestedClass.verified.txt @@ -1,4 +1,4 @@ -//------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ // // This code was generated by the NetEscapades.EnumGenerators source generator // @@ -14,6 +14,9 @@ using System; namespace MyTestNameSpace { + /// + /// Extension methods for + /// internal static partial class MyEnumExtensions { /// @@ -22,6 +25,14 @@ namespace MyTestNameSpace /// public const int Length = 2; + /// + /// Returns the string representation of the value. + /// If the attribute is decorated with a , 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) => value switch { @@ -30,6 +41,11 @@ namespace MyTestNameSpace _ => 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(MyTestNameSpace.InnerClass.MyEnum value) => value switch { @@ -38,8 +54,22 @@ namespace MyTestNameSpace _ => 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 + /// 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 with the name, false otherwise public static bool IsDefined(string name, bool allowMatchingMetadataAttribute) { return name switch @@ -51,15 +81,23 @@ namespace MyTestNameSpace } #if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 + /// + /// Returns a boolean telling whether an enum with the given name exists in the enumeration + /// + /// 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); /// - /// Slower then the ReadOnlySpan can't be cached like a string, tho it doesn't allocate memory./> + /// Returns a boolean telling whether an enum with the given name exists in the enumeration, + /// or optionally if a member decorated with a + /// with the required name exists. + /// Slower then the overload, but doesn't allocate memory./> /// - /// - /// - /// true if defined, otherwise false + /// 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 with the name, false otherwise public static bool IsDefined(in ReadOnlySpan name, bool allowMatchingMetadataAttribute) { return name switch @@ -71,6 +109,18 @@ namespace MyTestNameSpace } #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 [System.Diagnostics.CodeAnalysis.NotNullWhen(true)] @@ -79,6 +129,19 @@ namespace MyTestNameSpace out 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. + /// 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 [System.Diagnostics.CodeAnalysis.NotNullWhen(true)] @@ -88,6 +151,21 @@ namespace MyTestNameSpace 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 + /// 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 [System.Diagnostics.CodeAnalysis.NotNullWhen(true)] @@ -136,6 +214,18 @@ 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. + /// 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 [System.Diagnostics.CodeAnalysis.NotNullWhen(true)] @@ -144,6 +234,19 @@ namespace MyTestNameSpace out 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. + /// 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 [System.Diagnostics.CodeAnalysis.NotNullWhen(true)] @@ -154,14 +257,20 @@ namespace MyTestNameSpace => TryParse(name, out value, ignoreCase, false); /// - /// Slower then the , - /// bacause the ReadOnlySpan can't be cached like a string, tho it doesn't allocate memory./> + /// 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 + /// 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 [System.Diagnostics.CodeAnalysis.NotNullWhen(true)] @@ -210,6 +319,13 @@ namespace MyTestNameSpace } #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 MyTestNameSpace.InnerClass.MyEnum[] GetValues() { return new[] @@ -219,6 +335,13 @@ namespace MyTestNameSpace }; } + /// + /// 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[] diff --git a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsWithCustomName.verified.txt b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsWithCustomName.verified.txt index f175b6e..8aa93d5 100644 --- a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsWithCustomName.verified.txt +++ b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsWithCustomName.verified.txt @@ -1,4 +1,4 @@ -//------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ // // This code was generated by the NetEscapades.EnumGenerators source generator // @@ -14,6 +14,9 @@ using System; namespace MyTestNameSpace { + /// + /// Extension methods for + /// internal static partial class A { /// @@ -22,6 +25,14 @@ namespace MyTestNameSpace /// public const int Length = 2; + /// + /// Returns the string representation of the value. + /// If the attribute is decorated with a , 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) => value switch { @@ -30,6 +41,11 @@ namespace MyTestNameSpace _ => 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(MyTestNameSpace.MyEnum value) => value switch { @@ -38,8 +54,22 @@ namespace MyTestNameSpace _ => 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 + /// 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 with the name, false otherwise public static bool IsDefined(string name, bool allowMatchingMetadataAttribute) { return name switch @@ -51,15 +81,23 @@ namespace MyTestNameSpace } #if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 + /// + /// Returns a boolean telling whether an enum with the given name exists in the enumeration + /// + /// 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); /// - /// Slower then the ReadOnlySpan can't be cached like a string, tho it doesn't allocate memory./> + /// Returns a boolean telling whether an enum with the given name exists in the enumeration, + /// or optionally if a member decorated with a + /// with the required name exists. + /// Slower then the overload, but doesn't allocate memory./> /// - /// - /// - /// true if defined, otherwise false + /// 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 with the name, false otherwise public static bool IsDefined(in ReadOnlySpan name, bool allowMatchingMetadataAttribute) { return name switch @@ -71,6 +109,18 @@ namespace MyTestNameSpace } #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 [System.Diagnostics.CodeAnalysis.NotNullWhen(true)] @@ -79,6 +129,19 @@ namespace MyTestNameSpace out 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. + /// 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 [System.Diagnostics.CodeAnalysis.NotNullWhen(true)] @@ -88,6 +151,21 @@ namespace MyTestNameSpace 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 + /// 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 [System.Diagnostics.CodeAnalysis.NotNullWhen(true)] @@ -136,6 +214,18 @@ 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. + /// 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 [System.Diagnostics.CodeAnalysis.NotNullWhen(true)] @@ -144,6 +234,19 @@ namespace MyTestNameSpace out 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. + /// 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 [System.Diagnostics.CodeAnalysis.NotNullWhen(true)] @@ -154,14 +257,20 @@ namespace MyTestNameSpace => TryParse(name, out value, ignoreCase, false); /// - /// Slower then the , - /// bacause the ReadOnlySpan can't be cached like a string, tho it doesn't allocate memory./> + /// 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 + /// 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 [System.Diagnostics.CodeAnalysis.NotNullWhen(true)] @@ -210,6 +319,13 @@ namespace MyTestNameSpace } #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 MyTestNameSpace.MyEnum[] GetValues() { return new[] @@ -219,6 +335,13 @@ namespace MyTestNameSpace }; } + /// + /// 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[] diff --git a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsWithCustomNamespace.verified.txt b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsWithCustomNamespace.verified.txt index ab1f43a..6fa1729 100644 --- a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsWithCustomNamespace.verified.txt +++ b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsWithCustomNamespace.verified.txt @@ -1,4 +1,4 @@ -//------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ // // This code was generated by the NetEscapades.EnumGenerators source generator // @@ -14,6 +14,9 @@ using System; namespace A.B { + /// + /// Extension methods for + /// internal static partial class MyEnumExtensions { /// @@ -22,6 +25,14 @@ namespace A.B /// public const int Length = 2; + /// + /// Returns the string representation of the value. + /// If the attribute is decorated with a , 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) => value switch { @@ -30,6 +41,11 @@ namespace A.B _ => 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(MyTestNameSpace.MyEnum value) => value switch { @@ -38,8 +54,22 @@ namespace A.B _ => 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 + /// 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 with the name, false otherwise public static bool IsDefined(string name, bool allowMatchingMetadataAttribute) { return name switch @@ -51,15 +81,23 @@ namespace A.B } #if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 + /// + /// Returns a boolean telling whether an enum with the given name exists in the enumeration + /// + /// 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); /// - /// Slower then the ReadOnlySpan can't be cached like a string, tho it doesn't allocate memory./> + /// Returns a boolean telling whether an enum with the given name exists in the enumeration, + /// or optionally if a member decorated with a + /// with the required name exists. + /// Slower then the overload, but doesn't allocate memory./> /// - /// - /// - /// true if defined, otherwise false + /// 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 with the name, false otherwise public static bool IsDefined(in ReadOnlySpan name, bool allowMatchingMetadataAttribute) { return name switch @@ -71,6 +109,18 @@ namespace A.B } #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 [System.Diagnostics.CodeAnalysis.NotNullWhen(true)] @@ -79,6 +129,19 @@ namespace A.B out 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. + /// 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 [System.Diagnostics.CodeAnalysis.NotNullWhen(true)] @@ -88,6 +151,21 @@ namespace A.B 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 + /// 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 [System.Diagnostics.CodeAnalysis.NotNullWhen(true)] @@ -136,6 +214,18 @@ 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. + /// 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 [System.Diagnostics.CodeAnalysis.NotNullWhen(true)] @@ -144,6 +234,19 @@ namespace A.B out 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. + /// 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 [System.Diagnostics.CodeAnalysis.NotNullWhen(true)] @@ -154,14 +257,20 @@ namespace A.B => TryParse(name, out value, ignoreCase, false); /// - /// Slower then the , - /// bacause the ReadOnlySpan can't be cached like a string, tho it doesn't allocate memory./> + /// 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 + /// 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 [System.Diagnostics.CodeAnalysis.NotNullWhen(true)] @@ -210,6 +319,13 @@ namespace A.B } #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 MyTestNameSpace.MyEnum[] GetValues() { return new[] @@ -219,6 +335,13 @@ namespace A.B }; } + /// + /// 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[] diff --git a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsWithCustomNamespaceAndName.verified.txt b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsWithCustomNamespaceAndName.verified.txt index 004441a..cefe688 100644 --- a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsWithCustomNamespaceAndName.verified.txt +++ b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsWithCustomNamespaceAndName.verified.txt @@ -1,4 +1,4 @@ -//------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ // // This code was generated by the NetEscapades.EnumGenerators source generator // @@ -14,6 +14,9 @@ using System; namespace A.B { + /// + /// Extension methods for + /// internal static partial class C { /// @@ -22,6 +25,14 @@ namespace A.B /// public const int Length = 2; + /// + /// Returns the string representation of the value. + /// If the attribute is decorated with a , 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) => value switch { @@ -30,6 +41,11 @@ namespace A.B _ => 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(MyTestNameSpace.MyEnum value) => value switch { @@ -38,8 +54,22 @@ namespace A.B _ => 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 + /// 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 with the name, false otherwise public static bool IsDefined(string name, bool allowMatchingMetadataAttribute) { return name switch @@ -51,15 +81,23 @@ namespace A.B } #if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 + /// + /// Returns a boolean telling whether an enum with the given name exists in the enumeration + /// + /// 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); /// - /// Slower then the ReadOnlySpan can't be cached like a string, tho it doesn't allocate memory./> + /// Returns a boolean telling whether an enum with the given name exists in the enumeration, + /// or optionally if a member decorated with a + /// with the required name exists. + /// Slower then the overload, but doesn't allocate memory./> /// - /// - /// - /// true if defined, otherwise false + /// 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 with the name, false otherwise public static bool IsDefined(in ReadOnlySpan name, bool allowMatchingMetadataAttribute) { return name switch @@ -71,6 +109,18 @@ namespace A.B } #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 [System.Diagnostics.CodeAnalysis.NotNullWhen(true)] @@ -79,6 +129,19 @@ namespace A.B out 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. + /// 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 [System.Diagnostics.CodeAnalysis.NotNullWhen(true)] @@ -88,6 +151,21 @@ namespace A.B 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 + /// 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 [System.Diagnostics.CodeAnalysis.NotNullWhen(true)] @@ -136,6 +214,18 @@ 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. + /// 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 [System.Diagnostics.CodeAnalysis.NotNullWhen(true)] @@ -144,6 +234,19 @@ namespace A.B out 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. + /// 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 [System.Diagnostics.CodeAnalysis.NotNullWhen(true)] @@ -154,14 +257,20 @@ namespace A.B => TryParse(name, out value, ignoreCase, false); /// - /// Slower then the , - /// bacause the ReadOnlySpan can't be cached like a string, tho it doesn't allocate memory./> + /// 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 + /// 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 [System.Diagnostics.CodeAnalysis.NotNullWhen(true)] @@ -210,6 +319,13 @@ namespace A.B } #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 MyTestNameSpace.MyEnum[] GetValues() { return new[] @@ -219,6 +335,13 @@ namespace A.B }; } + /// + /// 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[] diff --git a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsWithDisplayName.verified.txt b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsWithDisplayName.verified.txt index fcb54fb..896892d 100644 --- a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsWithDisplayName.verified.txt +++ b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsWithDisplayName.verified.txt @@ -1,4 +1,4 @@ -//------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ // // This code was generated by the NetEscapades.EnumGenerators source generator // @@ -14,6 +14,9 @@ using System; namespace MyTestNameSpace { + /// + /// Extension methods for + /// public static partial class MyEnumExtensions { /// @@ -22,6 +25,14 @@ namespace MyTestNameSpace /// public const int Length = 4; + /// + /// Returns the string representation of the value. + /// If the attribute is decorated with a , 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) => value switch { @@ -32,6 +43,11 @@ namespace MyTestNameSpace _ => 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(MyTestNameSpace.MyEnum value) => value switch { @@ -42,8 +58,22 @@ namespace MyTestNameSpace _ => 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 + /// 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 with the name, false otherwise public static bool IsDefined(string name, bool allowMatchingMetadataAttribute) { var isDefinedInDisplayAttribute = false; @@ -74,15 +104,23 @@ namespace MyTestNameSpace } #if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 + /// + /// Returns a boolean telling whether an enum with the given name exists in the enumeration + /// + /// 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); /// - /// Slower then the ReadOnlySpan can't be cached like a string, tho it doesn't allocate memory./> + /// Returns a boolean telling whether an enum with the given name exists in the enumeration, + /// or optionally if a member decorated with a + /// with the required name exists. + /// Slower then the overload, but doesn't allocate memory./> /// - /// - /// - /// true if defined, otherwise false + /// 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 with the name, false otherwise public static bool IsDefined(in ReadOnlySpan name, bool allowMatchingMetadataAttribute) { var isDefinedInDisplayAttribute = false; @@ -90,8 +128,8 @@ namespace MyTestNameSpace { isDefinedInDisplayAttribute = name switch { - ReadOnlySpan current when current.Equals("2nd".AsSpan(), System.StringComparison.Ordinal) => true, - ReadOnlySpan current when current.Equals("4th".AsSpan(), System.StringComparison.Ordinal) => true, + ReadOnlySpan current when current.Equals("2nd".AsSpan(), System.StringComparison.Ordinal) => true, + ReadOnlySpan current when current.Equals("4th".AsSpan(), System.StringComparison.Ordinal) => true, _ => false, }; } @@ -112,6 +150,18 @@ namespace MyTestNameSpace } #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 [System.Diagnostics.CodeAnalysis.NotNullWhen(true)] @@ -120,6 +170,19 @@ namespace MyTestNameSpace out 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. + /// 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 [System.Diagnostics.CodeAnalysis.NotNullWhen(true)] @@ -129,6 +192,21 @@ namespace MyTestNameSpace 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 + /// 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 [System.Diagnostics.CodeAnalysis.NotNullWhen(true)] @@ -221,6 +299,18 @@ 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. + /// 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 [System.Diagnostics.CodeAnalysis.NotNullWhen(true)] @@ -229,6 +319,19 @@ namespace MyTestNameSpace out 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. + /// 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 [System.Diagnostics.CodeAnalysis.NotNullWhen(true)] @@ -239,14 +342,20 @@ namespace MyTestNameSpace => TryParse(name, out value, ignoreCase, false); /// - /// Slower then the , - /// bacause the ReadOnlySpan can't be cached like a string, tho it doesn't allocate memory./> + /// 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 + /// 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 [System.Diagnostics.CodeAnalysis.NotNullWhen(true)] @@ -339,6 +448,13 @@ namespace MyTestNameSpace } #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 MyTestNameSpace.MyEnum[] GetValues() { return new[] @@ -350,6 +466,13 @@ namespace MyTestNameSpace }; } + /// + /// 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[] diff --git a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsWithSameDisplayName.verified.txt b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsWithSameDisplayName.verified.txt index 8eaf9bf..9f6c9be 100644 --- a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsWithSameDisplayName.verified.txt +++ b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsWithSameDisplayName.verified.txt @@ -1,4 +1,4 @@ -//------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ // // This code was generated by the NetEscapades.EnumGenerators source generator // @@ -14,6 +14,9 @@ using System; namespace MyTestNameSpace { + /// + /// Extension methods for + /// public static partial class MyEnumExtensions { /// @@ -22,6 +25,14 @@ namespace MyTestNameSpace /// public const int Length = 4; + /// + /// Returns the string representation of the value. + /// If the attribute is decorated with a , 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) => value switch { @@ -32,6 +43,11 @@ namespace MyTestNameSpace _ => 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(MyTestNameSpace.MyEnum value) => value switch { @@ -42,8 +58,22 @@ namespace MyTestNameSpace _ => 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 + /// 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 with the name, false otherwise public static bool IsDefined(string name, bool allowMatchingMetadataAttribute) { var isDefinedInDisplayAttribute = false; @@ -73,15 +103,23 @@ namespace MyTestNameSpace } #if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 + /// + /// Returns a boolean telling whether an enum with the given name exists in the enumeration + /// + /// 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); /// - /// Slower then the ReadOnlySpan can't be cached like a string, tho it doesn't allocate memory./> + /// Returns a boolean telling whether an enum with the given name exists in the enumeration, + /// or optionally if a member decorated with a + /// with the required name exists. + /// Slower then the overload, but doesn't allocate memory./> /// - /// - /// - /// true if defined, otherwise false + /// 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 with the name, false otherwise public static bool IsDefined(in ReadOnlySpan name, bool allowMatchingMetadataAttribute) { var isDefinedInDisplayAttribute = false; @@ -89,7 +127,7 @@ namespace MyTestNameSpace { isDefinedInDisplayAttribute = name switch { - ReadOnlySpan current when current.Equals("2nd".AsSpan(), System.StringComparison.Ordinal) => true, + ReadOnlySpan current when current.Equals("2nd".AsSpan(), System.StringComparison.Ordinal) => true, _ => false, }; } @@ -110,6 +148,18 @@ namespace MyTestNameSpace } #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 [System.Diagnostics.CodeAnalysis.NotNullWhen(true)] @@ -118,6 +168,19 @@ namespace MyTestNameSpace out 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. + /// 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 [System.Diagnostics.CodeAnalysis.NotNullWhen(true)] @@ -127,6 +190,21 @@ namespace MyTestNameSpace 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 + /// 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 [System.Diagnostics.CodeAnalysis.NotNullWhen(true)] @@ -213,6 +291,18 @@ 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. + /// 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 [System.Diagnostics.CodeAnalysis.NotNullWhen(true)] @@ -221,6 +311,19 @@ namespace MyTestNameSpace out 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. + /// 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 [System.Diagnostics.CodeAnalysis.NotNullWhen(true)] @@ -231,14 +334,20 @@ namespace MyTestNameSpace => TryParse(name, out value, ignoreCase, false); /// - /// Slower then the , - /// bacause the ReadOnlySpan can't be cached like a string, tho it doesn't allocate memory./> + /// 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 + /// 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 [System.Diagnostics.CodeAnalysis.NotNullWhen(true)] @@ -325,6 +434,13 @@ namespace MyTestNameSpace } #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 MyTestNameSpace.MyEnum[] GetValues() { return new[] @@ -336,6 +452,13 @@ namespace MyTestNameSpace }; } + /// + /// 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[] diff --git a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesEnumCorrectly.verified.txt b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesEnumCorrectly.verified.txt index 1c0f79e..e5042c0 100644 --- a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesEnumCorrectly.verified.txt +++ b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesEnumCorrectly.verified.txt @@ -14,6 +14,9 @@ using System; namespace Something.Blah { + /// + /// Extension methods for + /// public static partial class ShortName { /// @@ -22,6 +25,14 @@ namespace Something.Blah /// public const int Length = 2; + /// + /// Returns the string representation of the value. + /// If the attribute is decorated with a , 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) => value switch { @@ -30,6 +41,11 @@ namespace Something.Blah _ => 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(Something.Blah.ShortName value) => value switch { @@ -38,8 +54,22 @@ namespace Something.Blah _ => 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 + /// 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 with the name, false otherwise public static bool IsDefined(string name, bool allowMatchingMetadataAttribute) { return name switch @@ -51,15 +81,23 @@ namespace Something.Blah } #if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 + /// + /// Returns a boolean telling whether an enum with the given name exists in the enumeration + /// + /// 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); /// - /// Slower then the ReadOnlySpan can't be cached like a string, tho it doesn't allocate memory./> + /// Returns a boolean telling whether an enum with the given name exists in the enumeration, + /// or optionally if a member decorated with a + /// with the required name exists. + /// Slower then the overload, but doesn't allocate memory./> /// - /// - /// - /// true if defined, otherwise false + /// 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 with the name, false otherwise public static bool IsDefined(in ReadOnlySpan name, bool allowMatchingMetadataAttribute) { return name switch @@ -71,6 +109,18 @@ namespace Something.Blah } #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 [System.Diagnostics.CodeAnalysis.NotNullWhen(true)] @@ -79,6 +129,19 @@ namespace Something.Blah out 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. + /// 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 [System.Diagnostics.CodeAnalysis.NotNullWhen(true)] @@ -88,6 +151,21 @@ namespace Something.Blah 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 + /// 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 [System.Diagnostics.CodeAnalysis.NotNullWhen(true)] @@ -136,6 +214,18 @@ 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. + /// 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 [System.Diagnostics.CodeAnalysis.NotNullWhen(true)] @@ -144,6 +234,19 @@ namespace Something.Blah out 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. + /// 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 [System.Diagnostics.CodeAnalysis.NotNullWhen(true)] @@ -154,14 +257,20 @@ namespace Something.Blah => TryParse(name, out value, ignoreCase, false); /// - /// Slower then the , - /// bacause the ReadOnlySpan can't be cached like a string, tho it doesn't allocate memory./> + /// 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 + /// 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 [System.Diagnostics.CodeAnalysis.NotNullWhen(true)] @@ -210,6 +319,13 @@ namespace Something.Blah } #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 Something.Blah.ShortName[] GetValues() { return new[] @@ -219,6 +335,13 @@ namespace Something.Blah }; } + /// + /// 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[] diff --git a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFlagsEnumCorrectly.verified.txt b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFlagsEnumCorrectly.verified.txt index a30068e..a2111aa 100644 --- a/tests/NetEscapades.EnumGenerators.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFlagsEnumCorrectly.verified.txt +++ b/tests/NetEscapades.EnumGenerators.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFlagsEnumCorrectly.verified.txt @@ -14,6 +14,9 @@ using System; namespace Something.Blah { + /// + /// Extension methods for + /// public static partial class ShortName { /// @@ -22,6 +25,14 @@ namespace Something.Blah /// public const int Length = 2; + /// + /// Returns the string representation of the value. + /// If the attribute is decorated with a , 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) => value switch { @@ -30,6 +41,13 @@ namespace Something.Blah _ => value.ToString(), }; + /// + /// Determines whether one or more bit fields are set in the current instance. + /// Equivalent to calling value.HasFlag(flag) + /// + /// The value of the instance to investiage + /// The flag to check for + /// true if the fields set in the flag are also set in the current instance; otherwise false. public static bool HasFlag(this Something.Blah.ShortName value, Something.Blah.ShortName flag) => value switch { @@ -37,6 +55,11 @@ namespace Something.Blah _ => (value & flag) != 0, }; + /// + /// 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(Something.Blah.ShortName value) => value switch { @@ -45,8 +68,22 @@ namespace Something.Blah _ => 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 + /// 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 with the name, false otherwise public static bool IsDefined(string name, bool allowMatchingMetadataAttribute) { return name switch @@ -58,15 +95,23 @@ namespace Something.Blah } #if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_1 && !NETCOREAPP1_0 + /// + /// Returns a boolean telling whether an enum with the given name exists in the enumeration + /// + /// 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); /// - /// Slower then the ReadOnlySpan can't be cached like a string, tho it doesn't allocate memory./> + /// Returns a boolean telling whether an enum with the given name exists in the enumeration, + /// or optionally if a member decorated with a + /// with the required name exists. + /// Slower then the overload, but doesn't allocate memory./> /// - /// - /// - /// true if defined, otherwise false + /// 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 with the name, false otherwise public static bool IsDefined(in ReadOnlySpan name, bool allowMatchingMetadataAttribute) { return name switch @@ -78,6 +123,18 @@ namespace Something.Blah } #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 [System.Diagnostics.CodeAnalysis.NotNullWhen(true)] @@ -86,6 +143,19 @@ namespace Something.Blah out 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. + /// 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 [System.Diagnostics.CodeAnalysis.NotNullWhen(true)] @@ -95,6 +165,21 @@ namespace Something.Blah 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 + /// 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 [System.Diagnostics.CodeAnalysis.NotNullWhen(true)] @@ -143,6 +228,18 @@ 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. + /// 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 [System.Diagnostics.CodeAnalysis.NotNullWhen(true)] @@ -151,6 +248,19 @@ namespace Something.Blah out 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. + /// 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 [System.Diagnostics.CodeAnalysis.NotNullWhen(true)] @@ -161,14 +271,20 @@ namespace Something.Blah => TryParse(name, out value, ignoreCase, false); /// - /// Slower then the , - /// bacause the ReadOnlySpan can't be cached like a string, tho it doesn't allocate memory./> + /// 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 + /// 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 [System.Diagnostics.CodeAnalysis.NotNullWhen(true)] @@ -217,6 +333,13 @@ namespace Something.Blah } #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 Something.Blah.ShortName[] GetValues() { return new[] @@ -226,6 +349,13 @@ namespace Something.Blah }; } + /// + /// 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[]