G
Guest
Hi,
I have a bunch of object derived from the same base class. They all share
the same constructor with some parameters. Now, instead of using a large
switch() statement where I call every single Object by itself, I'd like to
assign a reference to the class type and call it later without knowing the
derived type.
Example:
class BaseA {
public BaseA (int aParam) {...}
}
class DerivedA {
public DerivedA(int aParam) : BaseA (aParam){ ... }
}
class DerivedB {
public DerivedB(int aParam) : BaseA (aParam){ ... }
}
and now
Something a = DerivedA;
switch(type)
{
1: a = DerivedA; break;
2: a = DerivedB; break;
}
BaseA instance = new a(5);
Is this possible? The actual parameter list is very long, so it would be
cool to do it later.
Even better: can I create get the Type by string (due some reflection
feature or something)?
Thanks
Doc
I have a bunch of object derived from the same base class. They all share
the same constructor with some parameters. Now, instead of using a large
switch() statement where I call every single Object by itself, I'd like to
assign a reference to the class type and call it later without knowing the
derived type.
Example:
class BaseA {
public BaseA (int aParam) {...}
}
class DerivedA {
public DerivedA(int aParam) : BaseA (aParam){ ... }
}
class DerivedB {
public DerivedB(int aParam) : BaseA (aParam){ ... }
}
and now
Something a = DerivedA;
switch(type)
{
1: a = DerivedA; break;
2: a = DerivedB; break;
}
BaseA instance = new a(5);
Is this possible? The actual parameter list is very long, so it would be
cool to do it later.
Even better: can I create get the Type by string (due some reflection
feature or something)?
Thanks
Doc