I am having some problems passing a reference to an object that has a common type. I found a way by creating an “Object” and passing a link to it, not the original, but it seems to me that it smells a bit. Is there a better way here or do I need to live with it?
I understand the first mistake, but the second eludes me.
public static T Foo<T>(ref T Bar)
{
T Result;
Result = (T)ModifyObject (ref Bar);
Result = (T)ModifyObject (ref ((Object)Bar) );
Object Tmp = Bar;
Result = (T)ModifyObject (ref Tmp) );
return Result;
}
public static Object DoSomthing(ref Object Obj) {
Object Result = Activator.CreateInstance (Obj.GetType ())
}
DoSomething is not generic because it uses recursion where the type of Obj can change. I tried to distract from the use of reflection to name its general version, although perhaps this would be better for publication.
source
share