Ejemplo n.º 1
0
        private static IEdmType ResolveTypeName(IEdmModel model, IEdmType expectedType, string typeName, Func <IEdmType, string, IEdmType> customTypeResolver, ODataVersion version, out EdmTypeKind typeKind)
        {
            IEdmType    collectionType = null;
            EdmTypeKind kind;
            string      str = (version >= ODataVersion.V3) ? EdmLibraryExtensions.GetCollectionItemTypeName(typeName) : null;

            if (str == null)
            {
                if ((customTypeResolver != null) && model.IsUserModel())
                {
                    collectionType = customTypeResolver(expectedType, typeName);
                    if (collectionType == null)
                    {
                        throw new ODataException(Microsoft.Data.OData.Strings.MetadataUtils_ResolveTypeName(typeName));
                    }
                }
                else
                {
                    collectionType = model.FindType(typeName);
                }
                if (((version < ODataVersion.V3) && (collectionType != null)) && collectionType.IsSpatial())
                {
                    collectionType = null;
                }
                typeKind = (collectionType == null) ? EdmTypeKind.None : collectionType.TypeKind;
                return(collectionType);
            }
            typeKind = EdmTypeKind.Collection;
            IEdmType definition = null;

            if (((customTypeResolver != null) && (expectedType != null)) && (expectedType.TypeKind == EdmTypeKind.Collection))
            {
                definition = ((IEdmCollectionType)expectedType).ElementType.Definition;
            }
            IEdmType itemType = ResolveTypeName(model, definition, str, customTypeResolver, version, out kind);

            if (itemType != null)
            {
                collectionType = EdmLibraryExtensions.GetCollectionType(itemType);
            }
            return(collectionType);
        }
Ejemplo n.º 2
0
        internal static IEdmType ResolveTypeName(
            IEdmModel model,
            IEdmType expectedType,
            string typeName,
            Func <IEdmType, string, IEdmType> customTypeResolver,
            ODataVersion version,
            out EdmTypeKind typeKind)
        {
            DebugUtils.CheckNoExternalCallers();

            Debug.Assert(model != null, "model != null");
            Debug.Assert(typeName != null, "typeName != null");
            IEdmType resolvedType = null;

            // Collection types should only be recognized in V3 and higher.
            string itemTypeName = version >= ODataVersion.V3 ? EdmLibraryExtensions.GetCollectionItemTypeName(typeName) : null;

            if (itemTypeName == null)
            {
                // Note: we require the type resolver or the model to also resolve
                //       primitive types.
                if (customTypeResolver != null && model.IsUserModel())
                {
                    resolvedType = customTypeResolver(expectedType, typeName);
                    if (resolvedType == null)
                    {
                        // If a type resolver is specified it must never return null.
                        throw new ODataException(Strings.MetadataUtils_ResolveTypeName(typeName));
                    }
                }
                else
                {
                    resolvedType = model.FindType(typeName);
                }

                // Spatial types are only recognized in V3 and higher.
                if (version < ODataVersion.V3 && resolvedType != null && resolvedType.IsSpatial())
                {
                    resolvedType = null;
                }

                typeKind = resolvedType == null ? EdmTypeKind.None : resolvedType.TypeKind;
            }
            else
            {
                // Collection
                typeKind = EdmTypeKind.Collection;
                EdmTypeKind itemTypeKind;

                IEdmType expectedItemType = null;
                if (customTypeResolver != null && expectedType != null && expectedType.TypeKind == EdmTypeKind.Collection)
                {
                    expectedItemType = ((IEdmCollectionType)expectedType).ElementType.Definition;
                }

                IEdmType itemType = ResolveTypeName(model, expectedItemType, itemTypeName, customTypeResolver, version, out itemTypeKind);
                if (itemType != null)
                {
                    resolvedType = EdmLibraryExtensions.GetCollectionType(itemType);
                }
            }

            return(resolvedType);
        }