Type propertyType = nestedProperty.PropertyType;
var targetType = IsNullableType(propertyType) ?
Nullable.GetUnderlyingType(propertyType) : propertyType;
GetPredicateTemp'<'T , targetType> ("storage");
Here on passing targetType giving error targetType is a variable but is used like a type. targettype returns Int64 how can I pass this type , I need to return the lambda expression of this type only.
my question is different.. Here see the method, I need to pass two types T1,T2..In place of T2 , want to pass targetType
~ public static Expression<Func<T1, T2>> GetPredicateTemp<T1, T2>(string propName)
where T1 : UserEntity
{
string[] props = propName.Split('.');
Type t1 = typeof(T1);
PropertyInfo propertyInfo = t1.GetProperty(props[0]);
PropertyInfo nestedProperty = propertyInfo.PropertyType.GetProperty(props[1]);
var parameter = Expression.Parameter(typeof(T1), "t");
MemberExpression expBody = Expression.Property(parameter, propertyInfo.Name);
expBody = Expression.Property(expBody, nestedProperty.Name);
var predicateNEW = Expression.Lambda<Func<T1, T2>>(expBody, new ParameterExpression[] { parameter });
return predicateNEW;
}