WebAug 1, 2024 · public static string GetDescription (this Enum value) { Type type = value.GetType (); string name = Enum.GetName (type, value); if (name != null) { System.Reflection.FieldInfo field = type.GetField (name); if (field != null) { DescriptionAttribute attr = Attribute.GetCustomAttribute (field, typeof … WebWhat I want is given the enum type, produce 2-tuples of enum string value and its description. Value was easy: Array values = System.Enum.GetValues (typeof (FunkyAttributesEnum)); foreach (int value in values) Tuple.Value = Enum.GetName (typeof (FunkyAttributesEnum), value); But how do I get description attribute's value, to …
c# - Get Enum from Description attribute - Stack Overflow
WebJul 21, 2014 · Finding an enum value by its Description Attribute. I have a generic extension method which gets the Description attribute from an Enum: enum Animal { [Description ("")] NotSet = 0, [Description ("Giant Panda")] GiantPanda = 1, [Description ("Lesser Spotted … WebMar 30, 2024 · Figure 1 explanation: so as you can see there are 2 extension methods, First one, GetEnumDescription () is for "type enum" to fetch "description" of an enum values. Second, extension method GetEnumValueByDescription () which is for "type string" to fetch the "enum value" by their description. Go ahead and create an enum as shown in … candy jem fan art
c# - Getting attributes of Enum
WebApr 16, 2024 · Description of Enumeration Parameters. It looks better. But not good enough. Our controller has a method that takes an enum as a parameter: C#. public Task ExecuteOperation ( int id, OperationType type) Let's see how the Swagger UI shows this: As you can see, there is no description of the enum members here. WebApr 6, 2024 · In C#, an enum (short for "enumeration") is a value type that consists of a set of named constants. An enum can be defined using the enum keyword, followed by the name of the enum and a list of comma-separated identifiers representing the named constants. This article and code example teach you how to use enums in C# and .NET. WebFollowing is the method in C# to get the enum value by int. /// /// Method to get enumeration value from int value. /// /// /// public T GetEnumValue (int intValue) where T : struct, IConvertible { if (!typeof (T).IsEnum) { throw new Exception ("T must be … candy jelly bean bag