// The As*** functions never return null -- if the supplied type does not have the appropriate shape, an encoding of a bad type is returned. #region AsPrimitive, AsCollection, AsStructured, ... /// <summary> /// If this reference is of a primitive type, this will return a valid primitive type reference to the type definition. Otherwise, it will return a bad primitive type reference. /// </summary> /// <param name="type">Reference to the calling object.</param> /// <returns>A valid primitive type reference if the definition of the reference is of a primitive type. Otherwise a bad primitive type reference.</returns> public static IEdmPrimitiveTypeReference AsPrimitive(this IEdmTypeReference type) { EdmUtil.CheckArgumentNull(type, "type"); IEdmPrimitiveTypeReference reference = type as IEdmPrimitiveTypeReference; if (reference != null) { return(reference); } IEdmType typeDefinition = type.Definition; if (typeDefinition.TypeKind == EdmTypeKind.Primitive) { var primitiveDefinition = typeDefinition as IEdmPrimitiveType; if (primitiveDefinition != null) { switch (primitiveDefinition.PrimitiveKind) { case EdmPrimitiveTypeKind.Boolean: case EdmPrimitiveTypeKind.Byte: case EdmPrimitiveTypeKind.Double: case EdmPrimitiveTypeKind.Guid: case EdmPrimitiveTypeKind.Int16: case EdmPrimitiveTypeKind.Int32: case EdmPrimitiveTypeKind.Int64: case EdmPrimitiveTypeKind.SByte: case EdmPrimitiveTypeKind.Single: case EdmPrimitiveTypeKind.Stream: return(new EdmPrimitiveTypeReference(primitiveDefinition, type.IsNullable)); case EdmPrimitiveTypeKind.Binary: return(type.AsBinary()); case EdmPrimitiveTypeKind.Decimal: return(type.AsDecimal()); case EdmPrimitiveTypeKind.String: return(type.AsString()); case EdmPrimitiveTypeKind.Duration: case EdmPrimitiveTypeKind.DateTimeOffset: return(type.AsTemporal()); case EdmPrimitiveTypeKind.Geography: case EdmPrimitiveTypeKind.GeographyPoint: case EdmPrimitiveTypeKind.GeographyLineString: case EdmPrimitiveTypeKind.GeographyPolygon: case EdmPrimitiveTypeKind.GeographyCollection: case EdmPrimitiveTypeKind.GeographyMultiPolygon: case EdmPrimitiveTypeKind.GeographyMultiLineString: case EdmPrimitiveTypeKind.GeographyMultiPoint: case EdmPrimitiveTypeKind.Geometry: case EdmPrimitiveTypeKind.GeometryPoint: case EdmPrimitiveTypeKind.GeometryLineString: case EdmPrimitiveTypeKind.GeometryPolygon: case EdmPrimitiveTypeKind.GeometryCollection: case EdmPrimitiveTypeKind.GeometryMultiPolygon: case EdmPrimitiveTypeKind.GeometryMultiLineString: case EdmPrimitiveTypeKind.GeometryMultiPoint: return(type.AsSpatial()); case EdmPrimitiveTypeKind.None: break; } } } else if (typeDefinition.TypeKind == EdmTypeKind.TypeDefinition) { return(new EdmPrimitiveTypeReference(typeDefinition.UnderlyingType(), type.IsNullable)); } string typeFullName = type.FullName(); List <EdmError> errors = new List <EdmError>(type.Errors()); if (errors.Count == 0) { errors.AddRange(ConversionError(type.Location(), typeFullName, EdmConstants.Type_Primitive)); } return(new BadPrimitiveTypeReference(typeFullName, type.IsNullable, errors)); }
internal static IEdmType AsActualType(this IEdmType type) { IEdmPrimitiveType underlyingType = type.UnderlyingType(); return(underlyingType ?? type); }