当前位置: 首页>>代码示例>>C#>>正文


C# HttpActionDescriptor类代码示例

本文整理汇总了C#中HttpActionDescriptor的典型用法代码示例。如果您正苦于以下问题:C# HttpActionDescriptor类的具体用法?C# HttpActionDescriptor怎么用?C# HttpActionDescriptor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


HttpActionDescriptor类属于命名空间,在下文中一共展示了HttpActionDescriptor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ElevateRouteData

        // Given an action, update the Controller Context's route data to use that action.
        // If you call action selection again after this method, it should still return the same result. 
        internal static void ElevateRouteData(this HttpControllerContext controllerContext, HttpActionDescriptor actionDescriptorSelected)
        {
            IHttpRouteData routeData = controllerContext.RouteData;

            IEnumerable<IHttpRouteData> multipleRouteData = routeData.GetSubRoutes();
            if (multipleRouteData == null)
            {
                return;
            }

            foreach (IHttpRouteData subData in multipleRouteData)
            {
                CandidateAction[] candidates = subData.Route.GetDirectRouteCandidates();

                if (candidates != null)
                {
                    foreach (CandidateAction candidate in candidates)
                    {
                        if (candidate.ActionDescriptor.Equals(actionDescriptorSelected))
                        {
                            controllerContext.RouteData = subData;
                            return;
                        }
                    }
                }
            }
        }
开发者ID:khorchani,项目名称:aspnetwebstack,代码行数:29,代码来源:HttpControllerContextExtensions.cs

示例2: GetModel

        public override IEdmModel GetModel(Type elementClrType, HttpRequestMessage request,
            HttpActionDescriptor actionDescriptor)
        {
            // Get model for the request
            IEdmModel model = request.ODataProperties().Model;

            if (model == null)
            {
                // user has not configured anything or has registered a model without the element type
                // let's create one just for this type and cache it in the action descriptor
                model = actionDescriptor.Properties.GetOrAdd("System.Web.OData.Model+" + elementClrType.FullName, _ =>
                {
                    ODataConventionModelBuilder builder =
                        new ODataConventionModelBuilder(actionDescriptor.Configuration, isQueryCompositionMode: true);
                    builder.EnableLowerCamelCase();
                    EntityTypeConfiguration entityTypeConfiguration = builder.AddEntityType(elementClrType);
                    builder.AddEntitySet(elementClrType.Name, entityTypeConfiguration);
                    IEdmModel edmModel = builder.GetEdmModel();
                    Contract.Assert(edmModel != null);
                    return edmModel;
                }) as IEdmModel;
            }

            Contract.Assert(model != null);
            return model;
        }
开发者ID:tanjinfu,项目名称:WebApiODataSamples,代码行数:26,代码来源:MyEnableQueryAttribute.cs

示例3: HasQueryableAttribute

 private static bool HasQueryableAttribute(HttpActionDescriptor actionDescriptor)
 {
     #pragma warning disable 0618 // Disable obsolete warning for QueryableAttribute.
     return actionDescriptor.GetCustomAttributes<QueryableAttribute>(inherit: true).Any() ||
          actionDescriptor.ControllerDescriptor.GetCustomAttributes<QueryableAttribute>(inherit: true).Any();
     #pragma warning restore 0618
 }
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:7,代码来源:QueryFilterProvider.cs

示例4: ElevateRouteData

        // Given an action, update the Controller Context's route data to use that action.
        // If you call action selection again after this method, it should still return the same result. 
        internal static void ElevateRouteData(this HttpControllerContext controllerContext, HttpActionDescriptor actionDescriptorSelected)
        {
            IHttpRouteData routeData = controllerContext.RouteData;

            IEnumerable<IHttpRouteData> multipleRouteData = routeData.GetSubRoutes();
            if (multipleRouteData == null)
            {
                return;
            }

            foreach (IHttpRouteData subData in multipleRouteData)
            {
                ReflectedHttpActionDescriptor[] actionDescriptors = subData.Route.GetDirectRouteActions();
                if (actionDescriptors != null)
                {
                    foreach (ReflectedHttpActionDescriptor ad in actionDescriptors)
                    {
                        if (ad.Equals(actionDescriptorSelected))
                        {
                            controllerContext.RouteData = subData;
                            return;
                        }
                    }
                }
            }
        }
