M
marc
hi there,
i try to do a little generic style of programing in c#. the situation
is like this:
class MyObj1
{
}
class MyObj2 : MyClass1
{
}
......
void EnsureObjectExists(ref MyObj1 myObj)
{
if (myObj == null)
{
Type myObjType = typeof(myObj);
myObj = myObjType.CreateInstance();
}
}
....
MyObj1 obj1 = null;
MyObj2 obj2 = null;
EnsureObjectExists(obj1);
EnsureObjectExists(obj2);
Do you guys have an idea how to do something like this? Maybe it isn't
possible at all but hopefully it is ;-)
Cheers,
Marc
i try to do a little generic style of programing in c#. the situation
is like this:
class MyObj1
{
}
class MyObj2 : MyClass1
{
}
......
void EnsureObjectExists(ref MyObj1 myObj)
{
if (myObj == null)
{
Type myObjType = typeof(myObj);
myObj = myObjType.CreateInstance();
}
}
....
MyObj1 obj1 = null;
MyObj2 obj2 = null;
EnsureObjectExists(obj1);
EnsureObjectExists(obj2);
Do you guys have an idea how to do something like this? Maybe it isn't
possible at all but hopefully it is ;-)
Cheers,
Marc