Пример #1
0
        internal static IEdmOperation[] CalculateBindableOperationsForType(IEdmType bindingType, IEdmModel model, EdmTypeResolver edmTypeResolver)
        {
            Debug.Assert(model != null, "model != null");
            Debug.Assert(edmTypeResolver != null, "edmTypeResolver != null");

            List <IEdmOperation> operations = null;

            try
            {
                operations = model.FindBoundOperations(bindingType).ToList();
            }
            catch (Exception exc)
            {
                if (!ExceptionUtils.IsCatchableExceptionType(exc))
                {
                    throw;
                }

                throw new ODataException(Strings.MetadataUtils_CalculateBindableOperationsForType(bindingType.FullTypeName()), exc);
            }

            List <IEdmOperation> operationsFound = new List <IEdmOperation>();

            foreach (IEdmOperation operation in operations.EnsureOperationsBoundWithBindingParameter())
            {
                IEdmOperationParameter bindingParameter = operation.Parameters.FirstOrDefault();
                IEdmType resolvedBindingType            = edmTypeResolver.GetParameterType(bindingParameter).Definition;
                if (resolvedBindingType.IsAssignableFrom(bindingType))
                {
                    operationsFound.Add(operation);
                }
            }

            return(operationsFound.ToArray());
        }
Пример #2
0
        /// <summary>
        /// Calculates the operations that are bindable to the given type.
        /// </summary>
        /// <param name="bindingType">The binding type in question.</param>
        /// <param name="model">The model to search for operations.</param>
        /// <param name="edmTypeResolver">The edm type resolver to get the parameter type.</param>
        /// <returns>An enumeration of operations that are always bindable to the given type.</returns>
        internal static IList <IEdmOperation> CalculateBindableOperationsForType(IEdmType bindingType, IEdmModel model, EdmTypeResolver edmTypeResolver)
        {
            Debug.Assert(model != null, "model != null");
            Debug.Assert(edmTypeResolver != null, "edmTypeResolver != null");

            IEnumerable <IEdmOperation> operations = null;

            try
            {
                operations = model.FindBoundOperations(bindingType);
            }
            catch (Exception exc)
            {
                if (!ExceptionUtils.IsCatchableExceptionType(exc))
                {
                    throw;
                }

                throw new ODataException(Strings.MetadataUtils_CalculateBindableOperationsForType(bindingType.FullTypeName()), exc);
            }

            List <IEdmOperation> operationsFound = new List <IEdmOperation>();

            foreach (IEdmOperation operation in operations)
            {
                if (!operation.IsBound)
                {
                    throw new ODataException(Strings.EdmLibraryExtensions_UnBoundOperationsFoundFromIEdmModelFindMethodIsInvalid(operation.Name));
                }

                if (operation.Parameters.FirstOrDefault() == null)
                {
                    throw new ODataException(Strings.EdmLibraryExtensions_NoParameterBoundOperationsFoundFromIEdmModelFindMethodIsInvalid(operation.Name));
                }

                IEdmOperationParameter bindingParameter = operation.Parameters.FirstOrDefault();
                IEdmType resolvedBindingType            = edmTypeResolver.GetParameterType(bindingParameter).Definition;
                if (resolvedBindingType.IsAssignableFrom(bindingType))
                {
                    operationsFound.Add(operation);
                }
            }

            return(operationsFound);
        }