System Library Common Framework
Search Results for

    *.Benchmark*,*.Tests*,*.ApiTests*,*.BaseTest*,DelegateJsonConverter,CalleeCancelledRequestException,ClientResponse,ContentType,OutputCachePolicy
    Show / Hide Table of Contents Show / Hide Table of Contents
    NamespaceSystemLibrary.Common.Framework.Extensions SystemLibrary.Common.Framework.Net.dll

    Extension methods for IList of strings

    IListStringExtensions

    public static class IListStringExtensions

    Inheritance
    object
    IListStringExtensions
    Examples
    Arguments
    X

    Methods

    Convert an IList of string to a new List of Enum

    Remarks
    X

    Does not Throw exception Tries to convert data through EnumValue and EnumText if match is found

    public static List<TEnum> ToEnumList<TEnum>(this IList<string> collection) where TEnum : struct, IComparable, IFormattable, IConvertible

    X

    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
    X
    Generic types
    Name Description
    TEnum
    Methods arguments
    Type Name Description
    IList<string> collection
    X
    Type Description
    List<TEnum>

    A new list with 0 or more Enums

    }

    In This Article
    Package: nuget
    Source: github
    Website: System Library Common Framework