I have following interface That I am implementing
interface IReport <TOutput>
{
List<TOutput> GenerateReport<TInput>(TInput input);
}
In my implementation of this function
I want the output be FeederPerformanceErrorEntry type and input type be Tuple<int, int, bool>
What I am doing wrong ?
public List<FeederPerformanceErrorEntry> GenerateReport< FeederPerformanceErrorEntry , Tuple<int, int, bool> >(Tuple<int, int, bool> tuple)
Thanks
That’s not how generic methods work. If you have a generic interface, you can say that your class that implements that interface is not generic and has some specific type parameters.
But you can’t do the same for generic methods. Those always have to work for any type (or any type that satisfies specified constraints, if you have them). Although “work” here may mean “throw an exception”.
So, you could implement that method like this:
But if you want to do that, you don’t actually need generic method. It would be better if you changed the interface (if you can) to:
And then implement the class as:
If you are able to create the report from several different input types, you can always implement the interface several times: