Reputation: 4208
I have a question. I have a class and interface for it, so in class I have 3 methods that looks similar and those are:
public CurrentsFlagAnalysis GetCurrentsFlag(DateTime startDateTime, DateTime endDateTime)
{
//some code
}
CurrentsFlagAnalysis ICurrentService<CurrentsFlagAnalysis>.GetCurrentsFlag(DateTime startDateTime, DateTime endDateTime, byte id)
{
//some code
}
List<CurrentsFlagAnalysis> ICurrentService<List<CurrentsFlagAnalysis>>.GetCurrentsFlag(DateTime startDateTime, DateTime endDateTime, byte id)
{
//some cone
}
And interface looks like:
public interface ICurrentService <out TCurrent>
{
TCurrent GetCurrentsFlag(DateTime startDateTime, DateTime endDateTime, byte id);
CurrentsFlagAnalysis GetCurrentsFlag(DateTime startDateTime, DateTime endDateTime);
}
The idea is to use those two methods with same name and same parameters but different return type similar to overload, but i came across the problem when i call this method for example:
public Task<List<CurrentsFlagAnalysis>> GetCurrentsFlagAsync(DateTime startDateTime, DateTime endDateTime, byte id)
{
return Task.Run(() => GetCurrentsFlag(startDateTime, endDateTime, id));
}
From Compile time:
error CS1501: No overload for method 'GetCurrentsFlag' takes 3 arguments
and Visual studio sends me a message of ambiguous invocation and possible argument null exception;
I am getting ambiguous invocation implement error, I know i should use some sort of explicit implementation, but don't know hot to bite it.
And Another thing is this thing safe, should I just rename method and forget that idea.
Upvotes: 0
Views: 601
Reputation: 239824
Even from within the same class, once you've made methods be explicit interface implementations, you have to call them via a reference to the interface:
return Task.Run(() => ((ICurrentService<CurrentsFlagAnalysis>)this).GetCurrentsFlag(
startDateTime,
endDateTime,
id));
Upvotes: 2