I have the following function
public static T Translate<T>(T entity) { .... }
Now, if T is en IEnumerable <> I want to have a different behavior, so I made a second function
public static IEnumerable<T> Translate<T>(IEnumerable<T> entities) { .... }
When I call him like that
IEnumerable<string> test = new List<string>().AsEnumerable(); Translate(test);
However, when I call him like that
Func<IEnumerable<string>> func = () => new List<string>().AsEnumerable(); Translate(func.Invoke())
He goes to the first. Why is this happening and what is the best design to solve this problem?
UPDATE
I am creating a new example with a problem
static void Main(string[] args) { Func<IEnumerable<string>> stringFunction = () => new List<string>().AsEnumerable(); InvokeFunction(ExtendFunction(stringFunction)); } private static T Convert<T>(T text) where T : class { return null; } private static IEnumerable<T> Convert<T>(IEnumerable<T> text) { return null; } private static Func<T> ExtendFunction<T>(Func<T> func) where T : class { return () => Convert(func.Invoke()); } private static T InvokeFunction<T>(Func<T> func) { return func.Invoke(); }
The first function calls invoken now, when I expect the second to be called.
source share