I have a view model which uses custom attributes such as
public int Id { get; set; }
public string Name { get; set; }
[IsEnumeration(typeof(CaseStatus))]
public string Status { get; set; }
IsEnumeration is a custom attribute which takes an Enumeration superclass as a parameter (actually it takes any type, but that doesn't matter since noone else will be using this)
public class IsEnumerationAttribute : Attribute
{
public Type Enumeration;
public IsEnumerationAttribute(Type enumeration)
{
Enumeration = enumeration;
}
}
What I want is to be able to get the type specified for any parameter. Currently my code looks like this:
public T EnumerationValuesToDisplayNames<T>(T item) where T : new()
{
if (LoggedInUser.IsSuper) return item;
var tProps = typeof (T).GetProperties()
.Where(prop => Attribute
.IsDefined(prop, typeof (IsEnumerationAttribute)));
foreach (var prop in tProps)
{
if (prop.GetValue(item, null) != null)
{
/*
Here I look through all properties with the IsEnumerable attribute.
I want to do something such as:
var type = prop.GetAttribute(item, typeof(IsEnumerable));
var displayName = Enumeration<type>.FromId(prop.GetValue(item, null));
prop.SetValue(item, displayName);
*/
}
}
return item;
}
I hope this makes sense, any help would be greatly appreciated, thanks