I am trying to make a custom data annotation attribute with a simple bool result, if the property have the data annotation, then perform an action. My objective is to make an array with all the properties that have the Filter dataanotation to later make a DropDownListFor in view with that information.
public class Foo
{
public string property1 { get; set; }
[Filter]
public string property2 { get; set; }
}
Then somewhere in the code:
IList<PropertyInfo> properties = typeof(Foo).GetProperties().ToList();
ArrayList propertiesThatCanBeFiltered = new ArrayList();
foreach (var propertyInfo in properties)
{
if (propertyInfo.Attributes("Filter").Exists)
{
propertiesThatCanBeFiltered.Add(propertyInfo.Name);
}
}