internal override Expression Apply(Type converterType, List <KeyValuePair <Expression, Expression> > aliases) { var condition = GetFullCondition().Body.ResolveAliases(aliases); var message = Message == null?Expression.Constant(null, typeof(MultiLanguageTextBase)) : Message.Body.ResolveAliases(aliases); var result = Expression.Variable(typeof(ValidationResult)); var invalid = Expression.New(validationResultConstructor, Expression.Constant(validationResultType), message); var assign = Expression.IfThenElse(Expression.Convert(condition, typeof(bool)), Expression.Assign(result, invalid), Expression.Assign(result, Expression.Constant(ValidationResult.Ok))); var toLog = new ValidationLogInfo("Regex = " + regex, condition.ToString()); if (MutatorsValidationRecorder.IsRecording()) { MutatorsValidationRecorder.RecordCompilingValidation(converterType, toLog); } return(Expression.Block(new[] { result }, Expression.Call(RecordingMethods.RecordExecutingValidationMethodInfo, Expression.Constant(converterType, typeof(Type)), Expression.Constant(toLog), Expression.Call(result, typeof(object).GetMethod("ToString"))), assign, result)); }
public override Expression Apply(List <KeyValuePair <Expression, Expression> > aliases) { if (Condition == null) { return(validatorFromRoot.Body.ResolveAliases(aliases)); } Expression condition = Expression.Equal(Expression.Convert(Condition.Body.ResolveAliases(aliases), typeof(bool?)), Expression.Constant(true, typeof(bool?))); var toLog = new ValidationLogInfo(Name, condition.ToString()); var result = Expression.Variable(typeof(ValidationResult)); condition = Expression.Condition(condition, validatorFromRoot.Body.ResolveAliases(aliases), Expression.Constant(ValidationResult.Ok)); var assign = Expression.Assign(result, condition); if (MutatorsValidationRecorder.IsRecording()) { MutatorsValidationRecorder.RecordCompilingValidation(toLog); } return(Expression.Block(new[] { result }, assign, Expression.Call(typeof(MutatorsValidationRecorder).GetMethod("RecordExecutingValidation"), Expression.Constant(toLog), Expression.Call(result, typeof(object).GetMethod("ToString"))), result)); }
public override Expression Apply(List <KeyValuePair <Expression, Expression> > aliases) { if (Condition == null) { return(null); } var condition = Expression.Equal(Expression.Convert(Condition.Body.ResolveAliases(aliases), typeof(bool?)), Expression.Constant(true, typeof(bool?))); var message = Message == null?Expression.Constant(null, typeof(MultiLanguageTextBase)) : Message.Body.ResolveAliases(aliases); var result = Expression.Variable(typeof(ValidationResult)); var invalid = Expression.New(validationResultConstructor, Expression.Constant(validationResultType), message); var assign = Expression.IfThenElse(condition, Expression.Assign(result, invalid), Expression.Assign(result, Expression.Constant(ValidationResult.Ok))); var toLog = new ValidationLogInfo("invalidIf", condition.ToString()); if (MutatorsValidationRecorder.IsRecording()) { MutatorsValidationRecorder.RecordCompilingValidation(toLog); } return(Expression.Block(new[] { result }, assign, Expression.Call(typeof(MutatorsValidationRecorder).GetMethod("RecordExecutingValidation"), Expression.Constant(toLog), Expression.Call(result, typeof(object).GetMethod("ToString"))), result)); }