Reference passing

S

Shaun

There is a function which in my DLL which is referenced by other C#
projects.

VectorPlane vPlane = new VectorPlane(100.0, 25.0, 65.0, "unbridged,
extensible");

That object can be passed into a function called

int ModifyObject(object obj);


Using reflection, I can call functions which belong to VectorPlane and
change properties in vPlane, etc. Is it possible for me to completely
replace the object, such that vPlane will point to the new object?


Like:
int ModifyObject(object obj)
{
// use reflection to create a new object of type VectorPlane
// change the address of the object that they passed in to
// point to this new object
}

How can one go about doing this? Is this even possible?

Thanks,
Shaun
 
M

Mattias Sjögren

Using reflection, I can call functions which belong to VectorPlane and
change properties in vPlane, etc. Is it possible for me to completely
replace the object, such that vPlane will point to the new object?

Yes, if you change to a ref parameter

int ModifyObject(ref object obj);

To be able to pass in vPlane as an argument to that function you must
declare it as object too

object vPlane = new VectorPlane(100.0, 25.0, 65.0, "unbridged,
extensible");
x.ModifyObject(ref vPlane);


Mattias
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top