Let's say I'm working with generic function :
public interface IFoo
{
Type Type;
TValue Read<TValue>();
}
public class Foo : IFoo {}
var f = new Foo();
I'd like to write :
var value = f.Read<f.Type>();
but this gives error :
f is a variable but is used like a type
I could write conditionals :
object value;
if (f.Type == typeof(bool))
{
value = f.Read<bool>();
}
if (f.Type == typeof(byte))
{
value = f.Read<byte>();
}
...
but this doesn't really work because it's verbose , may be incomplete if I don't know in advance all possible types , and value is an object instead of the type.
Is there a solution ?