示例#1
0
        private static bool TryGetElementTypeReference(
            this IEdmTypeReference typeReference, out IEdmTypeReference elementTypeReference)
        {
            if (!typeReference.IsCollection())
            {
                elementTypeReference = null;
                return false;
            }

            elementTypeReference = typeReference.AsCollection().ElementType();
            return true;
        }
示例#2
0
 internal static IEdmCollectionTypeReference AsCollectionOrNull(this IEdmTypeReference typeReference)
 {
     if (typeReference == null)
     {
         return null;
     }
     if (typeReference.TypeKind() != EdmTypeKind.Collection)
     {
         return null;
     }
     IEdmCollectionTypeReference reference = typeReference.AsCollection();
     if (!reference.IsNonEntityODataCollectionTypeKind())
     {
         return null;
     }
     return reference;
 }
        /// <summary>
        /// Casts an <see cref="IEdmTypeReference"/> to a <see cref="IEdmCollectionTypeReference"/> or returns null if this is not supported.
        /// </summary>
        /// <param name="typeReference">The type reference to convert.</param>
        /// <returns>An <see cref="IEdmCollectionTypeReference"/> instance or null if the <paramref name="typeReference"/> cannot be converted.</returns>
        internal static IEdmCollectionTypeReference AsCollectionOrNull(this IEdmTypeReference typeReference)
        {
            DebugUtils.CheckNoExternalCallers();

            if (typeReference == null)
            {
                return null;
            }

            if (typeReference.TypeKind() != EdmTypeKind.Collection)
            {
                return null;
            }

            IEdmCollectionTypeReference collectionTypeReference = typeReference.AsCollection();
            if (!collectionTypeReference.IsNonEntityODataCollectionTypeKind())
            {
                return null;
            }

            return collectionTypeReference;
        }
示例#4
0
 /// <summary>
 /// Get the <see cref="IEdmEntityTypeReference"/> of the item type of the <paramref name="typeReference"/>.
 /// </summary>
 /// <param name="typeReference">The collection type to get the item type for.</param>
 /// <returns>The item type of the <paramref name="typeReference"/>.</returns>
 public static IEdmTypeReference GetCollectionItemType(this IEdmTypeReference typeReference)
 {
     IEdmCollectionTypeReference collectionType = typeReference.AsCollection();
     return collectionType == null ? null : collectionType.ElementType();
 }
        /// <summary>
        /// Constructs a new type reference with the specified nullable value
        /// </summary>
        /// <param name="typeReference">The original type reference</param>
        /// <param name="isNullable">The nullable value</param>
        /// <returns>A new type reference, with the specified nullable value</returns>
        public static IEdmTypeReference Nullable(this IEdmTypeReference typeReference, bool isNullable)
        {
            switch (typeReference.TypeKind())
            {
                case EdmTypeKind.Collection:
                    var collection = typeReference.AsCollection();
                    return new EdmCollectionTypeReference(collection.CollectionDefinition());

                case EdmTypeKind.Complex:
                    var complex = typeReference.AsComplex();
                    return new EdmComplexTypeReference(complex.ComplexDefinition(), isNullable);

                case EdmTypeKind.Entity:
                    var entity = typeReference.AsEntity();
                    return new EdmEntityTypeReference(entity.EntityDefinition(), isNullable);

                case EdmTypeKind.EntityReference:
                    var entityRef = typeReference.AsEntityReference();
                    return new EdmEntityReferenceTypeReference(entityRef.EntityReferenceDefinition(), isNullable);

                case EdmTypeKind.Primitive:
                    var primitive = (EdmPrimitiveTypeReference)typeReference.AsPrimitive();
                    return primitive.Nullable(isNullable);

                default:
                    throw new TaupoInvalidOperationException("Unexpected Edm Type Kind: " + typeReference.TypeKind());
            }
        }