使用AppDomain.CreateInstance时,实例的包装器是什么?

时间:2013-02-21 10:08:11

标签: c# .net appdomain

可能是一个基本问题:

我经历了这个,

secondDomain.CreateInstance("AssemblyA", "AssemblyA.Demo", true,
    System.Reflection.BindingFlags.CreateInstance, null, 
    new object[] { 7, 3 }, null, null);

以评论的形式看待解释。

   // Returns:
    //     An object that is a wrapper for the new instance specified by typeName. The
    //     return value needs to be unwrapped to access the real object.

MSDN:AppDomain.CreateInstance Method

在这种情况下,对象的包装是什么?这是为什么用的?如何解开这个?

1 个答案:

答案 0 :(得分:3)

您可以将包装器看作指向另一个对象的“c”或“c ++”指针。 您可以使用Unwrap方法解包它:

MyType testObj = (MyType) obj.Unwrap();

有关详细信息,请参阅this link