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


C# HttpActionDescriptor.GetCustomAttributes方法代码示例

本文整理汇总了C#中HttpActionDescriptor.GetCustomAttributes方法的典型用法代码示例。如果您正苦于以下问题:C# HttpActionDescriptor.GetCustomAttributes方法的具体用法?C# HttpActionDescriptor.GetCustomAttributes怎么用?C# HttpActionDescriptor.GetCustomAttributes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在HttpActionDescriptor的用法示例。


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

示例1: 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

示例2: 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

示例3: GetNewActionDescriptor

        private HttpActionDescriptor GetNewActionDescriptor(
            VersionNumber theRequestedApiVersion, 
            HttpActionDescriptor theOriginalHttpActionDescriptor)
        {
            var aApiVersionAttributes = theOriginalHttpActionDescriptor.GetCustomAttributes<ApiVersionAttribute>();
            if (aApiVersionAttributes == null || aApiVersionAttributes.Count == 0)
            {
                return theOriginalHttpActionDescriptor;
            }

            var aActionMappings = GetActionMapping(theOriginalHttpActionDescriptor.ControllerDescriptor);
            var aMatchedActionDescriptorMappings = new Dictionary<VersionNumber, HttpActionDescriptor>();
            foreach (var aApiVersionAttribute in aApiVersionAttributes)
            {
                var aActionName = aApiVersionAttribute.OperatioName;
                if (!aActionMappings.Contains(aActionName))
                {
                    continue;
                }

                var aHttpActionDescriptor = aActionMappings[aActionName].ElementAt(0);
                aMatchedActionDescriptorMappings[aApiVersionAttribute.VersionNumber] = aHttpActionDescriptor;
            }

            // this mapping could be cached
            if (aMatchedActionDescriptorMappings.Count == 0)
            {
                return theOriginalHttpActionDescriptor;
            }

            // customize version select logic here
            return CustomizedActionDescriptorSelector(theRequestedApiVersion, aMatchedActionDescriptorMappings);
        }
开发者ID:Elhx,项目名称:hxreport,代码行数:33,代码来源:WsActionSelector.cs

示例4: 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

示例5: 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

示例6: GetActionRouteFactories

 protected override IReadOnlyList<IDirectRouteFactory> GetActionRouteFactories(HttpActionDescriptor actionDescriptor)
 {
     //Honor inherited route attributes, but only for the MicroCms.WebApi assembly.
     // To reduce conflicts and changing global behavior for apps that host MicroCms Web API
     if (IsCmsApiController(actionDescriptor.ControllerDescriptor.ControllerType))
         return actionDescriptor.GetCustomAttributes<IDirectRouteFactory>(true);
     return base.GetActionRouteFactories(actionDescriptor);
 }
开发者ID:Steinerd,项目名称:MicroCms,代码行数:8,代码来源:CmsDirectRouteProvider.cs

示例7: GetFilters

        /// <summary>
        /// Returns an enumeration of filters.
        /// </summary>
        /// <param name="configuration">The HTTP configuration.</param>
        /// <param name="actionDescriptor">The action descriptor.</param>
        /// <returns>
        /// An enumeration of filters.
        /// </returns>
        public IEnumerable<FilterInfo> GetFilters(HttpConfiguration configuration, HttpActionDescriptor actionDescriptor) {
            if (actionDescriptor == null ||
                (!IsIQueryable(actionDescriptor.ReturnType)) ||
                actionDescriptor.GetCustomAttributes<QueryableAttribute>().Any() ||
                actionDescriptor.GetParameters().Any(parameter => typeof (ODataQueryOptions).IsAssignableFrom(parameter.ParameterType)))
                return Enumerable.Empty<FilterInfo>();

            return new[] {new FilterInfo(_filter, FilterScope.Global)};
        }
开发者ID:amartelr,项目名称:Beetle.js,代码行数:17,代码来源:BeetleQueryableFilterProvider.cs

示例8:

        string IDocumentationProvider.GetDocumentation(HttpActionDescriptor actionDescriptor)
        {
            var actionDoc = actionDescriptor.GetCustomAttributes<ActionDocAttribute>().FirstOrDefault();
            if (actionDoc != null)
            {
                return actionDoc.Documentation;
            }

            return string.Format("Documentation for '{0}'.", actionDescriptor.ActionName);
        }
开发者ID:jacktsai,项目名称:WebApiSurvey,代码行数:10,代码来源:MyDocumentationProvider.cs

示例9: GetResponseDocumentation

        public string GetResponseDocumentation(HttpActionDescriptor actionDescriptor)
        {
            var apiDocumentation = actionDescriptor.GetCustomAttributes<ApiResponseDocumentationAttribute>().FirstOrDefault();
            if (apiDocumentation != null)
            {
                return apiDocumentation.Description;
            }

            return String.Empty;
        }
