Esempio n. 1
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. 2
0
        public bool Set(Field field, ReadOnlyLogbookPredicate <object> value, bool overrideEnabled = false)
        {
            if (!_data.TryAdd(field, value))
            {
                if (overrideEnabled)
                {
                    _data.Remove(field);

                    return(_data.TryAdd(field, value));
                }
                else
                {
                    return(false);
                }
            }

            return(true);
        }
Esempio n. 3
0
 public bool TryGetValue(Field key, out ReadOnlyLogbookPredicate <object> value)
 {
     throw new NotImplementedException();
 }