예제 #1
0
        /// <summary>
        /// Add the Edm. prefix to the primitive type if there isn't.
        /// </summary>
        /// <param name="typeName">The type name which may be not prefixed (Edm.).</param>
        /// <returns>The type name with Edm. prefix</returns>
        internal static string AddEdmPrefixOfTypeName(string typeName)
        {
            if (!string.IsNullOrEmpty(typeName))
            {
                string itemTypeName = EdmLibraryExtensions.GetCollectionItemTypeName(typeName);
                if (itemTypeName == null)
                {
                    // This is the primitive type
                    IEdmSchemaType primitiveType = EdmLibraryExtensions.ResolvePrimitiveTypeName(typeName);
                    if (primitiveType != null)
                    {
                        return(primitiveType.FullName());
                    }
                }
                else
                {
                    // This is the collection type
                    IEdmSchemaType primitiveType = EdmLibraryExtensions.ResolvePrimitiveTypeName(itemTypeName);
                    if (primitiveType != null)
                    {
                        return(EdmLibraryExtensions.GetCollectionTypeName(primitiveType.FullName()));
                    }
                }
            }

            // Return the origin type name
            return(typeName);
        }
예제 #2
0
        /// <summary>
        /// Remove the Edm. prefix from the type name if it is primitive type.
        /// </summary>
        /// <param name="typeName">The type name to remove the Edm. prefix</param>
        /// <returns>The type name without the Edm. Prefix</returns>
        internal static string RemoveEdmPrefixFromTypeName(string typeName)
        {
            if (!string.IsNullOrEmpty(typeName))
            {
                string itemTypeName = EdmLibraryExtensions.GetCollectionItemTypeName(typeName);
                if (itemTypeName == null)
                {
                    IEdmSchemaType primitiveType = EdmLibraryExtensions.ResolvePrimitiveTypeName(typeName);
                    if (primitiveType != null)
                    {
                        return(primitiveType.ShortQualifiedName());
                    }
                }
                else
                {
                    IEdmSchemaType primitiveType = EdmLibraryExtensions.ResolvePrimitiveTypeName(itemTypeName);
                    if (primitiveType != null)
                    {
                        return(EdmLibraryExtensions.GetCollectionTypeName(primitiveType.ShortQualifiedName()));
                    }
                }
            }

            return(typeName);
        }
예제 #3
0
        /// <summary>
        /// Prepare the type name for writing.
        /// 1) If it is primitive type, remove the Edm. prefix.
        /// 2) If it is a non-primitive type or 4.0, prefix with #.
        /// </summary>
        /// <param name="typeName">The type name to write</param>
        /// <param name="version">OData Version of payload being written</param>
        /// <returns>The type name for writing</returns>
        internal static string PrefixTypeNameForWriting(string typeName, ODataVersion version)
        {
            if (!string.IsNullOrEmpty(typeName))
            {
                string itemTypeName = EdmLibraryExtensions.GetCollectionItemTypeName(typeName);
                if (itemTypeName == null)
                {
                    IEdmSchemaType primitiveType = EdmLibraryExtensions.ResolvePrimitiveTypeName(typeName);
                    if (primitiveType != null)
                    {
                        typeName = primitiveType.ShortQualifiedName();
                        return(version < ODataVersion.V401 ? PrefixTypeName(typeName) : typeName);
                    }
                }
                else
                {
                    IEdmSchemaType primitiveType = EdmLibraryExtensions.ResolvePrimitiveTypeName(itemTypeName);
                    if (primitiveType != null)
                    {
                        typeName = EdmLibraryExtensions.GetCollectionTypeName(primitiveType.ShortQualifiedName());
                        return(version < ODataVersion.V401 ? PrefixTypeName(typeName) : typeName);
                    }
                }
            }

            return(PrefixTypeName(typeName));
        }