开发者ID:jaceenet,项目名称:aspnetwebstack,代码行数:28,代码来源:HttpControllerContextExtensions.cs

示例5: CreateHttpRequestMessage

        private static HttpRequestMessage CreateHttpRequestMessage(HttpActionDescriptor actionDescriptor, ODataRoute oDataRoute, HttpConfiguration httpConfig)
        {
            Contract.Requires(httpConfig != null);
            Contract.Requires(oDataRoute != null);
            Contract.Requires(httpConfig != null);
            Contract.Ensures(Contract.Result<HttpRequestMessage>() != null);

            Contract.Assume(oDataRoute.Constraints != null);

            var httpRequestMessage = new HttpRequestMessage(actionDescriptor.SupportedHttpMethods.First(), "http://any/");

            var requestContext = new HttpRequestContext
            {
                Configuration = httpConfig
            };
            httpRequestMessage.SetConfiguration(httpConfig);
            httpRequestMessage.SetRequestContext(requestContext);

            var httpRequestMessageProperties = httpRequestMessage.ODataProperties();
            Contract.Assume(httpRequestMessageProperties != null);
            httpRequestMessageProperties.Model = oDataRoute.GetEdmModel();
            httpRequestMessageProperties.RouteName = oDataRoute.GetODataPathRouteConstraint().RouteName;
            httpRequestMessageProperties.RoutingConventions = oDataRoute.GetODataPathRouteConstraint().RoutingConventions;
            httpRequestMessageProperties.PathHandler = oDataRoute.GetODataPathRouteConstraint().PathHandler;
            return httpRequestMessage;
        }
开发者ID:bigred8982,项目名称:Swashbuckle.OData,代码行数:26,代码来源:AttributeRouteStrategy.cs

示例6: GetParameterValuePairs

        private IDictionary<string, object> GetParameterValuePairs(HttpActionDescriptor actionDescriptor)
        {
            IDictionary<string, object> parameterValuePairs = new Dictionary<string, object>();

            foreach (SwaggerDefaultValue defaultValue in actionDescriptor.GetCustomAttributes<SwaggerDefaultValue>())
            {
                parameterValuePairs.Add(defaultValue.Name, defaultValue.Value);
            }

            foreach (var parameter in actionDescriptor.GetParameters())
            {
                if (!parameter.ParameterType.IsPrimitive)
                {
                    foreach (PropertyInfo property in parameter.ParameterType.GetProperties())
                    {
                        var defaultValue = GetDefaultValue(property);

                        if (defaultValue != null)
                        {
                            parameterValuePairs.Add(property.Name, defaultValue);
                        }
                    }
                }
            }

            return parameterValuePairs;
        }
开发者ID:sudarsanan-krishnan,项目名称:DynamicsCRMConnector,代码行数:27,代码来源:AddDefaultsOpFilter.cs

示例7: CreateActionContext

 public static HttpActionContext CreateActionContext(HttpControllerContext controllerContext = null, HttpActionDescriptor actionDescriptor = null)
 {
     HttpControllerContext context = controllerContext ?? CreateControllerContext();
     HttpActionDescriptor descriptor = actionDescriptor ?? CreateActionDescriptor();
     descriptor.ControllerDescriptor = context.ControllerDescriptor;
     return new HttpActionContext(context, descriptor);
 }
开发者ID:nazhir,项目名称:kawaldesa,代码行数:7,代码来源:ContextUtils.cs

示例8: GetWrapResultAttributeOrNull

        public static WrapResultAttribute GetWrapResultAttributeOrNull(HttpActionDescriptor actionDescriptor)
        {
            if (actionDescriptor == null)
            {
                return null;
            }

            //Try to get for dynamic APIs (dynamic web api actions always define __OwDynamicApiDontWrapResultAttribute)
            var wrapAttr = actionDescriptor.Properties.GetOrDefault("__OwDynamicApiDontWrapResultAttribute") as WrapResultAttribute;
            if (wrapAttr != null)
            {
                return wrapAttr;
            }

            //Get for the action
            wrapAttr = actionDescriptor.GetCustomAttributes<WrapResultAttribute>().FirstOrDefault();
            if (wrapAttr != null)
            {
                return wrapAttr;
            }

            //Get for the controller
            wrapAttr = actionDescriptor.ControllerDescriptor.GetCustomAttributes<WrapResultAttribute>().FirstOrDefault();
            if (wrapAttr != null)
            {
                return wrapAttr;
            }

            //Not found
            return null;
        }
