diff --git a/CHANGELOG.md b/CHANGELOG.md index 0cea386..6c70744 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## v1.0.17 +fix doc +add TryParseFast ## v1.0.16 fix doc warning add GeneratedCodeAttribute attrbiute diff --git a/README.md b/README.md index d44cca0..a81a03d 100644 --- a/README.md +++ b/README.md @@ -45,12 +45,13 @@ For example: ```csharp /// - /// Provides extension methods for operations related to the UserTypeTest enumeration. - /// + /// Provides extension methods for operations related to the enumeration. + /// + [GeneratedCodeAttribute("Supernova.Enum.Generators", null)] public static class UserTypeTestEnumExtensions { /// - /// Provides a dictionary that maps values to their corresponding display names. + /// Provides a dictionary that maps values to their corresponding display names. /// public static readonly ImmutableDictionary DisplayNamesDictionary = new Dictionary { @@ -61,7 +62,7 @@ For example: }.ToImmutableDictionary(); /// - /// Provides a dictionary that maps values to their corresponding descriptions. + /// Provides a dictionary that maps values to their corresponding descriptions. /// public static readonly ImmutableDictionary DisplayDescriptionsDictionary = new Dictionary { @@ -72,11 +73,11 @@ For example: }.ToImmutableDictionary(); /// - /// Converts the enumeration value to its string representation. + /// Converts the enumeration value to its string representation. /// - /// The enumeration value. + /// The enumeration value. /// The default value to return if the enumeration value is not recognized. - /// The string representation of the value. + /// The string representation of the value. public static string ToStringFast(this UnitTests.UserTypeTest states, string defaultValue = null) { return states switch @@ -89,10 +90,10 @@ For example: } /// - /// Checks if the specified value is defined. + /// Checks if the specified value is defined. /// - /// The value to check. - /// True if the value is defined; otherwise, false. + /// The value to check. + /// True if the value is defined; otherwise, false. public static bool IsDefinedFast(UnitTests.UserTypeTest states) { return states switch @@ -105,10 +106,10 @@ For example: } /// - /// Checks if the specified string represents a defined value. + /// Checks if the specified string represents a defined value. /// - /// The string representing a value. - /// True if the string represents a defined value; otherwise, false. + /// The string representing a value. + /// True if the string represents a defined value; otherwise, false. public static bool IsDefinedFast(string states) { return states switch @@ -121,11 +122,11 @@ For example: } /// - /// Converts the enumeration value to its display string. + /// Converts the enumeration value to its display string. /// - /// The enumeration value. + /// The enumeration value. /// The default value to return if the enumeration value is not recognized. - /// The display string of the value. + /// The display string of the value. public static string ToDisplayFast(this UnitTests.UserTypeTest states, string defaultValue = null) { return states switch @@ -138,11 +139,11 @@ For example: } /// - /// Gets the description of the enumeration value. + /// Gets the description of the enumeration value. /// - /// The enumeration value. + /// The enumeration value. /// The default value to return if the enumeration value is not recognized. - /// The description of the value. + /// The description of the value. public static string ToDescriptionFast(this UnitTests.UserTypeTest states, string defaultValue = null) { return states switch @@ -155,9 +156,9 @@ For example: } /// - /// Retrieves an array of all enumeration values. + /// Retrieves an array of all enumeration values. /// - /// An array containing all enumeration values. + /// An array containing all enumeration values. public static UnitTests.UserTypeTest[] GetValuesFast() { return new[] @@ -169,9 +170,9 @@ For example: } /// - /// Retrieves an array of strings containing the names of all enumeration values. + /// Retrieves an array of strings containing the names of all enumeration values. /// - /// An array of strings containing the names of all enumeration values. + /// An array of strings containing the names of all enumeration values. public static string[] GetNamesFast() { return new[] @@ -183,14 +184,46 @@ For example: } /// - /// Gets the length of the enumeration. + /// Gets the length of the enumeration. /// - /// The length of the enumeration. + /// The length of the enumeration. public static int GetLengthFast() { return 3; } + + /// + /// Try parse a string to value. + /// + /// The string representing a value. + /// The enum parse result. + /// True if the string is parsed successfully; otherwise, false. + public static bool TryParseFast(string states, out UnitTests.UserTypeTest result) + { + switch (states) + { + case "Men": + { + result = UnitTests.UserTypeTest.Men; + return true; + } + case "Women": + { + result = UnitTests.UserTypeTest.Women; + return true; + } + case "None": + { + result = UnitTests.UserTypeTest.None; + return true; + } + default: { + result = default; + return false; + } + } + } } ``` @@ -211,6 +244,9 @@ var names = UserTypeTestEnumExtensions.GetNamesFast(); //string[] var values = UserTypeTestEnumExtensions.GetValuesFast(); //UserType[] var length = UserTypeTestEnumExtensions.GetLengthFast(); //3 + +var menString = "Men"; +var result = UserTypeTestEnumExtensions.TryParseFast(menString, out var enumValue); ``` If you had trouble using UserTypeTestEnumExtensions and the IDE did not recognize it. This is an IDE problem and you need to restart the IDE once. diff --git a/Supernova.Enum.Generators/Supernova.Enum.Generators.csproj b/Supernova.Enum.Generators/Supernova.Enum.Generators.csproj index 7aeda7b..e103b43 100644 --- a/Supernova.Enum.Generators/Supernova.Enum.Generators.csproj +++ b/Supernova.Enum.Generators/Supernova.Enum.Generators.csproj @@ -6,16 +6,16 @@ true false false - 1.0.16 - 1.0.16 - 1.0.16 + 1.0.17 + 1.0.17 + 1.0.17 README.md icon.png true - v1.0.16 - fix doc warning - add GeneratedCodeAttribute attrbiute + v1.0.17 + fix doc + add TryParseFast latest