예제 #1
0
        public Generator <T> AddGenerator <TValue>(AbstractValueGenerator <TValue> generator)
        {
            Type valueType = typeof(TValue);

            if (_generators.ContainsKey(valueType))
            {
                _generators.Remove(valueType);
            }

            _generators.Add(valueType, generator);
            return(this);
        }
예제 #2
0
        public Generator <T> AddGenerator <TModel, TProp>(AbstractValueGenerator <TProp> generator, params Expression <Func <TModel, TProp> >[] accessors)
        {
            foreach (var accessor in accessors)
            {
                if (accessor.Body.NodeType != ExpressionType.MemberAccess)
                {
                    throw new Exception("accessor must be simple property accessor eg obj.prop");
                }
                MemberExpression casted = accessor.Body as MemberExpression;

                if (_propertyGenerators.ContainsKey(casted.Member))
                {
                    _propertyGenerators.Remove(casted.Member);
                }
                _propertyGenerators.TryAdd(casted.Member, generator);
            }

            return(this);
        }