public SearchQuery(IFieldQualifier fields, IValueFieldQualifier valueMap, IPredicateFieldQualifier predicateMap, IOperationFieldQualifier operationMap) { Fields = fields ?? throw new ArgumentNullException(nameof(fields)); ValueMap = valueMap ?? throw new ArgumentNullException(nameof(valueMap)); PredicateMap = predicateMap ?? throw new ArgumentNullException(nameof(predicateMap)); OperationMap = operationMap ?? throw new ArgumentNullException(nameof(operationMap)); }
public static IReadOnlyLogbook Predicate <TModel>(this TModel model, IFieldQualifier <TModel> fieldQualifier, IPredicateFieldQualifier <TModel> predicateFieldQualifier, out IEnumerable <Field> fields) where TModel : class, IModel, new() { ILogbook logs = Logger.NewLogbook(); if (fieldQualifier.Build <TModel>(out fields)) { IReadOnlyDictionary <Field, ReadOnlyLogbookPredicate <object> > fieldPredicateMap = predicateFieldQualifier; Type modelType = typeof(TModel); foreach (Field field in fields) { if (fieldPredicateMap.TryGetValue(field, out ReadOnlyLogbookPredicate <object> predicate)) { if (predicate != null) { PropertyInfo modelProperty = modelType.GetProperty(field.Name); if (modelProperty is null) { throw new PropertyNotFoundException($"{field.Name} named property could not found in {modelType.FullName}"); } object value = modelProperty.GetValue(model); logs.AddRange(predicate.Invoke(value)); } } } } else { Type modelType = typeof(TModel); foreach (KeyValuePair <Field, ReadOnlyLogbookPredicate <object> > fieldPredicatePair in predicateFieldQualifier) { Field field = fieldPredicatePair.Key; ReadOnlyLogbookPredicate <object> predicate = fieldPredicatePair.Value; if (predicate is null) { continue; } PropertyInfo modelProperty = modelType.GetProperty(field.Name); if (modelProperty is null) { throw new PropertyNotFoundException($"{field.Name} named property could not found in {modelType.FullName}"); } object value = modelProperty.GetValue(model); logs.AddRange(predicate.Invoke(value)); } } return(logs); }
public ModelQuery(IFieldQualifier fields, IValueFieldQualifier valueMap, IPredicateFieldQualifier predicateMap) { Fields = fields ?? throw new ArgumentNullException(nameof(fields)); ValueMap = valueMap ?? throw new ArgumentNullException(nameof(valueMap)); PredicateMap = predicateMap ?? throw new ArgumentNullException(nameof(predicateMap)); }