Question

I want to write a method with signature Expression<Func<T, bool>> Foo<T>(). My class U inherits from T. I want to include U-specific processing in this delegate. The problem is, T can't be implicitly converted to U. Is there any way I can access U-specific properties in this method?

Complication: I also have type V : T which I want to be handled, so I can't just take advantage of variance by replacing T with U in the signature.

Was it helpful?

Solution 2

I ended up using separate overloads: (), (myVar) where T : U, and (myvar, myvar2) where T : V. That did the trick and I lucked out because each parameter is an app value that corresponds with an entity property.

OTHER TIPS

A simple approach is to define an interface which both T and U inherit(Use it) from it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top