I have an abstract baseclass with a collection of details IList that is automapped with fnh. After it has been populated with the correct values i would like to set some properties with reflection on the my class that inherits the abstract baseclass. I have tried to accomplish this in the constructor of my abstract baseclass but obviously my Details collection is empty when the occurs so my question is, what is the recommended way of doing this?
public abstract class ContentItem {
public virtual int? Id { get; set; }
public virtual string Name { get; set; }
public virtual IList<Detail> Details { get; private set; }
protected ContentItem() {
Details = new List<Detail>();
// When the code hit this point my collection is empty
}
protected virtual object GetDetail(string detailName) {
// Some logic to get the value of a specific detail from the details collection
}
protected virtual void SetDetail<T>(string detailName, T value, T defaultValue) where T : class {
// Some logic to set the value of a specific detail from the details collection
}
}
public class Home : ContentItem {
// This is how I add properties to my ContentItems today
public virtial string Heading { get { return GetDetail("Heading") as string; } set { SetDetail("Heading", value) } }
// This is how I would like to do:
// Get all properties with the DetailAttribute, get the correct value from the details collection and set this property with reflection
[Detail]
public virtual string Heading { get; set; }
public Home() { }
}