Although less elegant then Elisha's solution, but it works also :)
Your attribute:
[AttributeUsage(AttributeTargets.All, AllowMultiple=false)]
class RequiredAttribute : System.Attribute
{
public string Name {get; set; }
public RequiredAttribute(string name)
{
this.Name = name;
}
public RequiredAttribute()
{
this.Name = "";
}
}
Some class:
class Class1
{
[Required]
public string Address1 { get; set; }
public string Address2 { get; set; }
[Required]
public string Address3 { get; set; }
}
Usage:
Class1 c = new Class1();
RequiredAttribute ra = new RequiredAttribute();
Type class1Type = c.GetType();
PropertyInfo[] propInfoList = class1Type.GetProperties();
foreach (PropertyInfo p in propInfoList)
{
object[] a = p.GetCustomAttributes(true);
foreach (object o in a)
{
if (o.GetType().Equals(ra.GetType()))
{
richTextBox1.AppendText(p.Name + " ");
}
}
}