2

May be a basic question:

I went through this,

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

And looked at the explanation in form of comments.

   // 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.

What is wrapper for object in this context? Why is this used? How to unwrap this?

leppie
  • 115,091
  • 17
  • 196
  • 297
SHRI
  • 2,406
  • 6
  • 32
  • 48
  • Possible duplicate of: http://stackoverflow.com/questions/889160/what-is-a-wrapper-class – default locale Feb 21 '13 at 10:10
  • To answer your question on how to unwrap. You can use the CreateInstanceAndUnwrap method instead for this. – Evelie Feb 21 '13 at 10:12
  • 4
    @defaultlocale: I don't think that's a duplicate. His question is specific about that method. The question you linked is a question about wrapper classes in general. Completely different. – Daniel Hilgarth Feb 21 '13 at 10:12
  • @DanielHilgarth `What is wrapper for object in C#? Why this is used?` I believe OP can find answers to these questions there. Maybe OP should concentrate on `how to unwrap this` particular object from this particular method part. – default locale Feb 21 '13 at 10:15
  • 2
    @defaultlocale: You shouldn't always take the questions too literal. He *obviously* is asking his question in the context of `AppDomain.CreateInstance`. – Daniel Hilgarth Feb 21 '13 at 10:16

1 Answers1

3

You can see a wrapper as a 'c' or 'c++' pointer to another object. You can unwrap it using the Unwrap method:

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

See this link for more info.

default locale
  • 13,035
  • 13
  • 56
  • 62
Stefano Altieri
  • 4,550
  • 1
  • 24
  • 41