开发者ID:zhongkai1010,项目名称:OneWork,代码行数:31,代码来源:HttpActionDescriptorHelper.cs

示例9: GetMember

        private Member GetMember(HttpActionDescriptor actionDescriptor)
        {
            var reflectedActionDescriptor = actionDescriptor as ReflectedHttpActionDescriptor;
            if (reflectedActionDescriptor == null)
                return new Member();


            var xMember = _xMembers.Elements().FirstOrDefault(x => x.Attribute("name").Value == "M:" + GetMemberName(reflectedActionDescriptor.MethodInfo));
            if (xMember == null)
                return new Member();

            var xSummary = xMember.Element("summary");
            var xRemarks = xMember.Element("remarks");

            return new Member()
            {
                Summary = xSummary != null ? xSummary.Value : null,
                Remarks = xRemarks != null ? xRemarks.Value : null,
                Parameters = xMember.Elements("param").Select(p => new XParameter()
                {
                    Name = p.Attribute("name").Value,
                    Value = p.Value
                })
            };
        }
开发者ID:Tom-Kennedy,项目名称:Swagger.Net,代码行数:25,代码来源:XmlCommentDocumentationProvider.cs

示例10: GetDocumentation

		/// <summary>
		/// Gets the documentation based on <see cref="T:System.Web.Http.Controllers.HttpActionDescriptor" />.
		/// </summary>
		/// <param name="actionDescriptor">The action descriptor.</param>
		/// <returns>The documentation for the action.</returns>
		public virtual string GetDocumentation(HttpActionDescriptor actionDescriptor)
		{
			var methodNode = this.GetMethodNode(actionDescriptor);

			var s = new List<string>
						{
							GetTagValueForAction(methodNode, "summary"), 
							GetTagValueForAction(methodNode, "remarks")
						};

			// Add message if controller requires authorization
			if (actionDescriptor.GetCustomAttributes<AuthorizeAttribute>().Any())
			{
				s.Add("<p><i class='fa fa-lock'></i> Requires authorization!</p>");
			}

			// Add message if action is marked as Obsolete
			ObsoleteAttribute obsoleteAttribute = actionDescriptor.GetCustomAttributes<ObsoleteAttribute>().FirstOrDefault();
			if (obsoleteAttribute != null)
			{
				s.Add(string.Format("<p><i class='fa fa-warning'></i> This action is Obsolete: {0}</p>",
					string.IsNullOrEmpty(obsoleteAttribute.Message) ? "<i>unknown reason</i>" : obsoleteAttribute.Message));
			}

			return string.Join("", s.Where(x => !string.IsNullOrEmpty(x)));
		}
开发者ID:tarmopr,项目名称:Microsoft.AspNet.WebApi.HelpPage.Ex,代码行数:31,代码来源:MultipleXmlDocumentationProvider.cs

示例11: InvokeUsingActionResultAsync

        private static async Task<HttpResponseMessage> InvokeUsingActionResultAsync(HttpActionContext actionContext,
            HttpActionDescriptor actionDescriptor, CancellationToken cancellationToken)
        {
            Contract.Assert(actionContext != null);

            HttpControllerContext controllerContext = actionContext.ControllerContext;

            object result = await actionDescriptor.ExecuteAsync(controllerContext, actionContext.ActionArguments,
                cancellationToken);

            if (result == null)
            {
                throw new InvalidOperationException(SRResources.ApiControllerActionInvoker_NullHttpActionResult);
            }

            IHttpActionResult actionResult = result as IHttpActionResult;

            if (actionResult == null)
            {
                throw new InvalidOperationException(Error.Format(
                    SRResources.ApiControllerActionInvoker_InvalidHttpActionResult, result.GetType().Name));
            }

            HttpResponseMessage response = await actionResult.ExecuteAsync(cancellationToken);

            if (response == null)
            {
                throw new InvalidOperationException(
                    SRResources.ResponseMessageResultConverter_NullHttpResponseMessage);
            }

            response.EnsureResponseHasRequest(actionContext.Request);

            return response;
        }
