本文整理汇总了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;
}
示例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
}
示例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);
}
示例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;
}
示例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);
}
示例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)};
}
示例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);
}
示例9: GetResponseDocumentation
public string GetResponseDocumentation(HttpActionDescriptor actionDescriptor)
{
var apiDocumentation = actionDescriptor.GetCustomAttributes<ApiResponseDocumentationAttribute>().FirstOrDefault();
if (apiDocumentation != null)
{
return apiDocumentation.Description;
}
return String.Empty;
}
示例10: GetDocumentation
public string GetDocumentation(HttpActionDescriptor actionDescriptor)
{
string doc = "";
var attr = actionDescriptor.GetCustomAttributes<ApiDocAttribute>().FirstOrDefault();
if (attr != null)
{
doc = attr.Documentation;
}
return doc;
}
示例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));
}
示例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) };
}
示例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;
}
示例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;
}
示例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;
}