/// <summary> /// Validates a type kind for a value type. /// </summary> /// <param name="typeKind">The type kind.</param> /// <param name="typeName">The name of the type (used for error reporting only).</param> internal static void ValidateValueTypeKind(EdmTypeKind typeKind, string typeName) { Debug.Assert(typeName != null, "typeName != null"); if (typeKind != EdmTypeKind.Primitive && typeKind != EdmTypeKind.Enum && typeKind != EdmTypeKind.Complex && typeKind != EdmTypeKind.Collection) { throw new ODataException(Strings.ValidationUtils_IncorrectValueTypeKind(typeName, typeKind.ToString())); } }
/// <summary> /// Validates that the observed type kind is the expected type kind. /// </summary> /// <param name="actualTypeKind">The actual type kind to compare.</param> /// <param name="expectedTypeKind">The expected type kind to compare against.</param> /// <param name="typeName">The name of the type to use in the error.</param> internal static void ValidateTypeKind(EdmTypeKind actualTypeKind, EdmTypeKind expectedTypeKind, string typeName) { if (actualTypeKind != expectedTypeKind) { if (typeName == null) { throw new ODataException(Strings.ValidationUtils_IncorrectTypeKindNoTypeName(actualTypeKind.ToString(), expectedTypeKind.ToString())); } if (actualTypeKind == EdmTypeKind.TypeDefinition && expectedTypeKind == EdmTypeKind.Primitive || actualTypeKind == EdmTypeKind.Primitive && expectedTypeKind == EdmTypeKind.TypeDefinition) { return; } throw new ODataException(Strings.ValidationUtils_IncorrectTypeKind(typeName, expectedTypeKind.ToString(), actualTypeKind.ToString())); } }
internal static void ValidateValueTypeKind(EdmTypeKind typeKind, string typeName) { if (((typeKind != EdmTypeKind.Primitive) && (typeKind != EdmTypeKind.Complex)) && (typeKind != EdmTypeKind.Collection)) { throw new ODataException(Microsoft.Data.OData.Strings.ValidationUtils_IncorrectValueTypeKind(typeName, typeKind.ToString())); } }
internal static void ValidateTypeKind(EdmTypeKind actualTypeKind, EdmTypeKind expectedTypeKind, string typeName) { if (actualTypeKind != expectedTypeKind) { if (typeName == null) { throw new ODataException(Microsoft.Data.OData.Strings.ValidationUtils_IncorrectTypeKindNoTypeName(actualTypeKind.ToString(), expectedTypeKind.ToString())); } throw new ODataException(Microsoft.Data.OData.Strings.ValidationUtils_IncorrectTypeKind(typeName, expectedTypeKind.ToString(), actualTypeKind.ToString())); } }
/// <summary> /// Validates that the observed type kind is the expected type kind. /// </summary> /// <param name="actualTypeKind">The actual type kind to compare.</param> /// <param name="expectedTypeKind">The expected type kind to compare against.</param> /// <param name="typeName">The name of the type to use in the error.</param> internal static void ValidateTypeKind(EdmTypeKind actualTypeKind, EdmTypeKind expectedTypeKind, string typeName) { DebugUtils.CheckNoExternalCallers(); if (actualTypeKind != expectedTypeKind) { if (typeName == null) { throw new ODataException(Strings.ValidationUtils_IncorrectTypeKindNoTypeName(actualTypeKind.ToString(), expectedTypeKind.ToString())); } throw new ODataException(Strings.ValidationUtils_IncorrectTypeKind(typeName, expectedTypeKind.ToString(), actualTypeKind.ToString())); } }
/// <summary> /// Validates a type kind for a value type. /// </summary> /// <param name="typeKind">The type kind.</param> /// <param name="typeName">The name of the type (used for error reporting only).</param> internal static void ValidateValueTypeKind(EdmTypeKind typeKind, string typeName) { DebugUtils.CheckNoExternalCallers(); Debug.Assert(typeName != null, "typeName != null"); if (typeKind != EdmTypeKind.Primitive && typeKind != EdmTypeKind.Complex && typeKind != EdmTypeKind.Collection) { throw new ODataException(Strings.ValidationUtils_IncorrectValueTypeKind(typeName, typeKind.ToString())); } }
private static IEdmTypeReference GetEdmTypeReference(Dictionary <Type, IEdmType> availableTypes, IEdmTypeConfiguration configuration, bool nullable) { Contract.Assert(availableTypes != null); if (configuration == null) { return(null); } EdmTypeKind kind = configuration.Kind; if (kind == EdmTypeKind.Collection) { CollectionTypeConfiguration collectionType = configuration as CollectionTypeConfiguration; bool elementNullable = EdmLibHelpers.IsNullable(collectionType.ElementType.ClrType); EdmCollectionType edmCollectionType = new EdmCollectionType(GetEdmTypeReference(availableTypes, collectionType.ElementType, elementNullable)); return(new EdmCollectionTypeReference(edmCollectionType)); } else { Type configurationClrType = TypeHelper.GetUnderlyingTypeOrSelf(configuration.ClrType); if (!configurationClrType.IsEnum) { configurationClrType = configuration.ClrType; } IEdmType type; if (availableTypes.TryGetValue(configurationClrType, out type)) { if (kind == EdmTypeKind.Complex) { return(new EdmComplexTypeReference((IEdmComplexType)type, nullable)); } else if (kind == EdmTypeKind.Entity) { return(new EdmEntityTypeReference((IEdmEntityType)type, nullable)); } else if (kind == EdmTypeKind.Enum) { return(new EdmEnumTypeReference((IEdmEnumType)type, nullable)); } else { throw Error.InvalidOperation(SRResources.UnsupportedEdmTypeKind, kind.ToString()); } } else if (configuration.Kind == EdmTypeKind.Primitive) { PrimitiveTypeConfiguration primitiveTypeConfiguration = configuration as PrimitiveTypeConfiguration; return(new EdmPrimitiveTypeReference(primitiveTypeConfiguration.EdmPrimitiveType, nullable)); } else { throw Error.InvalidOperation(SRResources.NoMatchingIEdmTypeFound, configuration.FullName); } } }