Esempio n. 1
0
 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));
 }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
 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));
 }