Exemplo n.º 1
0
        public void AddRule(IValidationRule rule, RuleMeta meta = null)
        {
            //var internalRule = rule as ValidationRule;
            //if (internalRule == null) throw new NotSupportedException("验证规则必须从 ValidationRule 类型继承。");

            //this.AddRule(internalRule.RuleHandler, null, level, priority);

            //if (parameters != null)
            //{
            //    var properties = TypeDescriptor.GetProperties(parameters);
            //    foreach (PropertyDescriptor propertyDescriptor in properties)
            //    {
            //        object value = propertyDescriptor.GetValue(parameters);
            //        args[propertyDescriptor.Name] = value;
            //    }
            //}

            if (rule == null)
            {
                throw new ArgumentNullException("rule");
            }

            var innerRule = new Rule(rule);

            innerRule.Meta = meta ?? new RuleMeta();

            Rules.AddRule(innerRule);
        }
Exemplo n.º 2
0
        public void AddRule(IManagedProperty property, IValidationRule rule, RuleMeta meta = null)
        {
            if (property == null)
            {
                throw new ArgumentNullException("property");
            }
            if (rule == null)
            {
                throw new ArgumentNullException("rule");
            }

            var innerRule = new Rule(rule);

            innerRule.Property = property;
            innerRule.Meta     = meta ?? new RuleMeta();

            Rules.AddRule(innerRule);
        }
Exemplo n.º 3
0
        private static bool IsMatchEntityStatus(Entity entity, RuleMeta meta)
        {
            switch (entity.PersistenceStatus)
            {
            case PersistenceStatus.Unchanged:
                return(meta.HasScope(EntityStatusScopes.Add) || meta.HasScope(EntityStatusScopes.Update));

            case PersistenceStatus.Modified:
                return(meta.HasScope(EntityStatusScopes.Update));

            case PersistenceStatus.New:
                return(meta.HasScope(EntityStatusScopes.Add));

            case PersistenceStatus.Deleted:
                return(meta.HasScope(EntityStatusScopes.Delete));

            default:
                throw new NotSupportedException();
            }
        }