コード例 #1
0
        public async Task <ValidationResult> ValidateEntity <T>(T entity)
        {
            ValidationResult rtn = new ValidationResult();
            //var validators = await this.StateManager.GetOrAddAsync<IReliableDictionary<ComparableType, IGoodVibesValidator>>(ValidatorDictionary);
            var validators = await this.StateManager.GetOrAddAsync <IReliableDictionary <string, List <XElement> > >(SerializedValidatorDictionary);

            using (var tx = this.StateManager.CreateTransaction())
            {
                var conditionalValidatorRules = await validators.TryGetValueAsync(tx, typeof(T).AssemblyQualifiedName);

                if (conditionalValidatorRules.HasValue)
                {
                    foreach (var xml in conditionalValidatorRules.Value)
                    {
                        try
                        {
                            var x = _serializer.Deserialize <Func <T, ValidationMessage> >(xml);
                        }
                        catch (Exception ex)
                        {
                            Trace.TraceError(ex.ToString());
                        }
                    }
                    var validationRules = conditionalValidatorRules.Value.Select(x => _serializer.Deserialize <Func <T, ValidationMessage> >(x)).ToList();
                    var typeValidator   = GoodVibesValidator <T> .Create(validationRules);

                    var result = typeValidator.Validate(entity);
                    rtn.AddValidationResults(result);
                }
            }
            return(rtn);
        }
コード例 #2
0
        public static GoodVibesValidator <T> Create(List <Expression <Func <T, ValidationMessage> > > validationRules)
        {
            var instance = new GoodVibesValidator <T>(validationRules);

            return(instance);
        }