コード例 #1
0
        /// <inheritdoc />
        public virtual void ApplyTo(ApiDescription apiDescription)
        {
            Arg.NotNull(apiDescription, nameof(apiDescription));

            if (!IsSupported(apiDescription))
            {
                return;
            }

            var context      = new ODataQueryOptionDescriptionContext(ValidationSettings);
            var model        = apiDescription.EdmModel();
            var queryOptions = GetQueryOptions(Settings.DefaultQuerySettings, context);
            var singleResult = IsSingleResult(apiDescription, out var resultType);
            var visitor      = new ODataAttributeVisitor(context, model, queryOptions, resultType, singleResult);

            visitor.Visit(apiDescription);

            var options = visitor.AllowedQueryOptions;
            var parameterDescriptions = apiDescription.ParameterDescriptions;

            if (options.HasFlag(Select))
            {
                parameterDescriptions.Add(NewSelectParameter(context));
            }

            if (options.HasFlag(Expand))
            {
                parameterDescriptions.Add(NewExpandParameter(context));
            }

            if (singleResult)
            {
                return;
            }

            if (options.HasFlag(Filter))
            {
                parameterDescriptions.Add(NewFilterParameter(context));
            }

            if (options.HasFlag(OrderBy))
            {
                parameterDescriptions.Add(NewOrderByParameter(context));
            }

            if (options.HasFlag(Top))
            {
                parameterDescriptions.Add(NewTopParameter(context));
            }

            if (options.HasFlag(Skip))
            {
                parameterDescriptions.Add(NewSkipParameter(context));
            }

            if (options.HasFlag(Count))
            {
                parameterDescriptions.Add(NewCountParameter(context));
            }
        }
        /// <inheritdoc />
        public virtual void ApplyTo(ApiDescription apiDescription)
        {
            if (apiDescription == null)
            {
                throw new ArgumentNullException(nameof(apiDescription));
            }

            if (!IsSupported(apiDescription.HttpMethod.Method))
            {
                return;
            }

            var context      = new ODataQueryOptionDescriptionContext(ValidationSettings);
            var model        = apiDescription.EdmModel();
            var queryOptions = GetQueryOptions(apiDescription.ActionDescriptor.Configuration.GetDefaultQuerySettings(), context);
            var singleResult = IsSingleResult(apiDescription, out var resultType);
            var visitor      = new ODataAttributeVisitor(context, model, queryOptions, resultType, singleResult);

            visitor.Visit(apiDescription);

            var options = visitor.AllowedQueryOptions;
            var parameterDescriptions = apiDescription.ParameterDescriptions;

            if (options.HasFlag(Select))
            {
                parameterDescriptions.Add(SetAction(NewSelectParameter(context), apiDescription));
            }

            if (options.HasFlag(Expand))
            {
                parameterDescriptions.Add(SetAction(NewExpandParameter(context), apiDescription));
            }

            if (singleResult)
            {
                return;
            }

            if (options.HasFlag(Filter))
            {
                parameterDescriptions.Add(SetAction(NewFilterParameter(context), apiDescription));
            }

            if (options.HasFlag(OrderBy))
            {
                parameterDescriptions.Add(SetAction(NewOrderByParameter(context), apiDescription));
            }

            if (options.HasFlag(Top))
            {
                parameterDescriptions.Add(SetAction(NewTopParameter(context), apiDescription));
            }

            if (options.HasFlag(Skip))
            {
                parameterDescriptions.Add(SetAction(NewSkipParameter(context), apiDescription));
            }

            if (options.HasFlag(Count))
            {
                parameterDescriptions.Add(SetAction(NewCountParameter(context), apiDescription));
            }
        }