Example #1
0
 internal static void ValidateMinMaxValue(this OpenType openType, IComparable defaultValue, IComparable minValue, IComparable maxValue)
 {
     if (minValue != null)
     {
         if (!openType.IsValue(minValue))
         {
             throw new OpenDataException("Minimum value must be valid for supplied open type.");
         }
         if (defaultValue != null && minValue.CompareTo(defaultValue) > 0)
         {
             throw new OpenDataException("Minimum value must be less or equal to default value.");
         }
     }
     if (maxValue != null)
     {
         if (!openType.IsValue(maxValue))
         {
             throw new OpenDataException("Maximum value must be valid for supplied open type.");
         }
         if (defaultValue != null && defaultValue.CompareTo(maxValue) > 0)
         {
             throw new OpenDataException("Maximum value must be greater than or equal to default value.");
         }
     }
     if (maxValue != null && minValue != null && minValue.CompareTo(maxValue) > 0)
     {
         throw new OpenDataException("Maximum value must be greater than or equal to minimum value.");
     }
 }
Example #2
0
 internal static void ValidateDefaultValue(this OpenType openType, object defaultValue)
 {
     if (defaultValue != null)
     {
         if (!openType.IsValue(defaultValue))
         {
             throw new OpenDataException("Default value must be valid for supplied open type.");
         }
         if (openType.Kind == OpenTypeKind.ArrayType || openType.Kind == OpenTypeKind.TabularType)
         {
             throw new OpenDataException("Cannot specify default value for attribute of type array or tabular.");
         }
     }
 }
Example #3
0
 internal static void ValidateLegalValues(this OpenType openType, IEnumerable <object> legalValues)
 {
     if (legalValues == null)
     {
         throw new ArgumentNullException("legalValues");
     }
     if (openType.Kind == OpenTypeKind.ArrayType || openType.Kind == OpenTypeKind.TabularType)
     {
         throw new OpenDataException("Cannot specify legal values for attribute of type array or tabular.");
     }
     foreach (object o in legalValues)
     {
         if (!openType.IsValue(o))
         {
             throw new OpenDataException("Each legal value must be valid for supplied open type.");
         }
     }
 }
Example #4
0
        /// <summary>
        /// Constructs a CompositeDataSupport instance with the specified <paramref name="compositeType"/>,
        /// whose item values are specified by <paramref name="itemValues"/>, in the same order as in
        /// <paramref name="itemNames"/>. As a <see cref="compositeType"/> does not specify any order on its
        /// items, the <see cref="itemNames"/> parameter is used to specify the order in which the values are
        /// given in <paramref name="itemValues"/>.
        /// </summary>
        /// <param name="compositeType">The composite type  of this composite data instance; must not be null.</param>
        /// <param name="itemNames">Must list, in any order, all the item names defined in
        /// <paramref name="compositeType"/>; the order in which the names are listed, is used to match values in
        /// <paramref name="itemValues"/>; must not be null or empty.</param>
        /// <param name="itemValues">The values of the items, listed in the same order as their respective names
        /// in <paramref name="itemNames"/>; each item value can be null, but if it is non-null it must be a
        /// valid value for the open type defined in <paramref name="compositeType"/> for the corresponding item;
        /// must be of the same size as <paramref name="itemNames"/>; must not be null or empty.</param>
        public CompositeDataSupport(CompositeType compositeType, IEnumerable <string> itemNames, IEnumerable <object> itemValues)
        {
            if (compositeType == null)
            {
                throw new ArgumentNullException("compositeType");
            }
            if (itemNames == null)
            {
                throw new ArgumentNullException("itemNames");
            }
            if (itemValues == null)
            {
                throw new ArgumentNullException("itemValues");
            }
            IEnumerator <object> values = itemValues.GetEnumerator();

            foreach (string itemName in itemNames)
            {
                if (!values.MoveNext())
                {
                    throw new OpenDataException("Names and value collections must have equal size.");
                }
                OpenType itemType = compositeType.GetOpenType(itemName);
                if (itemType == null)
                {
                    throw new OpenDataException("Composite type doesn't have item with name " + itemName);
                }
                if (values.Current != null && !itemType.IsValue(values.Current))
                {
                    throw new OpenDataException("Value is not valid for its item's open type.");
                }
                _items[itemName] = values.Current;
            }
            if (_items.Count != compositeType.KeySet.Count)
            {
                throw new OpenDataException(string.Format(CultureInfo.CurrentCulture,
                                                          "Composite type has different item count ({0}) than count of items provided ({1}).",
                                                          _items.Count, compositeType.KeySet.Count));
            }
            _compositeType = compositeType;
        }
Example #5
0
        public sealed override bool IsValue(object value)
        {
            Array array = value as Array;

            if (array != null)
            {
                if (array.Rank != _dimension)
                {
                    return(false);
                }
                int   count       = 1;
                int[] index       = null;
                int[] lengths     = new int[array.Rank];
                int[] lowerBounds = new int[array.Rank];
                for (int i = 0; i < array.Rank; i++)
                {
                    lengths[i]     = array.GetLength(i);
                    count         *= lengths[i];
                    lowerBounds[i] = array.GetLowerBound(i);
                }
                for (int i = 0; i < count; i++)
                {
                    index = GetNextIndex(index, lengths, lowerBounds);
                    object element = array.GetValue(index);
                    if (element != null && !ElementType.IsValue(element))
                    {
                        return(false);
                    }
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }
 public bool IsValue(object value)
 {
     return(OpenType.IsValue(value));
 }