T
Tino Donderwinkel
Hi,
Currently I have the the following methods in my class;
public Circle LoadCircle(int a) {
Circle result = new Circle();
...
return result;
}
public Cube LoadCube(int a) {
Cube result = new Cube();
...
return result;
}
I want to make a Dynamic Method 'Load' in stead of the two methods I
currently have. I tried stuff like this;
public T Load<T>(int a) {
// here, result is determined to be either a Circle or a Cube
// triedstuff like this, but that obviously doesn't work: switch
(typeof(T)) { case (typeof(Circle)): break; case (typeof(Cube)): break;}
return result;
}
Problems I run into is that there is no conversion between types 'T' and
Circle/Cube. This can be fixed by returning an 'object' and casting it on
the other side. But I do not want to do that.
Furthermore, the switch statement I use won't let me use typeof(Cube) etc.
in the case constructor. This can be done with multiple 'if' statements, but
that's a 'dirty' solution.
Is there a way to solve this?
Tino Donderwinkel
Exchange Server MVP
Currently I have the the following methods in my class;
public Circle LoadCircle(int a) {
Circle result = new Circle();
...
return result;
}
public Cube LoadCube(int a) {
Cube result = new Cube();
...
return result;
}
I want to make a Dynamic Method 'Load' in stead of the two methods I
currently have. I tried stuff like this;
public T Load<T>(int a) {
// here, result is determined to be either a Circle or a Cube
// triedstuff like this, but that obviously doesn't work: switch
(typeof(T)) { case (typeof(Circle)): break; case (typeof(Cube)): break;}
return result;
}
Problems I run into is that there is no conversion between types 'T' and
Circle/Cube. This can be fixed by returning an 'object' and casting it on
the other side. But I do not want to do that.
Furthermore, the switch statement I use won't let me use typeof(Cube) etc.
in the case constructor. This can be done with multiple 'if' statements, but
that's a 'dirty' solution.
Is there a way to solve this?
Tino Donderwinkel
Exchange Server MVP