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


C# HttpControllerDescriptor.GetCustomAttributes方法代码示例

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


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

示例1: GetDocumentation

        public string GetDocumentation(HttpControllerDescriptor controllerDescriptor)
        {
            var apiDocumentation = controllerDescriptor.GetCustomAttributes<ApiDocumentationAttribute>().FirstOrDefault();
            if (apiDocumentation != null)
            {
                return apiDocumentation.Description;
            }

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

示例2: GetDocumentation

 public string GetDocumentation(HttpControllerDescriptor controllerDescriptor)
 {
     string doc = "";
     var attr = controllerDescriptor.GetCustomAttributes<ApiControllerDocAttribute>().FirstOrDefault();
     if (attr != null)
     {
         doc = attr.Documentation;
     }
     return doc;
 }
开发者ID:HK-Zhang,项目名称:Grains,代码行数:10,代码来源:DocProvider.cs

示例3: ShouldExploreController

        /// <summary>
        /// Determines whether the controller should be considered for <see cref="ApiExplorer.ApiDescriptions"/> generation. Called when initializing the <see cref="ApiExplorer.ApiDescriptions"/>.
        /// </summary>
        /// <param name="controllerVariableValue">The controller variable value from the route.</param>
        /// <param name="controllerDescriptor">The controller descriptor.</param>
        /// <param name="route">The route.</param>
        /// <returns><c>true</c> if the controller should be considered for <see cref="ApiExplorer.ApiDescriptions"/> generation, <c>false</c> otherwise.</returns>
        public virtual bool ShouldExploreController(string controllerVariableValue, HttpControllerDescriptor controllerDescriptor, IHttpRoute route)
        {
            if (controllerDescriptor == null)
            {
                throw Error.ArgumentNull("controllerDescriptor");
            }

            if (route == null)
            {
                throw Error.ArgumentNull("route");
            }

            ApiExplorerSettingsAttribute setting = controllerDescriptor.GetCustomAttributes<ApiExplorerSettingsAttribute>().FirstOrDefault();
            return (setting == null || !setting.IgnoreApi) &&
                MatchRegexConstraint(route, ControllerVariableName, controllerVariableValue);
        }
开发者ID:JokerMisfits,项目名称:linux-packaging-mono,代码行数:23,代码来源:ApiExplorer.cs

示例4: GetRoutePrefix

        private static string GetRoutePrefix(HttpControllerDescriptor controllerDescriptor)
        {
            Collection<RoutePrefixAttribute> routePrefixAttributes = controllerDescriptor.GetCustomAttributes<RoutePrefixAttribute>(inherit: false);
            if (routePrefixAttributes.Count > 0)
            {
                string routePrefix = routePrefixAttributes[0].Prefix;
                if (routePrefix != null)
                {
                    if (routePrefix.EndsWith("/", StringComparison.Ordinal))
                    {
                        throw Error.InvalidOperation(SRResources.AttributeRoutes_InvalidPrefix, routePrefix, controllerDescriptor.ControllerName);
                    }

                    return routePrefix;
                }
            }
            return null;
        }
开发者ID:pingxumeng,项目名称:aspnetwebstack,代码行数:18,代码来源:HttpConfigurationExtensions.cs

示例5: GetDefaultRouteTemplate

        // Return null if no DefaultRouteAttribute on the controller.        
        private static Collection<IHttpRouteInfoProvider> GetDefaultRouteTemplate(HttpControllerDescriptor controllerDescriptor)
        {
            Collection<DefaultRouteAttribute> defaultRouteAttributes = controllerDescriptor.GetCustomAttributes<DefaultRouteAttribute>(inherit: false);
            if ((defaultRouteAttributes == null) || (defaultRouteAttributes.Count == 0))
            {
                return null;
            }

            // Morph a DefaultRouteAttribute into a IHttpRouteInfoProvider
            // Let the other properties have their default values. If the user cared about them, 
            // they'd set the [Route] attribute on the action directly and specify them.
            string routeTemplate = defaultRouteAttributes[0].RouteTemplate;
            return new Collection<IHttpRouteInfoProvider> 
            {
                new RouteAttribute(routeTemplate) 
            };
        }
开发者ID:pingxumeng,项目名称:aspnetwebstack,代码行数:18,代码来源:HttpConfigurationExtensions.cs

示例6: GetODataRoutePrefix

        private static string GetODataRoutePrefix(HttpControllerDescriptor controllerDescriptor)
        {
            Contract.Assert(controllerDescriptor != null);

            string prefix = controllerDescriptor.GetCustomAttributes<ODataRoutePrefixAttribute>(inherit: false)
                .Select(prefixAttribute => prefixAttribute.Prefix)
                .SingleOrDefault();

            if (prefix != null && prefix.StartsWith("/", StringComparison.Ordinal))
            {
                throw Error.InvalidOperation(SRResources.RoutePrefixStartsWithSlash, prefix, controllerDescriptor.ControllerType.FullName);
            }

            if (prefix != null && prefix.EndsWith("/", StringComparison.Ordinal))
            {
                prefix = prefix.TrimEnd('/');
            }

            return prefix;
        }
开发者ID:tlycken,项目名称:aspnetwebstack,代码行数:20,代码来源:AttributeRoutingConvention.cs

示例7: GetControllerRouteFactories

 protected override IReadOnlyList<IDirectRouteFactory> GetControllerRouteFactories(HttpControllerDescriptor controllerDescriptor)
 {
     return controllerDescriptor.GetCustomAttributes<IDirectRouteFactory>(inherit: true);
 }
开发者ID:aliengoo,项目名称:ReactSignalR,代码行数:4,代码来源:CustomDirectRouteProvider.cs

示例8: GetControllerRouteFactories

        /// <summary>
        /// Gets route factories for the given controller descriptor.
        /// </summary>
        /// <param name="controllerDescriptor">The controller descriptor.</param>
        /// <returns>A set of route factories.</returns>
        /// <remarks>
        /// The implementation returns <see cref="IDirectRouteFactory"/> instances based on attributes on the controller.
        /// </remarks>
        protected virtual IReadOnlyList<IDirectRouteFactory> GetControllerRouteFactories(HttpControllerDescriptor controllerDescriptor)
        {
            Collection<IDirectRouteFactory> newFactories = controllerDescriptor.GetCustomAttributes<IDirectRouteFactory>(inherit: false);

            Collection<IHttpRouteInfoProvider> oldProviders = controllerDescriptor.GetCustomAttributes<IHttpRouteInfoProvider>(inherit: false);

            List<IDirectRouteFactory> combined = new List<IDirectRouteFactory>();
            combined.AddRange(newFactories);

            foreach (IHttpRouteInfoProvider oldProvider in oldProviders)
            {
                if (oldProvider is IDirectRouteFactory)
                {
                    continue;
                }

                combined.Add(new RouteInfoDirectRouteFactory(oldProvider));
            }

            return combined;
        }
开发者ID:ahmetgoktas,项目名称:aspnetwebstack,代码行数:29,代码来源:DefaultDirectRouteProvider.cs

示例9: GetRoutePrefix

        /// <summary>
        /// Gets the route prefix from the provided controller.
        /// </summary>
        /// <param name="controllerDescriptor">The controller descriptor.</param>
        /// <returns>The route prefix or null.</returns>
        protected virtual string GetRoutePrefix(HttpControllerDescriptor controllerDescriptor)
        {
            Collection<IRoutePrefix> attributes = controllerDescriptor.GetCustomAttributes<IRoutePrefix>(inherit: false);

            if (attributes == null)
            {
                return null;
            }

            if (attributes.Count > 1)
            {
                string errorMessage = Error.Format(SRResources.RoutePrefix_CannotSupportMultiRoutePrefix, controllerDescriptor.ControllerType.FullName);
                throw new InvalidOperationException(errorMessage);
            }

            if (attributes.Count == 1)
            {
                IRoutePrefix attribute = attributes[0];

                if (attribute != null)
                {
                    string prefix = attribute.Prefix;
                    if (prefix == null)
                    {
                        string errorMessage = Error.Format(
                            SRResources.RoutePrefix_PrefixCannotBeNull,
                            controllerDescriptor.ControllerType.FullName);
                        throw new InvalidOperationException(errorMessage);
                    }

                    if (prefix.EndsWith("/", StringComparison.Ordinal))
                    {
                        throw Error.InvalidOperation(SRResources.AttributeRoutes_InvalidPrefix, prefix,
                            controllerDescriptor.ControllerName);
                    }

                    return prefix;
                }
            }

            return null;
        }
开发者ID:ahmetgoktas,项目名称:aspnetwebstack,代码行数:47,代码来源:DefaultDirectRouteProvider.cs

示例10: GetODataRoutePrefixes

        private static IEnumerable<string> GetODataRoutePrefixes(HttpControllerDescriptor controllerDescriptor)
        {
            Contract.Assert(controllerDescriptor != null);

            var prefixAttributes = controllerDescriptor.GetCustomAttributes<ODataRoutePrefixAttribute>(inherit: false);
            if (prefixAttributes.Count == 0)
            {
                yield return null;
            }
            else
            {
                foreach (ODataRoutePrefixAttribute prefixAttribute in prefixAttributes)
                {
                    string prefix = prefixAttribute.Prefix;

                    if (prefix != null && prefix.StartsWith("/", StringComparison.Ordinal))
                    {
                        throw Error.InvalidOperation(SRResources.RoutePrefixStartsWithSlash, prefix, controllerDescriptor.ControllerType.FullName);
                    }

                    if (prefix != null && prefix.EndsWith("/", StringComparison.Ordinal))
                    {
                        prefix = prefix.TrimEnd('/');
                    }

                    yield return prefix;
                }
            }
        }
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:29,代码来源:AttributeRoutingConvention.cs

示例11: GetDocumentation

 public string GetDocumentation(HttpControllerDescriptor controllerDescriptor)
 {
     var attr = controllerDescriptor.GetCustomAttributes<ApiControlAttribute>().FirstOrDefault();
     return attr != null ? attr.Documentation : "";
 }
开发者ID:ouyh18,项目名称:LtePlatform,代码行数:5,代码来源:DocProvider.cs

示例12: GetCustomAttributesInheritFalse_GetsDeclaredAttributes

        public void GetCustomAttributesInheritFalse_GetsDeclaredAttributes()
        {
            HttpConfiguration config = new HttpConfiguration();
            HttpControllerDescriptor desc = new HttpControllerDescriptor(config, "MyController", typeof(MyDerived1Controller));

            var attributes = desc.GetCustomAttributes<MyConfigDerived1Attribute>(inherit: false);

            Assert.Equal(1, attributes.Count);
        }
开发者ID:huangw-t,项目名称:aspnetwebstack,代码行数:9,代码来源:HttpControllerDescriptorTest.cs

示例13: GetCustomAttributesInheritFalse_DoesNotGetInheritedAttributes

        public void GetCustomAttributesInheritFalse_DoesNotGetInheritedAttributes()
        {
            HttpConfiguration config = new HttpConfiguration();
            HttpControllerDescriptor desc = new HttpControllerDescriptor(config, "MyController", typeof(MyDerived1Controller));

            var attributes = desc.GetCustomAttributes<MyConfigBaseAttribute>(inherit: false);

            Assert.Empty(attributes);
        }
开发者ID:huangw-t,项目名称:aspnetwebstack,代码行数:9,代码来源:HttpControllerDescriptorTest.cs

示例14: CreateRouteEntries

        private static IEnumerable<HttpRouteEntry> CreateRouteEntries(HttpControllerDescriptor controllerDescriptor)
        {
            IHttpActionSelector actionSelector = controllerDescriptor.Configuration.Services.GetActionSelector();
            ILookup<string, HttpActionDescriptor> actionMap = actionSelector.GetActionMapping(controllerDescriptor);
            if (actionMap == null)
            {
                return Enumerable.Empty<HttpRouteEntry>();
            }

            List<HttpRouteEntry> routes = new List<HttpRouteEntry>();
            RoutePrefixAttribute routePrefix = controllerDescriptor.GetCustomAttributes<RoutePrefixAttribute>(inherit: false).SingleOrDefault();

            foreach (IGrouping<string, HttpActionDescriptor> actionGrouping in actionMap)
            {
                string actionName = actionGrouping.Key;

                foreach (ReflectedHttpActionDescriptor actionDescriptor in actionGrouping.OfType<ReflectedHttpActionDescriptor>())
                {
                    IEnumerable<IHttpRouteInfoProvider> routeInfoProviders = actionDescriptor.GetCustomAttributes<IHttpRouteInfoProvider>(inherit: false);

                    foreach (IHttpRouteInfoProvider routeProvider in routeInfoProviders.DefaultIfEmpty())
                    {
                        string routeTemplate = BuildRouteTemplate(routePrefix, routeProvider, controllerDescriptor.ControllerName);
                        if (routeTemplate == null)
                        {
                            continue;
                        }

                        // Try to find an entry with the same route template and the same HTTP verbs
                        HttpRouteEntry existingEntry = null;
                        foreach (HttpRouteEntry entry in routes)
                        {
                            if (String.Equals(routeTemplate, entry.RouteTemplate, StringComparison.OrdinalIgnoreCase) &&
                                    AreEqual(routeProvider.HttpMethods, entry.HttpMethods))
                            {
                                existingEntry = entry;
                                break;
                            }
                        }

                        if (existingEntry == null)
                        {
                            HttpRouteEntry entry = new HttpRouteEntry()
                            {
                                RouteTemplate = routeTemplate,
                                Actions = new HashSet<ReflectedHttpActionDescriptor>() { actionDescriptor }
                            };

                            if (routeProvider != null)
                            {
                                entry.HttpMethods = routeProvider.HttpMethods;
                                entry.Name = routeProvider.RouteName;
                                entry.Order = routeProvider.RouteOrder;
                            }
                            routes.Add(entry);
                        }
                        else
                        {
                            existingEntry.Actions.Add(actionDescriptor);

                            // Take the minimum of the two orders as the order
                            int order = routeProvider == null ? 0 : routeProvider.RouteOrder;
                            if (order < existingEntry.Order)
                            {
                                existingEntry.Order = order;
                            }

                            // Use the provider route name if the route hasn't already been named
                            if (routeProvider != null && existingEntry.Name == null)
                            {
                                existingEntry.Name = routeProvider.RouteName;
                            }
                        }
                    }
                }
            }

            return routes;
        }
开发者ID:karensyc,项目名称:aspnetwebstack,代码行数:79,代码来源:HttpConfigurationExtensions.cs

示例15: HasIgnoreAttribute

		public static bool HasIgnoreAttribute(HttpControllerDescriptor controllerDescriptor)
		{
			return controllerDescriptor.GetCustomAttributes<SwaggerIgnoreAttribute>().Count > 0;
		}
开发者ID:giacomelli,项目名称:DG-Swagger.Net,代码行数:4,代码来源:CustomAttributeHelper.cs


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