コード例 #1
0
        /// <summary>
        ///     Process an IEdmCollectionValue into a IEnumerable of CLR objects
        /// </summary>
        /// <param name="value">The collection delayedValue, recieved from an annotation</param>
        /// <param name="clarifiedType">A type describing the desired target collection type</param>
        /// <returns>A collection, of an instance of the clarifiedType, filled with values within the IEdmCollectionValue</returns>
        private static object MapToClr(IEdmCollectionValue value, Type clarifiedType = null)
        {
            if (clarifiedType == null)
            {
                return(null);
                //throw new ArgumentNullException("clarifiedType",
                //    "ClarifiedType must be defined to correctly return value of IEdmCollectionValue");
            }

            if (!clarifiedType.IsCollection())
            {
                throw new InvalidOperationException(
                          "Clarified type used for mapping to CLR values is not a valid collection type");
            }

            // Get the default constructor for the collection type and then invoke it.
            var collection = clarifiedType.CreateDefaultInstance();

            // Get an add method
            var addMethod = collection.GetType().GetMethod("Add", new[] { clarifiedType.GetGenericArguments().First() });

            foreach (var val in value.Elements)
            {
                addMethod.Invoke(collection, new[] { MapListElements(val) });
            }

            return(collection);
        }
コード例 #2
0
        private static void CompareCollectionValue(IEdmValue edmValue, ODataCollectionValue collectionValue, AssertionHandler assert)
        {
            assert.IsNotNull(edmValue, "EDM value instance must not be null.");

            if (collectionValue == null)
            {
                ValidateNullValue(edmValue, assert);
                return;
            }

            assert.AreEqual(EdmValueKind.Collection, edmValue.ValueKind, "Value kinds differ.");
            if (edmValue.Type != null)
            {
                assert.AreEqual(EdmTypeKind.Collection, edmValue.Type.TypeKind(), "Type kinds differ.");
            }

            IEdmCollectionValue edmCollectionValue = (IEdmCollectionValue)edmValue;
            IEnumerable         items = collectionValue.Items;

            if (items != null)
            {
                CompareCollectionItems(edmCollectionValue.Elements, items, assert);
            }
            else
            {
                assert.IsTrue(
                    edmCollectionValue.Elements == null || edmCollectionValue.Elements.Count() == 0,
                    "Expected empty collection value.");
            }
        }
コード例 #3
0
 public CastCollectionValue(IEdmCollectionTypeReference targetCollectionType, IEdmCollectionValue collectionValue)
 {
     this.targetCollectionType = targetCollectionType;
     this.collectionValue      = collectionValue;
 }