本文整理汇总了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;
}
示例2: GetDocumentation
public string GetDocumentation(HttpControllerDescriptor controllerDescriptor)
{
string doc = "";
var attr = controllerDescriptor.GetCustomAttributes<ApiControllerDocAttribute>().FirstOrDefault();
if (attr != null)
{
doc = attr.Documentation;
}
return doc;
}
示例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);
}
示例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;
}
示例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)
};
}
示例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;
}
示例7: GetControllerRouteFactories
protected override IReadOnlyList<IDirectRouteFactory> GetControllerRouteFactories(HttpControllerDescriptor controllerDescriptor)
{
return controllerDescriptor.GetCustomAttributes<IDirectRouteFactory>(inherit: true);
}
示例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;
}
示例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;
}
示例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;
}
}
}
示例11: GetDocumentation
public string GetDocumentation(HttpControllerDescriptor controllerDescriptor)
{
var attr = controllerDescriptor.GetCustomAttributes<ApiControlAttribute>().FirstOrDefault();
return attr != null ? attr.Documentation : "";
}
示例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);
}
示例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);
}
示例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;
}
示例15: HasIgnoreAttribute
public static bool HasIgnoreAttribute(HttpControllerDescriptor controllerDescriptor)
{
return controllerDescriptor.GetCustomAttributes<SwaggerIgnoreAttribute>().Count > 0;
}