using System;
using System.Collections.Generic;
using System.Linq.Expressions;
namespace EC.Utils
{
///
/// 动态Lamada
/// 版 本:V3.0.0
/// 版 权:EasyCode
/// 作 者:LXC
///
public partial class ExtLinq where T : new()
{
private List m_lstExpression = null;
private ParameterExpression m_Parameter = null;
public ExtLinq()
{
m_lstExpression = new List();
m_Parameter = Expression.Parameter(typeof(T), "x");
}
public void CreateExpression(string strPropertyName, object strValue, SearchMethod expressType)
{
Expression expRes = null;
MemberExpression member = Expression.PropertyOrField(m_Parameter, strPropertyName);
if (expressType == SearchMethod.Contains)
{
expRes = Expression.Call(member, typeof(string).GetMethod("Contains"), Expression.Constant(strValue));
}
else if (expressType == SearchMethod.Equal)
{
expRes = Expression.Equal(member, Expression.Constant(strValue, member.Type));
}
else if (expressType == SearchMethod.NotEqual)
{
expRes = Expression.NotEqual(member, Expression.Constant(strValue, member.Type));
}
else if (expressType == SearchMethod.LessThan)
{
expRes = Expression.LessThan(member, Expression.Constant(strValue, member.Type));
}
else if (expressType == SearchMethod.LessThanOrEqual)
{
expRes = Expression.LessThanOrEqual(member, Expression.Constant(strValue, member.Type));
}
else if (expressType == SearchMethod.GreaterThan)
{
expRes = Expression.GreaterThan(member, Expression.Constant(strValue, member.Type));
}
else if (expressType == SearchMethod.GreaterThanOrEqual)
{
expRes = Expression.GreaterThanOrEqual(member, Expression.Constant(strValue, member.Type));
}
m_lstExpression.Add(expRes);
}
public void CreateExpression(string strPropertyName, List