I'm building a class at runtime and creating objects of that.
After that, I've several objects of this generated class.
So, I'd like to proxy these objects:
IInterceptor[] interceptors = new IInterceptor[1];
interceptors[0] = new Interceptors.IEditableObjectInterceptor<object>();
return DynamicExtensions.proxyGenerator.CreateClassProxyWithTarget(baseType, target, options, interceptors);
When I perform CreateClassProxyWithTarget
it chrashes dumping me:
Can not instantiate proxy of class: DynamicDigitalInput.
Could not find a parameterless constructor.
So, the message is clear. However, I've tried the next:
System.Reflection.ConstructorInfo cInfo = baseType.GetConstructor(new Type[] { });
Assert.That(cInfo != null);
var constructor = baseType.GetConstructor(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic,null, Type.EmptyTypes, null);
Assert.That(constructor != null);
object d = Activator.CreateInstance(baseType, new object[] {});
Assert.That(d != null);
And it's work well. So I can get default constructors and instantiate a DynamicDigitalInput
class object.
Where's the problem?
Aucun commentaire:
Enregistrer un commentaire