NamespaceSystemLibrary.Common.Net.Extensions
Extension methods for IList of strings
IListStringExtensions
public static class IListStringExtensions
Inheritance
System.Object
IListStringExtensions
Extension methods for IList of strings
Convert an IList of string to a new List of Enum
Does not Throw exception Tries to convert data through EnumValue and EnumText if match is found
Example:
enum Cars
{
Car1,
[EnumValue("Second car value")]
Car2,
[EnumText("Third Car Display Text")]
Car3,
[EnumText("Fourth Car Display Text")]
Car4
}
var list = new List<string> { null, "", "SECOND CAR VALUE", "car4", "fourth car display text"};
var enums = list.ToEnumList<Cars>();
// enums[0] == Car1, null becomes the default value
// enums[1] == Car1, empty string becomes the default value
// enums[2] == Car2, case insensitive match
// enums[3] == Car4, case insensitive match
// enums[4] == Car4, case insensitive match
Name | Description |
---|---|
TEnum |
Type | Name | Description |
---|---|---|
System.Collections.Generic.IList<System.String> | collection |
Type | Description |
---|---|
System.Collections.Generic.List<TEnum> | A new list with 0 or more Enums |
}