I need some guidance on how the best way of adding interceptors to my project. I use Fluent NHibernate and Castle in my project and below is and example of what I would like to accomplish.
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>();
}
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:
// Add an interceptor that loads the value into this property
[Detail]
public virtual string Heading { get; set; }
public Home() { }
}
What is the best approach to solve this?