C# – Castle.DynamicProxy2 and Adding a Property at Run Time


I am using Castle.DynamicProxy2 and I am instantiating my proxy as such:

private static T GenerateProxy()
    ArrayList addtlInterfaces = new ArrayList();

    addtlInterfaces.Add(typeof (INotifyPropertyChanged));
    addtlInterfaces.Add(typeof (EntityStatus));

    object entityProxy = ProxyGenerator.CreateClassProxy(typeof(T), 
                                                          addtlInterfaces.ToArray(typeof(Type)) as Type[],
                                                          new IInterceptor[] { new LazyInterceptor() });

    return (T)entityProxy;

My interface of IEntityStatus looks like such:

public interface  IEntityStatus
    bool IsDirty
    { get; set;}

I need to be able to use that property during run time so that when my DTO has a property changed event the event could set the DTO to dirty. However because it is an interface and has no explicit implementation I am at a loss as to how to do this. Creating a delegate for the get and set method is an option I would like to avoid. So is there another way to achieve what I am looking to achieve?

I realize I could set up a collection of all my active DTOs and when the property changed event fires on one of the DTOs I could update that collection to show that this particular DTO is dirty, but I would really like for this information to be a part of the proxied DTO for pure syntactic ease.

Look forward to responses!

Best Solution

I dont know how you handle the INotifyPropertyChanged but I'd use mixin for both interfaces, having one subscribed to another's event. Is that a viable solution?