public override bool ValidValue(object dataValue) { Check.Require(dataValue != null, string.Format(CommonStrings.XMustNotBeNull, "dataValue")); AssumedTypes.IAggregate aggregate = dataValue as AssumedTypes.IAggregate; Check.Require(aggregate != null, string.Format( AmValidationStrings.XMustImplementY, dataValue.GetType().ToString(), "IAggregate")); bool result = true; aggregate.Constraint = this; AssumedTypes.IList iList = dataValue as AssumedTypes.IList; if (iList == null) { throw new ApplicationException(string.Format(AmValidationStrings.XMustImplementY, dataValue.GetType().ToString(), "IList")); } if (!Cardinality.Interval.Has(iList.Count)) { result = false; ValidationContext.AcceptValidationError(this, string.Format(AmValidationStrings.CardinalityOutOfBounds, iList.Count, RmAttributeName)); } result &= Cardinality.IsOrdered ? IsOrderedChildrenValid(iList) : IsUnorderedChildrenValid(iList); result &= IsOccurrencesValid(iList); return(result); }
protected void BuildPath(Path path) { Check.Require(path != null, "path must not be null"); Check.Require(path.Current != null, "current path step must not be null"); string attributeName = path.Current.Attribute; object value = GetAttributeValue(attributeName); if (value == null) { CComplexObject complexObjectConstraint = this.Constraint as CComplexObject; if (complexObjectConstraint == null) { throw new NotImplementedException(); } CAttribute attributeConstraint = complexObjectConstraint.GetAttribute(attributeName); if (attributeConstraint == null) { throw new ApplicationException("constraint for attribute not found"); } CMultipleAttribute multipleAttributeConstraint = attributeConstraint as CMultipleAttribute; if (multipleAttributeConstraint == null) { if (attributeConstraint.Children.Count != 1) { throw new ApplicationException("Single attribute constraint must have exactly one children"); } CObject objectConstraint = attributeConstraint.Children[0]; CDefinedObject definedObjectConstraint = objectConstraint as CDefinedObject; if (definedObjectConstraint == null) { throw new NotImplementedException(); } value = definedObjectConstraint.DefaultValue; SetAttributeValue(attributeName, value); } else { Type itemType = null; value = multipleAttributeConstraint.CreateAggregate(itemType); SetAttributeValue(attributeName, value); } } if (path.NextStep()) { IRmType rmType = value as IRmType; if (rmType == null) { AssumedTypes.IAggregate container = value as AssumedTypes.IAggregate; if (container != null) { container.BuildPath(path); } else { throw new ApplicationException("expected IRmType"); } } else { rmType.BuildPath(path); } } }