Friday, January 28, 2011

Reflection to pull description attribute for class


//get description from attribute on class
private static string GetDescription(Type type)
{
return (from v in type.GetCustomAttributes( typeof(System.ComponentModel.DescriptionAttribute), true)
select ((System.ComponentModel.DescriptionAttribute)v).Description).FirstOrDefault();
}


[Description("Users description!")]
public class MyClass
{
}