2013-02-21 36 views
2

可能是一個基本的問題:什麼是使用AppDomain.CreateInstance時的實例包裝?

我通過這一去,

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

什麼是在這種情況下對象的包裝?爲什麼使用這個?如何解開這個?

+0

可能的重複:http://stackoverflow.com/questions/889160/what-is-a-wrapper-class – 2013-02-21 10:10:35

+0

回答你的問題如何解開。您可以使用CreateInstanceAndUnwrap方法代替它。 – Evelie 2013-02-21 10:12:08

+4

@defaultlocale:我不認爲這是重複的。他的問題是關於該方法的具體問題。你所關聯的問題一般是關於包裝類的問題。完全不同。 – 2013-02-21 10:12:20

回答

3

你可以看到一個封裝器作爲'c'或'C++'指向另一個對象。 可以使用Unwrap方法解開它:

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

更多信息,請參見this link

相關問題