TaylorMichaelL wrote: | | Finally note that the generic method approach that you specified won't work because the return value of a function is not considered to be part of its signature. |
|
That's not the reason it won't work.
The main reason it won't work is that the creation of a concrete method from the generic (and selection of which of those concrete method to call) must be done at compile time (actually JIT time), while we won't know the type we need to create until runtime.
Similarly, we have the problem of how would we declare the return type. We'd need a function like:
public T CastDown ( object value ) { /// blah blah blah return (COMPANY)value;
else /// blah blah blah return (TRUST)value;
else /// etc
}
But one method can't have multiple different return types.
I guess the OP just had a basic misunderstanding of generics:
They are a single method which adapts at run-time, but a directive to the compiler to produce multiple methods at compile time.
|