Reference passing

  • Thread starter Thread starter Shaun
  • Start date Start date
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
 
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
 
Back
Top