#nullable enable
using
System;
using
System.Diagnostics.CodeAnalysis;
using
System.Globalization;
#pragma warning disable CS1591 // publicly visible type or member must be documented
namespace
EnumClassDemo
{
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute(
"Raiqub.Generators.EnumUtilities"
,
"1.6.0.0"
)]
public
static
partial
class
ColorsFactory
{
/// <summary>
/// Converts the string representation of the name or numeric value of one or more enumerated constants to
/// an equivalent enumerated object. The return value indicates whether the conversion succeeded.
/// </summary>
/// <param name="name">The case-sensitive string representation of the enumeration name or underlying value to convert.</param>
/// <param name="comparisonType">One of the enumeration values that specifies how the strings will be compared.</param>
/// <param name="result">
/// When this method returns, result contains an object of type Colors whose value is represented by value
/// if the parse operation succeeds. If the parse operation fails, result contains the default value of the
/// underlying type of Colors. Note that this value need not be a member of the Colors enumeration.
/// </param>
/// <returns><c>true</c> if the value parameter was converted successfully; otherwise, <c>false</c>.</returns>
/// <exception cref="ArgumentException"><paramref name="comparisonType"/> is not a <see cref="StringComparison"/> value.</exception>
public
static
bool
TryParse(
[NotNullWhen(
true
)]
string
? name,
StringComparison comparisonType,
out
Colors result)
{
switch
(name)
{
case
{ } s when s.Equals(nameof(Colors.None), comparisonType):
result = Colors.None;
return
true
;
case
{ } s when s.Equals(nameof(Colors.Red), comparisonType):
result = Colors.Red;
return
true
;
case
{ } s when s.Equals(nameof(Colors.Green), comparisonType):
result = Colors.Green;
return
true
;
case
{ } s when s.Equals(nameof(Colors.Blue), comparisonType):
result = Colors.Blue;
return
true
;
case
{ } s when TryParseNumeric(s, comparisonType,
out
int
val):
result = (Colors)val;
return
true
;
default
:
return
Enum.TryParse(name,
out
result);
}
}
/// <summary>
/// Converts the string representation of the name or numeric value of one or more enumerated constants to
/// an equivalent enumerated object. The return value indicates whether the conversion succeeded.
/// </summary>
/// <param name="name">The case-sensitive string representation of the enumeration name or underlying value to convert.</param>
/// <param name="result">
/// When this method returns, result contains an object of type Colors whose value is represented by value
/// if the parse operation succeeds. If the parse operation fails, result contains the default value of the
/// underlying type of Colors. Note that this value need not be a member of the Colors enumeration.
/// </param>
/// <returns><c>true</c> if the value parameter was converted successfully; otherwise, <c>false</c>.</returns>
public
static
bool
TryParse(
[NotNullWhen(
true
)]
string
? name,
out
Colors result)
{
switch
(name)
{
case
nameof(Colors.None):
result = Colors.None;
return
true
;
case
nameof(Colors.Red):
result = Colors.Red;
return
true
;
case
nameof(Colors.Green):
result = Colors.Green;
return
true
;
case
nameof(Colors.Blue):
result = Colors.Blue;
return
true
;
case
{ } s when TryParseNumeric(s, StringComparison.Ordinal,
out
int
val):
result = (Colors)val;
return
true
;
default
:
return
Enum.TryParse(name,
out
result);
}
}
/// <summary>
/// Converts the string representation of the name or numeric value of one or more enumerated constants to
/// an equivalent enumerated object. The return value indicates whether the conversion succeeded.
/// </summary>
/// <param name="name">The case-sensitive string representation of the enumeration name or underlying value to convert.</param>
/// <param name="result">
/// When this method returns, result contains an object of type Colors whose value is represented by value
/// if the parse operation succeeds. If the parse operation fails, result contains the default value of the
/// underlying type of Colors. Note that this value need not be a member of the Colors enumeration.
/// </param>
/// <returns><c>true</c> if the value parameter was converted successfully; otherwise, <c>false</c>.</returns>
public
static
bool
TryParseIgnoreCase(
[NotNullWhen(
true
)]
string
? name,
out
Colors result)
{
return
TryParse(name, StringComparison.OrdinalIgnoreCase,
out
result);
}
/// <summary>
/// Converts the string representation of the name or numeric value of one or more enumerated constants to
/// an equivalent enumerated object.
/// </summary>
/// <param name="name">The case-sensitive string representation of the enumeration name or underlying value to convert.</param>
/// <returns>
/// Contains an object of type Colors whose value is represented by value if the parse operation succeeds.
/// If the parse operation fails, result contains <c>null</c> value.
/// </returns>
public
static
Colors? TryParse(
string
? name)
{
return
TryParse(name,
out
Colors result) ? result :
null
;
}
/// <summary>
/// Converts the string representation of the name or numeric value of one or more enumerated constants to
/// an equivalent enumerated object.
/// </summary>
/// <param name="name">The case-sensitive string representation of the enumeration name or underlying value to convert.</param>
/// <returns>
/// Contains an object of type Colors whose value is represented by value if the parse operation succeeds.
/// If the parse operation fails, result contains <c>null</c> value.
/// </returns>
public
static
Colors? TryParseIgnoreCase(
string
? name)
{
return
TryParse(name, StringComparison.OrdinalIgnoreCase,
out
Colors result) ? result :
null
;
}
/// <summary>
/// Converts the string representation of the name or numeric value of one or more enumerated constants to
/// an equivalent enumerated object.
/// </summary>
/// <param name="name">The case-sensitive string representation of the enumeration name or underlying value to convert.</param>
/// <param name="comparisonType">One of the enumeration values that specifies how the strings will be compared.</param>
/// <returns>
/// Contains an object of type Colors whose value is represented by value if the parse operation succeeds.
/// If the parse operation fails, result contains <c>null</c> value.
/// </returns>
/// <exception cref="ArgumentException"><paramref name="comparisonType"/> is not a <see cref="StringComparison"/> value.</exception>
public
static
Colors? TryParse(
string
? name, StringComparison comparisonType)
{
return
TryParse(name, comparisonType,
out
Colors result) ? result :
null
;
}
/// <summary>
/// Converts the string representation of the value associated with one enumerated constant to
/// an equivalent enumerated object. The return value indicates whether the conversion succeeded.
/// </summary>
/// <param name="enumMemberValue">The value as defined with <see cref="System.Runtime.Serialization.EnumMemberAttribute"/>.</param>
/// <param name="comparisonType">One of the enumeration values that specifies how the strings will be compared.</param>
/// <param name="result">
/// When this method returns, result contains an object of type Colors whose value is represented by value
/// if the parse operation succeeds. If the parse operation fails, result contains the default value of the
/// underlying type of Colors. Note that this value need not be a member of the Colors enumeration.
/// </param>
/// <returns><c>true</c> if the value parameter was converted successfully; otherwise, <c>false</c>.</returns>
/// <exception cref="ArgumentException"><paramref name="comparisonType"/> is not a <see cref="StringComparison"/> value.</exception>
public
static
bool
TryParseFromEnumMemberValue(
[NotNullWhen(
true
)]
string
? enumMemberValue,
StringComparison comparisonType,
out
Colors result)
{
switch
(enumMemberValue)
{
case
{ } s when s.Equals(
"This should be never seen"
, comparisonType):
result = Colors.None;
return
true
;
case
{ } s when s.Equals(nameof(Colors.Red), comparisonType):
result = Colors.Red;
return
true
;
case
{ } s when s.Equals(nameof(Colors.Green), comparisonType):
result = Colors.Green;
return
true
;
case
{ } s when s.Equals(nameof(Colors.Blue), comparisonType):
result = Colors.Blue;
return
true
;
default
:
result =
default
;
return
false
;
}
}
/// <summary>
/// Converts the string representation of the value associated with one enumerated constant to
/// an equivalent enumerated object. The return value indicates whether the conversion succeeded.
/// </summary>
/// <param name="enumMemberValue">The value as defined with <see cref="System.Runtime.Serialization.EnumMemberAttribute"/>.</param>
/// <param name="result">
/// When this method returns, result contains an object of type Colors whose value is represented by value
/// if the parse operation succeeds. If the parse operation fails, result contains the default value of the
/// underlying type of Colors. Note that this value need not be a member of the Colors enumeration.
/// </param>
/// <returns><c>true</c> if the value parameter was converted successfully; otherwise, <c>false</c>.</returns>
public
static
bool
TryParseFromEnumMemberValue([NotNullWhen(
true
)]
string
? enumMemberValue,
out
Colors result)
{
return
TryParseFromEnumMemberValue(enumMemberValue, StringComparison.Ordinal,
out
result);
}
/// <summary>
/// Converts the string representation of the value associated with one enumerated constant to
/// an equivalent enumerated object.
/// </summary>
/// <param name="enumMemberValue">The value as defined with <see cref="System.Runtime.Serialization.EnumMemberAttribute"/>.</param>
/// <param name="comparisonType">One of the enumeration values that specifies how the strings will be compared.</param>
/// <returns>
/// Contains an object of type Colors whose value is represented by value if the parse operation succeeds.
/// If the parse operation fails, result contains a null value.
/// </returns>
/// <exception cref="ArgumentException"><paramref name="comparisonType"/> is not a <see cref="StringComparison"/> value.</exception>
public
static
Colors? TryParseFromEnumMemberValue(
string
? enumMemberValue, StringComparison comparisonType)
{
return
TryParseFromEnumMemberValue(enumMemberValue, comparisonType,
out
Colors result) ? result :
null
;
}
/// <summary>
/// Converts the string representation of the value associated with one enumerated constant to
/// an equivalent enumerated object.
/// </summary>
/// <param name="enumMemberValue">The value as defined with <see cref="System.Runtime.Serialization.EnumMemberAttribute"/>.</param>
/// <returns>
/// Contains an object of type Colors whose value is represented by value if the parse operation succeeds.
/// If the parse operation fails, result contains a null value.
/// </returns>
public
static
Colors? TryParseFromEnumMemberValue(
string
? enumMemberValue)
{
return
TryParseFromEnumMemberValue(enumMemberValue, StringComparison.Ordinal,
out
Colors result) ? result :
null
;
}
/// <summary>Retrieves an array of the values of the constants in the Colors enumeration.</summary>
/// <returns>An array that contains the values of the constants in Colors.</returns>
public
static
Colors[] GetValues()
{
return
new
[]
{
Colors.None,
Colors.Red,
Colors.Green,
Colors.Blue,
};
}
/// <summary>Retrieves an array of the names of the constants in Colors enumeration.</summary>
/// <returns>A string array of the names of the constants in Colors.</returns>
public
static
string
[] GetNames()
{
return
new
[]
{
nameof(Colors.None),
nameof(Colors.Red),
nameof(Colors.Green),
nameof(Colors.Blue),
};
}
private
static
bool
TryParseNumeric(
string
name,
StringComparison comparisonType,
out
int
result)
{
switch
(comparisonType)
{
case
StringComparison.CurrentCulture:
case
StringComparison.CurrentCultureIgnoreCase:
return
int
.TryParse(name, NumberStyles.Integer, NumberFormatInfo.CurrentInfo,
out
result);
case
StringComparison.InvariantCulture:
case
StringComparison.InvariantCultureIgnoreCase:
case
StringComparison.Ordinal:
case
StringComparison.OrdinalIgnoreCase:
return
int
.TryParse(name, NumberStyles.Integer, NumberFormatInfo.InvariantInfo,
out
result);
default
:
return
int
.TryParse(name,
out
result);
}
}
}
}