0
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;
    }
Preeti
  • 421
  • 5
  • 14
  • Edit your question, clear the code, copy and paste it in fresh. Then highlight the code block and hit the `{}` button to format it as a code block – Damien_The_Unbeliever May 22 '20 at 13:44
  • `targetType` is a variable, but you are using it as a type name – Sergey Berezovskiy May 22 '20 at 13:46
  • how can I pass two types T1,T2 in generic while calling the function? T2 should be of targetType – Preeti May 22 '20 at 17:53
  • Problem solved by using **object** type as second parameter as below Expression conversion = Expression.Convert(expBody, typeof(object)); Expression> predicate = Expression.Lambda>(conversion, new ParameterExpression[] { parameter }); – Preeti Jun 13 '20 at 16:49

0 Answers0