Beispiel #1
0
 public IAttachedValidation Create(IStructuralItem modelItem,
                                   IEnumerable <IAttribute> attributes)
 {
     // Enusre that the data type is a positive integer semantic
     // type (or nullable positive integer)
     if (!IsValid(modelItem))
     {
         throw new InvalidOperationException("Unsupported data type.");
     }
     return(new MaxIntegerValidation(attributes));
 }
Beispiel #2
0
        public bool IsValid(IStructuralItem modelItem)
        {
            INullableType nullableType = modelItem as INullableType;

            // Get underlying type if it is an INullableType.
            modelItem =
                null != nullableType ? nullableType.UnderlyingType : modelItem;

            // Ensure the type matches the business type,
            // or the underlying type
            while (modelItem is ISemanticType)
            {
                if (String.Equals(((ISemanticType)modelItem).Id,
                                  "ApressExtensionCS:DurationType",
                                  StringComparison.Ordinal))
                {
                    return(true);
                }
                modelItem = ((ISemanticType)modelItem).UnderlyingType;
            }

            //Don't apply the validation if the conditions aren't met
            return(false);
        }