Search Results for

    Show / Hide Table of Contents

    Class EnumUtil

    A helper class for handling enums

    Inheritance
    System.Object
    EnumUtil
    Inherited Members
    System.Object.ToString()
    System.Object.Equals(System.Object)
    System.Object.Equals(System.Object, System.Object)
    System.Object.ReferenceEquals(System.Object, System.Object)
    System.Object.GetHashCode()
    System.Object.GetType()
    System.Object.MemberwiseClone()
    Namespace: ImageVault.Common.Lib
    Assembly: ImageVault.Common.dll
    Syntax
    public static class EnumUtil

    Methods

    GetDisplayName(Enum)

    Gets the DisplayName from the enum

    Declaration
    public static string GetDisplayName(Enum value)
    Parameters
    Type Name Description
    System.Enum value

    The System.Enum value to get the DisplayName from

    Returns
    Type Description
    System.String

    The displayName of the enum value

    Exceptions
    Type Condition
    System.ArgumentException

    If the enum misses the System.ComponentModel.DisplayNameAttribute

    GetEnumInfo(Enum)

    Gets the System.Reflection.FieldInfo for the supplied enum value

    Declaration
    public static FieldInfo GetEnumInfo(Enum value)
    Parameters
    Type Name Description
    System.Enum value

    The System.Enum to get the info for

    Returns
    Type Description
    System.Reflection.FieldInfo

    The found System.Reflection.FieldInfo

    Parse(Type, String)

    Parses the supplied string as the supplied enum type

    Declaration
    public static object Parse(Type type, string stringToParse)
    Parameters
    Type Name Description
    System.Type type

    The System.Type of enum to parse as

    System.String stringToParse

    The string to parse

    Returns
    Type Description
    System.Object

    The parsed enum value

    Remarks

    Also supports flag enums with | separating the different values

    Exceptions
    Type Condition
    System.ArgumentNullException

    If stringToParse is null.

    ParseValidEnum(Type, String)

    Parses the supplied enum value

    Declaration
    public static object ParseValidEnum(Type type, string value)
    Parameters
    Type Name Description
    System.Type type

    The System.Type of enum to parse

    System.String value

    The string value of the enum

    Returns
    Type Description
    System.Object

    The found enum value or null if no matchin enum was found.

    Exceptions
    Type Condition
    System.ArgumentNullException

    If type is null.

    ParseValidEnum(Type, String, Object)

    Parses the supplied enum value

    Declaration
    public static object ParseValidEnum(Type type, string value, object defaultValue)
    Parameters
    Type Name Description
    System.Type type

    The System.Type of enum to parse

    System.String value

    The string value of the enum

    System.Object defaultValue

    The value to return if parsing was not successful

    Returns
    Type Description
    System.Object

    The found enum value or null if no matchin enum was found.

    Exceptions
    Type Condition
    System.ArgumentNullException

    If type is null.

    ToString(Object)

    Returns a System.String that represents the supplied enumValue.

    Declaration
    public static string ToString(object enumValue)
    Parameters
    Type Name Description
    System.Object enumValue

    The enum value to parse

    Returns
    Type Description
    System.String

    A System.String that represents the supplied enumValue.

    Remarks

    Flag values are separated by |

    Exceptions
    Type Condition
    System.ArgumentNullException

    If enumValue is null.

    In This Article
    Back to top (c) Meriworks 2002-2022