Exemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FluentStringRuleSet{TEntity}"/> class.
        /// </summary>
        /// <param name="entityRules">The <see cref="EntityRuleSet{TEntity}"/> instance that validation rules will be added to.</param>
        /// <param name="property">An expression that represents the property that this fluent chain applies to.</param>
        /// <exception cref="System.ArgumentNullException">
        /// entityRules
        /// or
        /// property
        /// </exception>
        /// <exception cref="System.ArgumentException">Raised if the property parameter does not represent a property.</exception>
        public FluentStringRuleSet(EntityRuleSet <TEntity> entityRules, Expression <Func <TEntity, string> > property)
        {
            if (entityRules == null)
            {
                throw new ArgumentNullException("entityRules");
            }
            if (property == null)
            {
                throw new ArgumentNullException("property");
            }

            EntityRules = entityRules;
            var body = property.Body as MemberExpression;

            if (body == null || (Property = body.Member as PropertyInfo) == null)
            {
                throw new ArgumentException(Resources.InvalidPropertyError);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FluentNumberRuleSet{TEntity}"/> class.
        /// </summary>
        /// <param name="entityRules">The <see cref="EntityRuleSet{TEntity}"/> instance that validation rules will be added to.</param>
        /// <param name="property">An expression that represents the property that this fluent chain applies to.</param>
        /// <exception cref="System.ArgumentNullException">
        /// entityRules
        /// or
        /// property
        /// </exception>
        /// <exception cref="System.ArgumentException">Raised if the property parameter does not represent a property.</exception>
        public FluentNumberRuleSet(EntityRuleSet <TEntity> entityRules, LambdaExpression property)
        {
            if (entityRules == null)
            {
                throw new ArgumentNullException("entityRules");
            }
            if (property == null)
            {
                throw new ArgumentNullException("property");
            }

            EntityRules = entityRules;
            var body = property.Body as MemberExpression;

            if (body == null && property.Body.NodeType == ExpressionType.Convert)
            {
                body = ((UnaryExpression)property.Body).Operand as MemberExpression;
            }
            if (body == null || (Property = body.Member as PropertyInfo) == null)
            {
                throw new ArgumentException(Resources.InvalidPropertyError);
            }
        }