public Constraint(int index, Variable x, CompareEnum comparator, Variable y) { Index = index; X = x; Y = y; Comparator = comparator; }
public BTNodeFloatEnergy(BlackBoard blackboard, float valueToCheck, CompareEnum comparer) { this.comparer = comparer; this.blackboard = blackboard; this.valueToCheck = valueToCheck; }
/// <summary> /// 根据条件对象获取Where语句,条件与条件之间的逻辑为与即用AND连接 /// </summary> /// <param name="where">条件对象</param> /// <param name="compareOptions">条件对象属性所对应的比较操作字典,如果为空,则所有条件用 = 比较</param> /// <returns></returns> public static string GetWhereString(object where, Dictionary <string, CompareEnum> compareOptions = null) { if (where == null) { return(""); } StringBuilder builder = new StringBuilder(); var t = where.GetType(); var pis = t.GetProperties(); foreach (var pi in pis) { var value = pi.GetValue(where, null); if (value == null) { continue; } CompareEnum compare = CompareEnum.Equal; if (compareOptions != null && compareOptions.ContainsKey(pi.Name)) { compare = compareOptions[pi.Name]; } var compareStr = CompareStringFactory.BuildCompareString(pi, compare, DbType); builder.Append($" AND {compareStr} "); } return(builder.ToString()); }
public CompareToken(string selectToken, CompareEnum compareType, object value, ValueEnum valueType) : this() { SelectToken = selectToken; CompareType = compareType; Value = value; ValueType = valueType; }
public CompareToken(string selectToken, CompareEnum compareType, object value) : this() { SelectToken = selectToken; CompareType = compareType; Value = value; ValueType = ValueTypeEvaluator.GetValueTypeFor(value); }
public static string GetCompareOperator(CompareEnum comp) { switch (comp) { case CompareEnum.EqualTo: return("="); case CompareEnum.GreaterThan: return(">"); case CompareEnum.LessThan: return("<"); } return(">"); }
public static bool CheckEquality(CompareEnum equality, int firstValue, int secondValue) { switch (equality) { case CompareEnum.EqualTo: return(firstValue == secondValue); case CompareEnum.GreaterThan: return(firstValue > secondValue); case CompareEnum.LessThan: return(firstValue < secondValue); } return(false); }
protected static void Compare(CompareEnum compare, StringBuilder sb) { switch (compare) { case CompareEnum.None: return; case CompareEnum.Equal: sb.Append("="); return; case CompareEnum.NotEqual: sb.Append("<>"); return; case CompareEnum.LessThan: sb.Append("<"); return; case CompareEnum.LessThanOrEqual: sb.Append("<="); return; case CompareEnum.GreaterThan: sb.Append(">"); return; case CompareEnum.GreaterThanOrEqual: sb.Append(">="); return; case CompareEnum.Like: sb.Append(" like "); return; case CompareEnum.In: sb.Append(" in "); return; case CompareEnum.NotIn: sb.Append(" not in "); return; default: throw new Exception($"{XConfig.EC._023} - [[{compare}]] 不能解析!!!"); } }
private static CompareEnum Opposite(CompareEnum comparison) { switch (comparison) { case CompareEnum.Equals: return(CompareEnum.NotEquals); case CompareEnum.NotEquals: return(CompareEnum.Equals); case CompareEnum.Greater: return(CompareEnum.Smaller); case CompareEnum.Smaller: return(CompareEnum.Greater); default: return(CompareEnum.Default); } }
protected static string Compare(CompareEnum compare) { switch (compare) { case CompareEnum.None: return(" "); case CompareEnum.Equal: return("="); case CompareEnum.NotEqual: return("<>"); case CompareEnum.LessThan: return("<"); case CompareEnum.LessThanOrEqual: return("<="); case CompareEnum.GreaterThan: return(">"); case CompareEnum.GreaterThanOrEqual: return(">="); case CompareEnum.Like: return(" like "); case CompareEnum.In: return(" in "); case CompareEnum.NotIn: return(" not in "); } return(" "); }
public static string BuildCompareString(PropertyInfo propertyInfo, CompareEnum option) { var columnName = propertyInfo.Name; var tableColumnAttribute = propertyInfo.GetCustomAttributes(true).SingleOrDefault(p => p is TableColumnAttribute) as TableColumnAttribute; if (tableColumnAttribute != null) { columnName = tableColumnAttribute.ColumnName; } switch (option) { case CompareEnum.Equal: { return($" {columnName} = @{propertyInfo.Name}"); } case CompareEnum.GreaterThan: { return($"{columnName} > @{propertyInfo.Name}"); } case CompareEnum.GreaterThanEqualTo: { return($"{columnName} >= @{propertyInfo.Name}"); } case CompareEnum.In: { return($" {columnName} In @{propertyInfo.Name} "); } case CompareEnum.LessThan: { return($"{columnName} < @{propertyInfo.Name}"); } case CompareEnum.LessThanEqualTo: { return($"{columnName} <= @{propertyInfo.Name}"); } case CompareEnum.Like: { return($"{columnName} Like '%@{propertyInfo.Name}%'"); } case CompareEnum.NotIn: { return($"{columnName} Not In @{propertyInfo.Name}"); } case CompareEnum.NotLike: { return($"{columnName} Not Like @{propertyInfo.Name}"); } case CompareEnum.IsNull: { return($"{columnName} Is Null"); } default: { throw new ArgumentException($"不支持这种比较操作【{option.ToString()}】"); } } }
public PageNameComparer( CompareEnum compareEnum, SortOrder sortOrder ) { _compareEnum = compareEnum; _sortOrder = sortOrder; }
public QueryCompareAttribute(CompareEnum compare) { this.compare = compare; }
/// <summary> /// 将查询条件model转换成表达式树 /// </summary> /// <typeparam name="T"></typeparam> /// <typeparam name="K"></typeparam> /// <param name="entity"></param> /// <param name="model"></param> /// <returns></returns> public static Expression <Func <T, bool> > CreateExpression <T, K>(K model) { var allProperty = typeof(K).GetProperties(); var lstValidProperty = new List <Tuple <int, PropertyInfo> >(); //1.先去除掉忽略项 foreach (var p in allProperty) { //如果有Ignore直接忽略 if (p.GetCustomAttribute <IgnoreAttribute>() != null) { continue; } //如果model中对应的值为null,也直接忽略 if (p.GetValue(model) == null) { continue; } var compare = p.GetCustomAttribute <QueryCompareAttribute>(); int order = compare != null ? compare.Order : 0; lstValidProperty.Add(new Tuple <int, PropertyInfo>(order, p)); } if (lstValidProperty.Count == 0) { return(x => true); } lstValidProperty = lstValidProperty.OrderBy(x => x.Item1).ToList(); ParameterExpression parameter = Expression.Parameter(typeof(T)); Expression query = null; for (int i = 0; i < lstValidProperty.Count; i++) { var p = lstValidProperty[i].Item2; var val = p.GetValue(model); string fieldName = p.Name; CompareEnum compareType = CompareEnum.Eq; var compare = p.GetCustomAttribute <QueryCompareAttribute>(); if (compare != null) { fieldName = string.IsNullOrWhiteSpace(compare.FieldName) ? p.Name : compare.FieldName; compareType = compare.compare; } ConstantExpression constant = Expression.Constant(val, typeof(T).GetProperty(fieldName).PropertyType); //ConstantExpression constant = Expression.Constant(val, val.GetType()); MemberExpression member = Expression.PropertyOrField(parameter, fieldName); Expression exp; switch (compareType) { case CompareEnum.Eq: exp = Expression.Equal(member, constant); break; case CompareEnum.NotEq: exp = Expression.NotEqual(member, constant); break; case CompareEnum.Gt: exp = Expression.GreaterThan(member, constant); break; case CompareEnum.GtEq: exp = Expression.GreaterThanOrEqual(member, constant); break; case CompareEnum.Lt: exp = Expression.LessThan(member, constant); break; case CompareEnum.LtEq: exp = Expression.LessThanOrEqual(member, constant); break; case CompareEnum.Like: exp = Expression.Call(member, typeof(string).GetMethod(nameof(string.Contains), new Type[] { typeof(string) }), constant); break; case CompareEnum.LeftLike: exp = Expression.Call(member, typeof(string).GetMethod(nameof(string.StartsWith), new Type[] { typeof(string) }), constant); break; case CompareEnum.RightLike: exp = Expression.Call(member, typeof(string).GetMethod(nameof(string.EndsWith), new Type[] { typeof(string) }), constant); break; default: exp = Expression.Equal(member, constant); break; } if (i == 0) { query = exp; } else { query = Expression.And(query, exp); } } return(Expression.Lambda <Func <T, bool> >(query, parameter)); }
public static Expression <Func <T, bool> > AddAndExpression <T>(this Expression <Func <T, bool> > exp, CompareEnum compareType, string parameterName, object val) { ParameterExpression parameter = Expression.Parameter(typeof(T)); ConstantExpression constant = Expression.Constant(val); MemberExpression member = Expression.PropertyOrField(exp.Parameters[0], parameterName); Expression expAdd; switch (compareType) { case CompareEnum.Eq: expAdd = Expression.Equal(member, constant); break; case CompareEnum.NotEq: expAdd = Expression.NotEqual(member, constant); break; case CompareEnum.Gt: expAdd = Expression.GreaterThan(member, constant); break; case CompareEnum.GtEq: expAdd = Expression.GreaterThanOrEqual(member, constant); break; case CompareEnum.Lt: expAdd = Expression.LessThan(member, constant); break; case CompareEnum.LtEq: expAdd = Expression.LessThanOrEqual(member, constant); break; case CompareEnum.Like: expAdd = Expression.Call(member, typeof(string).GetMethod(nameof(string.Contains)), constant); break; case CompareEnum.LeftLike: expAdd = Expression.Call(member, typeof(string).GetMethod(nameof(string.StartsWith), new Type[] { typeof(string) }), constant); break; case CompareEnum.RightLike: expAdd = Expression.Call(member, typeof(string).GetMethod(nameof(string.EndsWith)), constant); break; default: expAdd = Expression.Equal(member, constant); break; } var query = Expression.And(exp.Body, expAdd); return(Expression.Lambda <Func <T, bool> >(query, exp.Parameters)); }
public ItemComparer( CompareEnum compareEnum, SortOrder sortOrder ) { _compareEnum = compareEnum; _sortOrder = sortOrder; }
public static string BuildCompareString(PropertyInfo propertyInfo, CompareEnum option, DBTypeEnums dbType) { var ParameterPrefix = dbType == DBTypeEnums.ORACLE?":": "@"; var columnName = propertyInfo.Name; var tableColumnAttribute = propertyInfo.GetCustomAttributes(true).SingleOrDefault(p => p is TableColumnAttribute) as TableColumnAttribute; if (tableColumnAttribute != null) { columnName = tableColumnAttribute.ColumnName; } switch (option) { case CompareEnum.Equal: { return($" {columnName} = {ParameterPrefix}{propertyInfo.Name}"); } case CompareEnum.GreaterThan: { return($"{columnName} > {ParameterPrefix}{propertyInfo.Name}"); } case CompareEnum.GreaterThanEqualTo: { return($"{columnName} >= {ParameterPrefix}{propertyInfo.Name}"); } case CompareEnum.In: { return($" {columnName} In {ParameterPrefix}{propertyInfo.Name} "); } case CompareEnum.LessThan: { return($"{columnName} < {ParameterPrefix}{propertyInfo.Name}"); } case CompareEnum.LessThanEqualTo: { return($"{columnName} <= {ParameterPrefix}{propertyInfo.Name}"); } case CompareEnum.Like: { return($"{columnName} Like {ParameterPrefix}{propertyInfo.Name}"); } case CompareEnum.NotIn: { return($"{columnName} Not In {ParameterPrefix}{propertyInfo.Name}"); } case CompareEnum.NotLike: { return($"{columnName} Not Like {ParameterPrefix}{propertyInfo.Name}"); } case CompareEnum.IsNull: { return($"{columnName} Is Null"); } default: { throw new ArgumentException($"不支持这种比较操作【{option.ToString()}】"); } } }
public PageNameComparer(CompareEnum compareEnum, SortOrder sortOrder) { _compareEnum = compareEnum; _sortOrder = sortOrder; }
public void StencilFunc(CompareEnum func, int reference, uint mask) { GlBindings.glStencilFunc(func, reference, mask); }
public ItemComparer(CompareEnum compareEnum, SortOrder sortOrder) { _compareEnum = compareEnum; _sortOrder = sortOrder; }
public QueryColumnAttribute(string columnName, CompareEnum compareType = CompareEnum.Equal) { ColumnName = columnName; CompareCondition = compareType; }