Hi Guys,
I have an interface contract that looks like this:
ICollection<FooBar> FindByPredicate(Expression<Func<FooBar,bool>> predicate);
ICollection<Foo> FindByPredicate(Expression<Func<Foo,bool>> predicate);
ICollection<Bar> FindByPredicate(Expression<Func<Bar,bool>> predicate);
Foo and Bar are concrete classes which inherit from the FooBar abstract class.
Now, im running into problems when trying to invoke these methods:
var foo = myService.FindByPredicate(f => f.UserId == 1);
It's getting "Ambigious invocation" errors, which kind of makes sense, because the property "UserId" exists on the abstract "FooBar" type (and thus exists on Foo and Bar as well).
So, how can i overcome this?
I like the look of my interface (overloaded predicate methods) as from an intellisense point of view from the calling code, there is only one method name.
Why do i have my interface like that? Well, some scenarios i wish to return only "Foo" or "Bar", other times i need a mixed bag, hence i need to return the abstract type - make sense?
Anyway, onto the obvious question - is there a way around this? (other than renaming my interface methods)? (and thus compromising the simplicity)