Search Results for

    Show / Hide Table of Contents
    View Source

    Class Enum<T>

    Provides utility methods for handling enumerations.

    Inheritance
    object
    Namespace: Umbraco.Cms.Core
    Assembly: Umbraco.Core.dll
    Syntax
    public static class Enum<T> where T : struct
    Type Parameters
    Name Description
    T
    Remarks

    Taken from http://damieng.com/blog/2010/10/17/enums-better-syntax-improved-performance-and-tryparse-in-net-3-5

    Methods

    View Source

    CastOrNull(int)

    Casts an integer to the enum type, returning null if the integer is not a valid value.

    Declaration
    public static T? CastOrNull(int value)
    Parameters
    Type Name Description
    int value

    The integer value to cast.

    Returns
    Type Description
    T?

    The enum value, or null if the integer is not valid.

    View Source

    GetName(T)

    Gets the name of the specified enum value.

    Declaration
    public static string? GetName(T value)
    Parameters
    Type Name Description
    T value

    The enum value.

    Returns
    Type Description
    string

    The name of the value, or null if not found.

    View Source

    GetNames()

    Gets all names defined in the enumeration.

    Declaration
    public static string[] GetNames()
    Returns
    Type Description
    string[]

    An array containing all enum names.

    View Source

    GetValues()

    Gets all values defined in the enumeration.

    Declaration
    public static IEnumerable<T> GetValues()
    Returns
    Type Description
    IEnumerable<T>

    An enumerable containing all enum values.

    View Source

    IsDefined(int)

    Determines whether the specified integer is a defined value in the enumeration.

    Declaration
    public static bool IsDefined(int value)
    Parameters
    Type Name Description
    int value

    The integer value to check.

    Returns
    Type Description
    bool

    true if the value is defined; otherwise, false.

    View Source

    IsDefined(string)

    Determines whether the specified string is a defined name in the enumeration.

    Declaration
    public static bool IsDefined(string value)
    Parameters
    Type Name Description
    string value

    The string value to check.

    Returns
    Type Description
    bool

    true if the name is defined; otherwise, false.

    View Source

    IsDefined(T)

    Determines whether the specified value is defined in the enumeration.

    Declaration
    public static bool IsDefined(T value)
    Parameters
    Type Name Description
    T value

    The enum value to check.

    Returns
    Type Description
    bool

    true if the value is defined; otherwise, false.

    View Source

    Parse(string, bool)

    Parses the string representation of an enum value.

    Declaration
    public static T Parse(string value, bool ignoreCase = false)
    Parameters
    Type Name Description
    string value

    The string to parse.

    bool ignoreCase

    If true, case is ignored during parsing.

    Returns
    Type Description
    T

    The parsed enum value.

    Exceptions
    Type Condition
    ArgumentException

    The string is not a valid enum name.

    View Source

    ParseOrNull(string)

    Parses the string representation of an enum value, returning null if parsing fails.

    Declaration
    public static T? ParseOrNull(string value)
    Parameters
    Type Name Description
    string value

    The string to parse.

    Returns
    Type Description
    T?

    The parsed enum value, or null if parsing failed.

    View Source

    TryParse(string, out T, bool)

    Tries to parse the string representation of an enum value.

    Declaration
    public static bool TryParse(string value, out T returnValue, bool ignoreCase = false)
    Parameters
    Type Name Description
    string value

    The string to parse.

    T returnValue

    When this method returns, contains the parsed value if successful.

    bool ignoreCase

    If true, case is ignored during parsing.

    Returns
    Type Description
    bool

    true if parsing succeeded; otherwise, false.

    • View Source
    In this article
    Back to top Copyright © 2016-present Umbraco
    Generated by DocFX