开发者ID:samgithub-duplicate,项目名称:aspnetwebstack,代码行数:35,代码来源:ApiControllerActionInvoker.cs

示例12: GetDocumentation

        public string GetDocumentation(HttpActionDescriptor actionDescriptor)
        {
            XPathNavigator memberNode = GetMemberNode(actionDescriptor);

            if (memberNode != null)
            {
                XPathNavigator summaryNode = memberNode.SelectSingleNode("summary");
                XPathNavigator jsonNode = memberNode.SelectSingleNode("jsonResponse");

                if (summaryNode != null)
                {
                    var docDescription = new StringBuilder();

                    docDescription.Append(summaryNode.Value.Trim().Replace("[br]", "<br/>"));

                    if (jsonNode != null)
                    {
                        docDescription.AppendLine("<div class='json' style='display: none;'>");
                        docDescription.Append(jsonNode.Value.Trim());
                        docDescription.AppendLine("</div>");

                        docDescription.AppendLine("<pre>");
                        docDescription.AppendLine("</pre>");

                    }

                    return docDescription.ToString();
                }

            }

            return string.Empty;
        }
开发者ID:ahmetoz,项目名称:Photopia,代码行数:33,代码来源:XmlCommentDocumentationProvider.cs

示例13: Map

 public HttpParameterDescriptor Map(Parameter swaggerParameter, int parameterIndex, HttpActionDescriptor actionDescriptor)
 {
     var httpParameterDescriptors = actionDescriptor.GetParameters();
     Contract.Assume(httpParameterDescriptors != null);
     return httpParameterDescriptors
         .SingleOrDefault(descriptor => string.Equals(descriptor.ParameterName, swaggerParameter.name, StringComparison.CurrentCultureIgnoreCase));
 }
开发者ID:bigred8982,项目名称:Swashbuckle.OData,代码行数:7,代码来源:MapByParameterName.cs

示例14: Map

 public HttpParameterDescriptor Map(Parameter swaggerParameter, int parameterIndex, HttpActionDescriptor actionDescriptor)
 {
     // Maybe the parameter is a key parameter, e.g., where Id in the URI path maps to a parameter named 'key'
     if (swaggerParameter.description != null && swaggerParameter.description.StartsWith("key:"))
     {
         // Find either a single 'key' in the route or composite keys
         // which take the form of key<parameter name>
         var keyParameterName = swaggerParameter
                                 .description
                                 .Replace(FindKeyReplacementSubStr, 
                                             String.Empty)
                                 .ToLower();
         var parameterDescriptor = 
             actionDescriptor
                 .GetParameters()?
                 .SingleOrDefault(descriptor =>
                     descriptor.ParameterName.ToLower() == KeyName
                     || descriptor.ParameterName.ToLower().Equals(keyParameterName)
                 );
         if (parameterDescriptor != null && !parameterDescriptor.IsODataLibraryType())
         {
             var httpControllerDescriptor = actionDescriptor.ControllerDescriptor;
             Contract.Assume(httpControllerDescriptor != null);
             return new ODataParameterDescriptor(swaggerParameter.name, parameterDescriptor.ParameterType, parameterDescriptor.IsOptional, parameterDescriptor)
             {
                 Configuration = httpControllerDescriptor.Configuration,
                 ActionDescriptor = actionDescriptor,
                 ParameterBinderAttribute = parameterDescriptor.ParameterBinderAttribute
             };
         }
     }
     return null;
 }
开发者ID:rbeauchamp,项目名称:Swashbuckle.OData,代码行数:33,代码来源:MapByDescription.cs

示例15: ActionHasChangeSetEntityParameter

		internal static bool ActionHasChangeSetEntityParameter(HttpActionDescriptor actionDescriptor)
		{
			Contract.Assert(actionDescriptor != null);

			var parameters = actionDescriptor.GetParameters();
			return (parameters.Count > 0) && IsChangeSetEntityParameter(parameters[0]);
		}
开发者ID:mdabbagh88,项目名称:ODataServer,代码行数:7,代码来源:ChangeSetEntityModelBinder.cs


注:本文中的HttpActionDescriptor类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。