Published: 2020.05.11
Category: C#
Description attribute value
Library allows to get description content from DescriptionAttribute.
Currently it retrieve value from following elements:
-
Property
-
Field
-
Method
-
Enum
Usage example:
typeof(TestClass).GetPropertyDescription("PropertyName"); typeof(TestClass).GetFieldDescription("FieldName"); typeof(TestClass).GetMethodDescription("Method1"); testClass.Enum.GetDescription();
all methods:
- extension method Description for enum
- extension method Description for Type
- extension method PropertyDescription for Property
- extension method MethodDescription for Method
- extension method FieldDescription for Field
Description is not existing
Method will throw an exception if we will try to get value from item which doesn’t have exception set up. You could use DescriptionExists* methods to validate before using. Methods:
- extension method DescriptionExists for enum
- extension method DescriptionExists for Type
- extension method PropertyDescriptionExists for Property
- extension method MethodDescriptionExists for Method
- extension method FieldDescriptionExists for Field