I have the following method:
public TResult Get<TGenericType, TResult>()
where TGenericType : SomeGenericType<TResult>
where TResult : IConvertible {
//...code that uses TGenericType...
//...code that sets someValue...
return (TResult) someValue;
}
Right now, a user of this method has to use it like this:
//notice the duplicate int type specification
int number = Get<SomeGenericType<int>, int>();
Why do I have to specify TResult in the method defintion? The compiler already knows TResult since I specified it in TGenericType. Ideally (if the C# compiler was a little smarter), my method would look like this:
public TResult Get<TGenericType>()
where TGenericType : SomeGenericType<TResult>
where TResult : IConvertible {
//...code that uses TGenericType...
//...code that sets someValue...
return (TResult) someValue;
}
So the user could just simply use it like this:
//much cleaner
int number = Get<SomeGenericType<int>>();
Is there any way to do what I want to do?