1
lstReport=lstReport.Where(o=>DateTime.Parse(o.Field)==DateTime.Parse(o.FieldValue));
//I am creating above statement dynamically like this
var variable = Expression.Variable(typeof(Report));
foreach (SQWFilterConstraint oFC in oFilter.LstFilterConstraint) //using this collection I am making dynamic query
{
Expression ExprLeft =Expression.Property(variable, oFC.Field);
MethodInfo methodDateTimeParse = typeof(DateTime).GetMethod("Parse", newType[] { typeof(string) });
var methodParam = Expression.Parameter(typeof(string), oFC.FieldValue);
Expression exprRight = Expression.Call(methodDateTimeParse, methodParam); //This is working fine for right side
}
var props = new[] { variable };
var lambda = Expression.Lambda<Func<Report, bool>>(ExprPrev, props).Compile();
ReportList = ReportList.Where(lambda).ToList();
그래서 나는 왼쪽에서 (밑줄 연산자의 왼쪽 위의 굵은되는) 제공도 필드에 DateTime.Parse
방법표현식 트리를 만드는 동안 DateTime.Parse() 메서드를 양측 (즉, 표현식 왼쪽과 표현식 오른쪽)으로 사용하는 방법은 무엇입니까?
오른쪽 측면에서 이미 수행 한 것과 똑같은 작업을 수행하지 않는 이유는 무엇입니까? – svick
매개 변수를 제공하는 방법이 없기 때문에 시도했지만 작동하지 않습니다. methodParam = Expression.Parameter (typeof (string), oFC.FieldName); //이 함수는 fieldname이 아닌 두 번째 매개 변수로 상수 값을 필요로합니다. –