コード例 #1
0
 public CompositeDataType_Type(CompositeType value)
     : base(value)
 {
     List<CompositeDataField> fields = new List<CompositeDataField>();
      foreach (string fieldName in value.KeySet)
      {
     fields.Add(new CompositeDataField(fieldName, value.GetDescription(fieldName), Serialize(value.GetOpenType(fieldName))));
      }
      CompositeDataField = fields.ToArray();
 }
コード例 #2
0
        public ICompositeDataBuilder Composite(string name, Action <ICompositeDataBuilder> nestedCompositeValueBuilderAction)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            if (nestedCompositeValueBuilderAction == null)
            {
                throw new ArgumentNullException("nestedCompositeValueBuilderAction");
            }
            CompositeType nestedCompositeType = _type.GetOpenType(name) as CompositeType;

            if (nestedCompositeType == null)
            {
                throw new InvalidOperationException(string.Format("Item {0} is not of CompositeType", name));
            }
            CompositeDataBuilder nestedBuilder = new CompositeDataBuilder(nestedCompositeType);

            nestedCompositeValueBuilderAction(nestedBuilder);
            _items.Add(name, nestedBuilder.Create());
            return(this);
        }
コード例 #3
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;
        }
コード例 #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;
 }
コード例 #5
0
 private static ICompositeData ExtractCompositeValue(CompositeType openType, CompositeData compositeData)
 {
     return new CompositeDataSupport(openType,
         compositeData.Properties.Select(x => x.Name),
         compositeData.Properties.Select(x => ExtractSimpleValue(openType.GetOpenType(x.Name), x.Value)));
 }
コード例 #6
0
 private static CompositeData FormatCompositeValue(CompositeType compositeType, ICompositeData compositeData)
 {
     return new CompositeData(compositeType.KeySet.Select(x => new CompositeDataProperty(x, FormatSimpleValue(compositeType.GetOpenType(x), compositeData[x]))));
 }
コード例 #7
0
        private static CompositeType MakeRowType(CompositeType elementType)
        {
            List<string> names = new List<string>();
             List<string> descriptions = new List<string>();
             List<OpenType> types = new List<OpenType>();

             names.Add(CollectionIndexColumnName);
             descriptions.Add("Index of a collection");
             types.Add(SimpleType.Integer);

             foreach (string itemName in elementType.KeySet)
             {
            names.Add(itemName);
            descriptions.Add(elementType.GetDescription(itemName));
            types.Add(elementType.GetOpenType(itemName));
             }
             return new CompositeType(elementType.TypeName, elementType.Description, names, descriptions, types);
        }
コード例 #8
0
        private static CompositeType MakeElementType(CompositeType rowType)
        {
            List<string> names = new List<string>();
             List<string> descriptions = new List<string>();
             List<OpenType> types = new List<OpenType>();

             foreach (string itemName in rowType.KeySet)
             {
            if (itemName != CollectionIndexColumnName)
            {
               names.Add(itemName);
               descriptions.Add(rowType.GetDescription(itemName));
               types.Add(rowType.GetOpenType(itemName));
            }
             }
             return new CompositeType(rowType.TypeName, rowType.Description, names, descriptions, types);
        }