public FilterPredicate(string propertyNameOverride, scan_context ctx, PropertyInfo pi, FilterBinaryOperator op = FilterBinaryOperator.Eq) { _contextExpression = ctx.Expression; _propertyName = propertyNameOverride; _path = ctx.Path + _propertyName; _propInfo = ctx.CtxType.GetProperty(_propertyName); // ReflectionHelper.GetPropertyFromPath(ctx.CtxType, _path); _operator = op; _propertyValueSnapshot = null; }
public Filter(FoType fo, FilterBinaryOperator op = FilterBinaryOperator.And) { Fo = fo; _op = op; //expression in destination object domain _mainExpression = Expression.Parameter(typeof(ContextType), "o"); _predicates = new Dictionary <string, IFilterExpression <FoType> >(); scanCustomAttributes(fo.GetType(), "", typeof(ContextType), _mainExpression); //GetSnapshot(fo); }
private void handleOneProperty(PropertyInfo pi, PropertyInfo metaPi = null) { //we can have complex types if (pi != null) { FilterBinaryOperator op = FilterBinaryOperator.Eq; string propertyName = pi.Name; string propertyPath = _scan_ctx.Path + pi.Name; #if DEBUG_TRACE_LOG_ON manager.SLogManager.getInstance().getClassLogger(this.GetType()).Debug("Make filter predicate for : " + propertyPath); #endif bool skip = false; try { var attr = pi.GetCustomAttributes(typeof(FilterPredicateAttribute), true); if (attr.Count() > 0) { FilterPredicateAttribute fpa = (attr[0] as FilterPredicateAttribute); // handle eventual overrides op = fpa.Operator; skip = fpa.SkipProperty; } //check also meta info if present if (metaPi != null) { attr = metaPi.GetCustomAttributes(typeof(FilterPredicateAttribute), true); if (attr.Count() > 0) { FilterPredicateAttribute fpa = (attr[0] as FilterPredicateAttribute); // handle eventual overrides op = fpa.Operator; skip = fpa.SkipProperty; } } } catch (Exception) {} if (skip) { return; //skipped property } if (pi.PropertyType.FullName == "System.String" || pi.PropertyType.IsPrimitive || pi.PropertyType.FullName == "System.DateTime" || pi.PropertyType.IsValueType) // || pi.PropertyType.IsGenericType) { // direct field if (!_predicates.ContainsKey(propertyPath)) { _predicates[propertyPath] = new FilterPredicate <FoType>(propertyName, _scan_ctx, pi, op); } } else if (pi.PropertyType.IsClass) //do recursion only for classes { // nested object so we have to change contexts Type t = _scan_ctx.CtxType?.GetProperty(propertyName)?.PropertyType; if (t != null) { scanCustomAttributes( // Fo domain pi.PropertyType, propertyName, // Filtered domain t, Expression.Property(_scan_ctx.Expression, _scan_ctx.CtxType.GetProperty(propertyName)) ); } } } }