Generic method with inferred generic arguments?

If the return type has to remain Func then the method has to stay generic. You will have to specify the types at compile-time. That's the thing - although PropertyInfo knows the types, that information is only available at execution time, whereas the compiler needs to know the type information in order to check that you're using the value properly, etc.It can't possibly know what the execution-time values of the properties will be.

If you could change the return type to just Expression then you could create an Expression with the appropriate types at execution time, but just return it as an Expression. You wouldn't be able to use the return value in a compile-time type-safe way without casting, but it may be helpful...

Yeah I think thats my only alternative. Can't decide whether id rather cast an Expression or pass in the Ts hmmmm. Thanks :) – Andrew Bullock May 7 '09 at 16:12.

You are not passing any argument to the function that is of that type. You could try something like this: public static Expression> BuildGet (TObj obj, TProperty property) { ... } which would allow the compiler to infer the types of TObj and TProperty but that would mean you would have to refactor your method as you are using the PropertyInfo parameter currently.

Yeah I know that's the problem, I'm looking for a solution :) I take it that means there isn't one :( – Andrew Bullock May 7 '09 at 14:49 You can't pass TProperty, it requires that you have an instance. – Stefan Steinegger May 7 '09 at 14:55.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions