public string Translate(FilterExpressionSettings e) { var template = GetTemplate(e.Operation); var @operator = GetOperator(e.Operator); var operand = e.Operand; return(string.Format(template, @operator, operand)); }
private IFilterExpression Create(FilterExpressionSettings item) { var type = (from t in Assembly.GetAssembly(typeof(IFilter)).GetTypes() where t.GetCustomAttribute <FilterAttribute>() != null && t.IsClass && (t.GetCustomAttribute <FilterAttribute>()?.Name ?? "") == item.Operation.ToLower() && t.GetInterfaces().Any(e => e == typeof(IFilterExpression)) select t).FirstOrDefault(); if (type != null) { var filter = (BaseFilter)Activator.CreateInstance(type); filter.Type = item.Operation; filter.Operator = item.Operator; filter.Operand = item.Operand; return(filter); } else { return(new EmptyFilter()); } }