我正在使用CreateClassProxyWithTarget
方法装饰现有对象。但是,构造函数和初始化代码被调用两次。我已经有一个“构造”实例(目标)。我明白为什么发生这种情况,但有没有办法避免它,除了使用空的构造函数?如何避免动态代理:: CreateClassProxyWithTarget代理的双重构造?
编辑:下面是一些代码:
首先创建代理:现在
public class KatalogBase : AuditableBaseEntity
{
public KatalogBase()
{
Values = new HashedSet<Values>();
Attributes = new HashedSet<Attributes>();
}
...
}
如果我:
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;
}
我用这个例子与下面的类的对象请致电BindingFactory.Create(someKatalogBaseObject);
Values
和Attributes
属性再次被初始化。
你能有一些代码,显示你所遇到的问题详细点吗? –
@KrzysztofKoźmic我用一些代码更新了我的问题,它显示了问题。 – Belvasis