C # compiler error using typeof (expression <Func <, >>)
The name basically says it all. I implement some logic that parses expressions and uses reflection here and there. To get the overload of a specific generic method that takes a parameter Expression<Func<T, S>>as a parameter, I used the operator typeofto get the correct open common type of this parameter:
typeof(Expression<Func<,>>)
As far as I understand, the use of the operator typeofcan be used to get open common types. However, in this case, the compiler complains that it skips type information from the delegate Func<,>:
Type expected
Is it by specification? And if so, how to get the correct type here? I am using Visual Studio 2013 Update 4 / C # 5 .
Since you can get information on the type or an open generic type or a closed type. You cannot use with a mixture of both. typeoftypeof
Expression<>is an open type, but specifying a type argument Func<,>tries to refer to a private type, so the compiler also wants to specify type arguments Func<,>.
Just use typeof(Expression<>), this is the open type you need.