I decorate an existing object with the CreateClassProxyWithTarget method. However, the constructor, and therefore the initialization code, is called twice. I already have a βbuiltβ instance (target). I understand why this is happening, but is there a way to avoid this other than using an empty constructor?
Edit: Here is the code:
First create a proxy:
public static T Create<T>(T i_pEntity) where T : class { object pResult = m_pGenerator.CreateClassProxyWithTarget(typeof(T), new[] { typeof(IEditableObject), typeof(INotifyPropertyChanged) , typeof(IMarkerInterface), typeof(IDataErrorInfo) }, i_pEntity, ProxyGenerationOptions.Default, new BindingEntityInterceptor<T>(i_pEntity)); return (T)pResult; }
I use this, for example, with an object of the following class:
public class KatalogBase : AuditableBaseEntity { public KatalogBase() { Values = new HashedSet<Values>(); Attributes = new HashedSet<Attributes>(); } ... }
If now I call BindingFactory.Create(someKatalogBaseObject); Values and Attributes properties are initialized again.
source share