开发者ID:huangw-t,项目名称:aspnetwebstack,代码行数:10,代码来源:AttributeDocumentationProvider.cs

示例10: GetDocumentation

 public string GetDocumentation(HttpActionDescriptor actionDescriptor)
 {
     string doc = "";
     var attr = actionDescriptor.GetCustomAttributes<ApiDocAttribute>().FirstOrDefault();
     if (attr != null)
     {
         doc = attr.Documentation;
     }
     return doc;
 }
开发者ID:flower1990,项目名称:ZhenShiWenHua,代码行数:10,代码来源:DocProvider.cs

示例11: GetODataActionDescriptorFromAttributeRoute

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

            var odataRouteAttribute = actionDescriptor.GetCustomAttributes<ODataRouteAttribute>()?.FirstOrDefault();
            Contract.Assume(odataRouteAttribute != null);
            var pathTemplate = HttpUtility.UrlDecode(oDataRoute.GetRoutePrefix().AppendPathSegment(odataRouteAttribute.PathTemplate));
            Contract.Assume(pathTemplate != null);
            return new ODataActionDescriptor(actionDescriptor, oDataRoute, pathTemplate, CreateHttpRequestMessage(actionDescriptor, oDataRoute, httpConfig));
        }
开发者ID:bigred8982,项目名称:Swashbuckle.OData,代码行数:12,代码来源:AttributeRouteStrategy.cs

示例12: GetFilters

        public IEnumerable<FilterInfo> GetFilters(HttpConfiguration configuration, HttpActionDescriptor actionDescriptor)
        {
            if (actionDescriptor == null ||
              actionDescriptor.GetCustomAttributes<QueryableAttribute>().Any() || // if method already has a QueryableAttribute (or subclass) then skip it.
              actionDescriptor.GetParameters().Any(parameter => typeof(ODataQueryOptions).IsAssignableFrom(parameter.ParameterType))
            )
            {
                return Enumerable.Empty<FilterInfo>();
            }

            return new[] { new FilterInfo(_filter, FilterScope.Global) };
        }
开发者ID:Ross-cz,项目名称:breeze.server.net,代码行数:12,代码来源:BreezeNHControllerAttribute.cs

示例13: GetActionRouteFactories

 protected override IReadOnlyList<IDirectRouteFactory> GetActionRouteFactories(HttpActionDescriptor actionDescriptor)
 {
     var fromBase = base.GetActionRouteFactories(actionDescriptor);
     System.Collections.ObjectModel.Collection<IDirectRouteFactory> newFactories = actionDescriptor.GetCustomAttributes<IDirectRouteFactory>(inherit: true);
     var combined = new List<IDirectRouteFactory>();
     if(fromBase != null)
     {
         combined.AddRange(fromBase);
     }
     if(newFactories != null)
     {
         combined.AddRange(newFactories);
     }
     return fromBase == null ? combined : fromBase;
 }
开发者ID:mchound,项目名称:falyze,代码行数:15,代码来源:WebApiConfig.cs

示例14: DescriptionAuthorized

        private bool DescriptionAuthorized(HttpActionContext actionContext, HttpActionDescriptor actionDescriptor) 
        {
     
            var attributes = actionDescriptor.GetCustomAttributes<Attribute>()
                 .ToArray();

            IEnumerable<ISwaggerAuthorization> swaggerAuthorization =
                attributes == null ? new List<ISwaggerAuthorization>() :
                                    attributes.Where(c => c as ISwaggerAuthorization != null).Cast<ISwaggerAuthorization>().ToList();

            foreach (var auth in swaggerAuthorization) {
                if (!auth.IsDescriptionAuthorized(actionContext)) {
                    return false;
                }
            }
            return true;
        }
开发者ID:Jaryli,项目名称:Swagger.Net,代码行数:17,代码来源:SwaggerActionFilter.cs

示例15: CreateBetaAction

        private HttpActionDescriptor CreateBetaAction(HttpActionDescriptor originalAction)
        {
            var attributes = originalAction.GetCustomAttributes<HasBetaTestingActionAttribute>().OfType<HasBetaTestingActionAttribute>();
            if (!attributes.Any())
            {
                return null;
            }

            var methodName = attributes.First().MethodName;
            var actionMethod = originalAction.ControllerDescriptor.ControllerType.GetMethod(methodName, BindingFlags.Instance | BindingFlags.NonPublic);
            if (actionMethod == null)
            {
                return null;
            }
           
            var actionDescriptor = new ReflectedHttpActionDescriptor(originalAction.ControllerDescriptor, actionMethod);
            actionDescriptor.Properties.TryAdd("IsBetaAction", true);
            return actionDescriptor;
        }
开发者ID:andreychizhov,项目名称:microsoft-aspnet-samples,代码行数:19,代码来源:BetaTestingActionSelector.cs


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