/// <summary>
        /// Validates that <paramref name="typeName"/> is a valid type name of the specified kind (<paramref name="typeKind"/>).
        /// </summary>
        /// <param name="metadata">The metadata against which to validate the type name.</param>
        /// <param name="typeName">The type name to validate.</param>
        /// <param name="typeKind">The expected <see cref="ResourceTypeKind"/> of the type.</param>
        /// <returns>A <see cref="ResourceType"/> for the <paramref name="typeName"/>.</returns>
        internal static ResourceType ValidateNonMultiValueTypeName(DataServiceMetadataProviderWrapper metadata, string typeName, ResourceTypeKind typeKind)
        {
            DebugUtils.CheckNoExternalCallers();
            Debug.Assert(metadata != null, "metadata != null");

            ResourceType resourceType = metadata.TryResolveResourceType(typeName);

            if (resourceType == null)
            {
                throw new ODataException(Strings.ODataWriterCore_UnrecognizedTypeName(typeName, typeKind));
            }

            if (resourceType.ResourceTypeKind != typeKind)
            {
                throw new ODataException(Strings.ODataWriterCore_IncorrectTypeKind(typeName, typeKind.ToString(), resourceType.ResourceTypeKind.ToString()));
            }

            return resourceType;
        }
        /// <summary>
        /// Validates that <paramref name="multiValueTypeName"/> is a valid type name for a MultiValue.
        /// </summary>
        /// <param name="metadata">The metadata against which to validate the type name.</param>
        /// <param name="multiValueTypeName">The name of the MultiValue.</param>
        /// <returns>A <see cref="MultiValueResourceType"/> for the <paramref name="multiValueTypeName"/>.</returns>
        internal static ResourceType ValidateMultiValueTypeName(DataServiceMetadataProviderWrapper metadata, string multiValueTypeName)
        {
            DebugUtils.CheckNoExternalCallers();
            Debug.Assert(metadata != null, "metadata != null");

            string itemTypeName = MetadataUtils.GetMultiValueItemTypeName(multiValueTypeName);

            if (itemTypeName == null)
            {
                throw new ODataException(Strings.ODataWriterCore_InvalidMultiValueTypeName(multiValueTypeName));
            }

            ResourceType resourceType = metadata.TryResolveResourceType(itemTypeName);

            if (resourceType == null)
            {
                // if we are resolving a MultiValue the item type might be primitive
                ResourceType[] primitiveTypes = PrimitiveTypeUtils.PrimitiveTypes;
                for (int i = 0; i < primitiveTypes.Length; ++i)
                {
                    ResourceType primitiveType = primitiveTypes[i];
                    if (string.CompareOrdinal(itemTypeName, primitiveType.FullName) == 0)
                    {
                        resourceType = primitiveType;
                        break;
                    }
                }
            }

            if (resourceType == null)
            {
                throw new ODataException(Strings.ODataWriterCore_UnrecognizedTypeName(multiValueTypeName, ResourceTypeKind.MultiValue));
            }

            // create a MultiValue resource type from the item type
            resourceType = ResourceType.GetMultiValueResourceType(resourceType);

            return resourceType;
        }