Search Results for

    Show / Hide Table of Contents

    Class EnumHelper

    A set of functions and extensions for helping to work with an System.Enum

    Inheritance
    System.Object
    EnumHelper
    Inherited Members
    System.Object.Equals(System.Object)
    System.Object.Equals(System.Object, System.Object)
    System.Object.GetHashCode()
    System.Object.GetType()
    System.Object.MemberwiseClone()
    System.Object.ReferenceEquals(System.Object, System.Object)
    System.Object.ToString()
    Namespace: LemonEdge.Utils
    Assembly: Utils.dll
    Syntax
    public static class EnumHelper

    Methods

    GetShortFlaggedValues<T>(T)

    Returns all enum values that total the specified enum value

    Declaration
    public static IEnumerable<T> GetShortFlaggedValues<T>(this T value)
        where T : Enum
    Parameters
    Type Name Description
    T value

    The value to return as a combination of smaller bitwise values

    Returns
    Type Description
    System.Collections.Generic.IEnumerable<T>

    All enum values that total the specified enum value

    Type Parameters
    Name Description
    T

    The type of enum

    Remarks

    For example:

    public enum MyEnum : short 
    {
        Left = 1,
        Right = 2,
        Up = 4,
        Down = 8,
    
        Vertical = 12
    }
    
    public class Example
    {
        public void GetVertical()
        {
            var vertical = MyEnum.Vertical;
            foreach (var dir in vertical.GetShortFlaggedValues())
            {
                switch (dir)
                {
                    //matches these two
                    case MyEnum.Up: break;
                    case MyEnum.Down: break;
    
                    default:
                        //no other value is enumerated
                        break;
                }
            }
        }
    }

    GetValues(Type)

    Returns an array of all items within a specified Enum

    Declaration
    public static Array GetValues(Type t)
    Parameters
    Type Name Description
    System.Type t

    The enum to enumerate all values of

    Returns
    Type Description
    System.Array

    An enumeration of all items within a specified Enum

    GetValues<T>()

    Returns an enumeration of all items within a specified Enum

    Declaration
    public static IEnumerable<T> GetValues<T>()
        where T : Enum
    Returns
    Type Description
    System.Collections.Generic.IEnumerable<T>

    An enumeration of all items within a specified Enum

    Type Parameters
    Name Description
    T

    The enum to enumerate all values of

    GetValuesWithTooltips(Type)

    Returns an EnumWrapper<T> for each enum value in the specifid enum t type

    Declaration
    public static IEnumerable<EnumWrapper> GetValuesWithTooltips(Type t)
    Parameters
    Type Name Description
    System.Type t

    The type of the enum

    Returns
    Type Description
    System.Collections.Generic.IEnumerable<EnumWrapper>

    An EnumWrapper<T> for each enum value in the specifid enum t type

    GetValuesWithTooltips(Type, Type)

    Returns an EnumWrapper<T> for each enum value in the specifid enum t type

    Declaration
    public static IEnumerable<EnumWrapper> GetValuesWithTooltips(Type t, Type propType)
    Parameters
    Type Name Description
    System.Type t

    The type of the enum

    System.Type propType

    Optionally converts each enum value to a different type such as an int for compatability in the ui

    Returns
    Type Description
    System.Collections.Generic.IEnumerable<EnumWrapper>

    An EnumWrapper<T> for each enum value in the specifid enum t type

    GetValuesWithTooltips<T>()

    Returns an EnumWrapper<T> for each enum value in the specifid enum type

    Declaration
    public static IEnumerable<EnumWrapper<T>> GetValuesWithTooltips<T>()
        where T : Enum
    Returns
    Type Description
    System.Collections.Generic.IEnumerable<EnumWrapper<T>>

    An EnumWrapper<T> for each enum value in the specifid enum type

    Type Parameters
    Name Description
    T

    The type of enum

    Parse(Type, String)

    Parses the specified string representation of an enum value and returns if it was valid, and the value

    Declaration
    public static (bool Valid, object Result) Parse(Type enumType, string value)
    Parameters
    Type Name Description
    System.Type enumType

    The type of enum to parse

    System.String value

    The value to parse

    Returns
    Type Description
    System.ValueTuple<System.Boolean, System.Object>

    A tuple indicating if the parse was valid, and the value if it was

    Parse<T>(String)

    Parses an enum string representation and returns the enum value

    Declaration
    public static T Parse<T>(string value)
        where T : struct, Enum
    Parameters
    Type Name Description
    System.String value

    The string representation of an enum value to parse

    Returns
    Type Description
    T

    The enum value

    Type Parameters
    Name Description
    T

    The enum value

    Exceptions
    Type Condition
    System.ArgumentOutOfRangeException

    If the value can not be parsed an error is thrown

    ParseAsShortID<T>(Guid, out T)

    Parses the given guid that holds the equivelant of a short value representing a value in the specified enum T type

    Declaration
    public static bool ParseAsShortID<T>(this Guid id, out T intID)
        where T : struct, Enum
    Parameters
    Type Name Description
    System.Guid id

    The short guid to try to parse and convert into an enum value

    T intID

    If the guid was correctly parsed into an enum value this is the value returned

    Returns
    Type Description
    System.Boolean

    True if the guid was valid and could be converted to the specified enum type

    Type Parameters
    Name Description
    T

    The type of the enum to retrieve from the specified guid short value

    See Also
    LemonEdge.Utils.EnumHelper.ToShortGuid(System.Int32)

    ToShortGuid<T>(T)

    Returns the value of an enum as a guid. This is used by LemonEdge for enum values that can also be represented by custom items holding a unique ID, such as images ImageType

    Declaration
    public static Guid ToShortGuid<T>(this T i)
        where T : Enum
    Parameters
    Type Name Description
    T i

    The value of an enum to be converted to a guid equivelant

    Returns
    Type Description
    System.Guid

    The value of an enum as a guid. This is used by LemonEdge for enum values that can also be represented by custom items holding a unique ID, such as images ImageType

    Type Parameters
    Name Description
    T

    The enum type

    See Also
    ParseAsShortID<T>(Guid, out T)
    In This Article
    Back to top © LemonTree Software Ltd. All rights reserved.