コード例 #1
0
		// --- Methods ---

		// --- Methods | Validation ---

		public void Validate()
		{
			brokenRules = new List<BrokenPropertyRuleInfo>();

			//this.Merge(GetBrokenRuleInfos(this.propertyValueRules), GetBrokenRuleInfos(this.propertyStateRules));

			foreach (var stateRule in propertyStateRules)
			{
				var validator = stateRule.Validator;
				var currentPropertyValue = stateRule.PropertyInfo.GetValue(this.ManagedObject, null);

				if (!validator.Validate(currentPropertyValue, this.ManagedObject))
				{
					var info = new BrokenPropertyRuleInfo()
					{
						AttemptedValue = currentPropertyValue,
						ErrorMessage = GetPropertyStateErrorMessage(stateRule, currentPropertyValue, this.ManagedObject),
						PropertyInfo = stateRule.PropertyInfo
					};
					brokenRules.Add(info);
				}
			}


		}
コード例 #2
0
		private List<BrokenPropertyRuleInfo> GetBrokenRuleInfos(List<PropertyValueRule> propertyValueRules)
		{
			var brokenRules = new List<BrokenPropertyRuleInfo>();

			foreach (var valueRule in propertyValueRules)
			{
				var validator = valueRule.Validator;
				var currentPropertyValue = valueRule.PropertyInfo.GetValue(this.ManagedObject, null);

				if (!validator.Validate(currentPropertyValue))
				{
					var info = new BrokenPropertyRuleInfo()
					{
						AttemptedValue = currentPropertyValue,
						ErrorMessage = GetPropertyValueErrorMessage(valueRule, currentPropertyValue),
						PropertyInfo = valueRule.PropertyInfo
					};
					brokenRules.Add(info);
				}
			}
			return brokenRules;
		}