How do you access the Description property on either a const or a property, i.e.,
public static class Group
{
[Description( \"Specified parent-child rel
Here is a helper class I am using for processing custom attributes in .NET
public class AttributeList : List
{
///
/// Gets a list of custom attributes
///
///
///
public static AttributeList GetCustomAttributeList(ICustomAttributeProvider propertyInfo)
{
var result = new AttributeList();
result.AddRange(propertyInfo.GetCustomAttributes(false).Cast());
return result;
}
///
/// Finds attribute in collection by its type
///
///
///
public T FindAttribute() where T : Attribute
{
return (T)Find(x => typeof(T).IsAssignableFrom(x.GetType()));
}
public bool IsAttributeSet() where T : Attribute
{
return FindAttribute() != null;
}
}
Also unit tests for MsTest showing how to use this class
[TestClass]
public class AttributeListTest
{
private class TestAttrAttribute : Attribute
{
}
[TestAttr]
private class TestClass
{
}
[TestMethod]
public void Test()
{
var attributeList = AttributeList.GetCustomAttributeList(typeof (TestClass));
Assert.IsTrue(attributeList.IsAttributeSet());
Assert.IsFalse(attributeList.IsAttributeSet());
Assert.IsInstanceOfType(attributeList.FindAttribute(), typeof(TestAttrAttribute));
}
}
http://www.kozlenko.info/2010/02/02/getting-a-list-of-custom-attributes-in-net/