Maybe I\'m overworked, but this isn\'t compiling (CS0411). Why?
interface ISignatur
{
Type Type { get; }
}
interface IAccess where
Kirk's answer is right on. As a rule, you're not going to have any luck with type inference when your method signature has fewer types of parameters than it has generic type parameters.
In your particular case, it seems you could possibly move the T
type parameter to the class level and then get type inference on your Get
method:
class ServiceGate
{
public IAccess Get(S sig) where S : ISignatur
{
throw new NotImplementedException();
}
}
Then the code you posted with the CS0411 error could be rewritten as:
static void Main()
{
// Notice: a bit more cumbersome to write here...
ServiceGate service = new ServiceGate();
// ...but at least you get type inference here.
IAccess access = service.Get(new Signatur());
}