Hi,
I am having some troubles passing a reference to an object which is of generic type. I have found a way around by creating a 'Object' and passing a reference to that rather than the original - but it seems to smell a bit to me. Is there a better way here or do I have to live with it?
I understand the first error but the second eludes me.
public static T Foo<T>(ref T Bar)
{
T Result;
// Next line gives
// cannot convert from 'ref T' to 'ref object'
Result = (T)ModifyObject (ref Bar);
// Next line gives
// A ref or out argument must be an assignable variable
Result = (T)ModifyObject (ref ((Object)Bar) );
// Works
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 as it uses recursion where the type of Obj can change. I was trying to stick away from using reflection to call a generic version of it, although on posting maybe it would be a better option?