Esempio n. 1
0
 internal static IEdmEntityTypeReference AsEntityOrNull(this IEdmTypeReference typeReference)
 {
     if (typeReference == null)
     {
         return null;
     }
     if (typeReference.TypeKind() != EdmTypeKind.Entity)
     {
         return null;
     }
     return typeReference.AsEntity();
 }
        /// <summary>
        /// Casts an <see cref="IEdmTypeReference"/> to a <see cref="IEdmComplexTypeReference"/> or returns null if this is not supported.
        /// </summary>
        /// <param name="typeReference">The type reference to convert.</param>
        /// <returns>An <see cref="IEdmComplexTypeReference"/> instance or null if the <paramref name="typeReference"/> cannot be converted.</returns>
        internal static IEdmEntityTypeReference AsEntityOrNull(this IEdmTypeReference typeReference)
        {
            DebugUtils.CheckNoExternalCallers();

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

            return typeReference.TypeKind() == EdmTypeKind.Entity ? typeReference.AsEntity() : null;
        }
Esempio n. 3
0
		public static IEdmStructuredTypeReference AsStructured(this IEdmTypeReference type)
		{
			string str;
			List<EdmError> edmErrors;
			EdmUtil.CheckArgumentNull<IEdmTypeReference>(type, "type");
			IEdmStructuredTypeReference edmStructuredTypeReference = type as IEdmStructuredTypeReference;
			if (edmStructuredTypeReference == null)
			{
				EdmTypeKind edmTypeKind = type.TypeKind();
				switch (edmTypeKind)
				{
					case EdmTypeKind.Entity:
					{
						return type.AsEntity();
					}
					case EdmTypeKind.Complex:
					{
						return type.AsComplex();
					}
					case EdmTypeKind.Row:
					{
						return type.AsRow();
					}
					default:
					{
						str = type.FullName();
						edmErrors = new List<EdmError>(type.TypeErrors());
						if (edmErrors.Count != 0)
						{
							break;
						}
						edmErrors.AddRange(EdmTypeSemantics.ConversionError(type.Location(), str, "Structured"));
						break;
					}
				}
				return new BadEntityTypeReference(str, type.IsNullable, edmErrors);
			}
			else
			{
				return edmStructuredTypeReference;
			}
		}
Esempio n. 4
0
        /// <summary>
        /// If this reference is of a structured type, this will return a valid structured type reference to the type definition. Otherwise, it will return a bad structured type reference.
        /// </summary>
        /// <param name="type">Reference to the calling object.</param>
        /// <returns>A valid structured type reference if the definition of the reference is of a structured type. Otherwise a bad structured type reference.</returns>
        public static IEdmStructuredTypeReference AsStructured(this IEdmTypeReference type)
        {
            EdmUtil.CheckArgumentNull(type, "type");
            IEdmStructuredTypeReference reference = type as IEdmStructuredTypeReference;
            if (reference != null)
            {
                return reference;
            }

            switch (type.TypeKind())
            {
                case EdmTypeKind.Entity:
                    return type.AsEntity();
                case EdmTypeKind.Complex:
                    return type.AsComplex();
            }

            string typeFullName = type.FullName();
            List<EdmError> errors = new List<EdmError>(type.TypeErrors());
            if (errors.Count == 0)
            {
                errors.AddRange(ConversionError(type.Location(), typeFullName, EdmConstants.Type_Structured));
            }

            return new BadEntityTypeReference(typeFullName, type.IsNullable, errors);
        }
        /// <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());
            }
        }