Show / Hide Table of Contents

Class EnumExtension

Extensions for enums

Inheritance
System.Object
EnumExtension
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.ToString()
System.Object.ReferenceEquals(System.Object, System.Object)
Namespace: StoneCo.Framework.Extension
Assembly: cs.temp.dll.dll
Syntax
public static class EnumExtension

Methods

GetDescription(Enum)

Get the enum description. To get the description, the enum must be decorated with the description attribute.

[System.ComponentModel.Description("Your Description")]
Declaration
public static string GetDescription(this Enum value)
Parameters
Type Name Description
System.Enum value

Enum object type of enum

Returns
Type Description
System.String

String with the description decorated in the enum.

Examples

Brand enum used in this example.

Example to get the description.

public class EnumDescriptionSample
{
    public void GetVisaPaymentSchemeKey()
    {
        var paymentSchemeKey = GetDescriptionOfBrand(Brand.Visa);

        // paymentSchemeKey value is "fagxbcet".
    }

    public string GetDescriptionOfBrand(Brand brand) => brand.GetDescription();
}

GetName<TEnum>(Enum)

Get the enum name.

Declaration
public static string GetName<TEnum>(this Enum value)
    where TEnum : struct
Parameters
Type Name Description
System.Enum value

Enum object type of enum

Returns
Type Description
System.String

String with name of the enum.

Type Parameters
Name Description
TEnum

Enum type provider.

Examples

Brand enum used in this example.

public enum Brand
{
    Visa = 1,
    Master = 2,
    Amex = 3,
    Elo = 4,
    Hiper = 5
}

Example to get the name.

public class EnumNameSample
{
    public void GetName()
    {
        var masterEnum = Brand.Master;
        var name = masterEnum.GetName<Brand>();

        // name value is "Master".
    }
}
Exceptions
Type Condition
System.ArgumentException

If typeof TEnum is different of Enum struct, an exception is thrown with message 'Type provided must be an Enum.'.

Back to top Generated by DocFX