本文整理汇总了C#中System.Web.Mvc.ActionDescriptor类的典型用法代码示例。如果您正苦于以下问题:C# ActionDescriptor类的具体用法?C# ActionDescriptor怎么用?C# ActionDescriptor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ActionDescriptor类属于System.Web.Mvc命名空间,在下文中一共展示了ActionDescriptor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InvokeActionMethod
protected override ActionResult InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary<string, object> parameters)
{
var uowParam = actionDescriptor.GetParameters().FirstOrDefault(x => x.ParameterType == typeof(IUnitOfWork));
if (uowParam != null)
{
var connectionKey = controllerContext.Controller.GetType().GetCustomAttribute<ConnectionKeyAttribute>();
if (connectionKey == null)
throw new ArgumentNullException("connectionKey");
using (var connection = SqlConnections.NewByKey(connectionKey.Value))
using (var uow = new UnitOfWork(connection))
{
parameters[uowParam.ParameterName] = uow;
var result = base.InvokeActionMethod(controllerContext, actionDescriptor, parameters);
uow.Commit();
return result;
}
}
var cnnParam = actionDescriptor.GetParameters().FirstOrDefault(x => x.ParameterType == typeof(IDbConnection));
if (cnnParam != null)
{
var connectionKey = controllerContext.Controller.GetType().GetCustomAttribute<ConnectionKeyAttribute>();
if (connectionKey == null)
throw new ArgumentNullException("connectionKey");
using (var cnn = SqlConnections.NewByKey(connectionKey.Value))
{
parameters[cnnParam.ParameterName] = cnn;
return base.InvokeActionMethod(controllerContext, actionDescriptor, parameters);
}
}
return base.InvokeActionMethod(controllerContext, actionDescriptor, parameters);
}
示例2: GetParameters
public static ParameterDescriptor[] GetParameters(ActionDescriptor actionDescriptor, MethodInfo methodInfo, ref ParameterDescriptor[] parametersCache)
{
ParameterDescriptor[] parameters = LazilyFetchParametersCollection(actionDescriptor, methodInfo, ref parametersCache);
// need to clone array so that user modifications aren't accidentally stored
return (ParameterDescriptor[])parameters.Clone();
}
示例3: GetFilters
public IEnumerable<Filter> GetFilters(ControllerContext controllerContext, ActionDescriptor actionDescriptor)
{
return filterRegistry.Items.Where(item => item.IsMatching(controllerContext, actionDescriptor))
.SelectMany(item => item.BuildFilters())
.OrderBy(x => x.Order)
.ToArray();
}
示例4: CreateRouteEntry_IfDirectRouteProviderReturnsRouteWithEmptyActionDescriptors_Throws
public void CreateRouteEntry_IfDirectRouteProviderReturnsRouteWithEmptyActionDescriptors_Throws()
{
// Arrange
string areaPrefix = null;
string controllerPrefix = null;
Route route = new Route(url: null, routeHandler: null);
route.DataTokens = new RouteValueDictionary();
route.DataTokens.Add(RouteDataTokenKeys.Actions, new ActionDescriptor[0]);
ActionDescriptor[] originalActions = route.GetTargetActionDescriptors();
Assert.NotNull(originalActions); // Guard
Assert.Equal(0, originalActions.Length); // Guard
RouteEntry entry = new RouteEntry(name: null, route: route);
IDirectRouteFactory factory = CreateStubRouteFactory(entry);
ControllerDescriptor controllerDescriptor = CreateStubControllerDescriptor("IgnoreController");
ActionDescriptor actionDescriptor = CreateStubActionDescriptor(controllerDescriptor, "IgnoreAction");
IReadOnlyCollection<ActionDescriptor> actions = new ActionDescriptor[] { actionDescriptor };
IInlineConstraintResolver constraintResolver =
new Mock<IInlineConstraintResolver>(MockBehavior.Strict).Object;
// Act & Assert
string expectedMessage = "The route does not have any associated action descriptors. Routing requires " +
"that each direct route map to a non-empty set of actions.";
Assert.Throws<InvalidOperationException>(() => DefaultDirectRouteProvider.CreateRouteEntry(areaPrefix,
controllerPrefix, factory, actions, constraintResolver, targetIsAction: false), expectedMessage);
}
示例5: LazilyFetchParametersCollection
private static ParameterDescriptor[] LazilyFetchParametersCollection(ActionDescriptor actionDescriptor, MethodInfo methodInfo, ref ParameterDescriptor[] parametersCache)
{
return DescriptorUtil.LazilyFetchOrCreateDescriptors<ParameterInfo, ParameterDescriptor>(
cacheLocation: ref parametersCache,
initializer: methodInfo.GetParameters,
converter: parameterInfo => new ReflectedParameterDescriptor(parameterInfo, actionDescriptor));
}
示例6: GetFilters
protected override FilterInfo GetFilters(ControllerContext controllerContext, ActionDescriptor actionDescriptor)
{
var filterList = base.GetFilters(controllerContext, actionDescriptor);
filterList.ResultFilters.Add(new ViewProviderFilter(actionDescriptor.ActionName));
return filterList;
}
示例7: ExecutedAttributesOf
private static IEnumerable<FilterAttribute> ExecutedAttributesOf(ActionDescriptor actionDescriptor)
{
var actionCustomAttributes = actionDescriptor.GetCustomAttributes(inherit: true).OfType<FilterAttribute>().OrderByDescending(attribute => attribute.Order);
var controllerCustomAttributes = actionDescriptor.ControllerDescriptor.GetCustomAttributes(inherit: true).OfType<FilterAttribute>().OrderByDescending(attribute => attribute.Order);
return actionCustomAttributes.Concat(controllerCustomAttributes);
}
示例8:
CachePolicy IMvcCachePolicyProvider.CreateCachePolicy( ControllerContext context, ActionDescriptor action, IDictionary<string, object> parameters )
{
if ( context.IsChildAction )
return null;
return _provider.CreateCachePolicy( context.HttpContext );
}
示例9: Get
public ControllerAction Get(ActionDescriptor actionDescriptor)
{
string httpVerb = actionDescriptor.GetHttpVerb();
return DB.ControllerActions.SingleOrDefault(r => r.Controller == actionDescriptor.ControllerDescriptor.ControllerName
&& r.Action == actionDescriptor.ActionName
&& r.HttpVerb == httpVerb);
}
示例10: GetParamSignatureString
private string GetParamSignatureString(ActionDescriptor action)
{
var res = "(";
ReflectedActionDescriptor aD = action as ReflectedActionDescriptor;
foreach (var parameterDescriptor in aD.GetParameters())
{
res += parameterDescriptor.ParameterType.Name + " " + parameterDescriptor.ParameterName + ", ";
}
if (res == "(")
{
res += ")";
return res;
}
if (res.Substring(res.Length - 2) == ", ")
{
res = res.Substring(0, res.Length - 2);
res += ")";
}
return res;
}
示例11: GetFilters
/// <summary>
/// Gets the filters for the specified request and action.
/// </summary>
/// <param name="controllerContext">The controller context.</param>
/// <param name="actionDescriptor">The action descriptor.</param>
/// <returns>The filters.</returns>
protected override FilterInfo GetFilters(ControllerContext controllerContext, ActionDescriptor actionDescriptor)
{
FilterInfo filterInfo = base.GetFilters(controllerContext, actionDescriptor);
foreach (IActionFilter filter in filterInfo.ActionFilters.Where(f => f != null))
{
this.Kernel.Inject(filter);
}
foreach (IAuthorizationFilter filter in filterInfo.AuthorizationFilters.Where(f => f != null))
{
this.Kernel.Inject(filter);
}
foreach (IExceptionFilter filter in filterInfo.ExceptionFilters.Where(f => f != null))
{
this.Kernel.Inject(filter);
}
foreach (IResultFilter filter in filterInfo.ResultFilters.Where(f => f != null))
{
this.Kernel.Inject(filter);
}
return filterInfo;
}
示例12: GetFilters
public IEnumerable<Filter> GetFilters(ControllerContext controllerContext,
ActionDescriptor actionDescriptor)
{
if ((actionDescriptor.ControllerDescriptor.ControllerType ==
typeof(ProductController) &&
(actionDescriptor.ActionName.Equals("Create",
StringComparison.InvariantCultureIgnoreCase) ||
actionDescriptor.ActionName.Equals("Edit",
StringComparison.InvariantCultureIgnoreCase)) &&
controllerContext.HttpContext.Request.HttpMethod == "POST") ||
(actionDescriptor.ControllerDescriptor.ControllerType ==
typeof(ProductVariantController) &&
(actionDescriptor.ActionName.Equals("Create",
StringComparison.InvariantCultureIgnoreCase) ||
actionDescriptor.ActionName.Equals("Edit",
StringComparison.InvariantCultureIgnoreCase)) &&
controllerContext.HttpContext.Request.HttpMethod == "POST"))
{
return new Filter[]
{
new Filter(_actionFilter, FilterScope.Action, null)
};
};
return new Filter[] { };
}
示例13: GetFilters
public IEnumerable<Filter> GetFilters(ControllerContext controllerContext, ActionDescriptor actionDescriptor)
{
#if !DEBUG
yield return new Filter(new RedirectToHttpsAttribute(), FilterScope.Global, App.HttpsRedirectOrder);
#endif
yield return new Filter(new RequiresAllRoles("staff"), FilterScope.Global, App.ActiveAuthenticationOrder);
}
示例14: CreateActionResult
protected override ActionResult CreateActionResult(ControllerContext controllerContext, ActionDescriptor actionDescriptor, object actionReturnValue)
{
if(!(actionReturnValue is ActionResult))
{
var controller = controllerContext.Controller;
if(actionReturnValue is Result)
{
if(actionReturnValue == Result.Successfully)
{
actionReturnValue = controller.Success();
}
else
{
var result = actionReturnValue as IValueResult;
if(result.IsSucceed)
{
actionReturnValue = controller.Success(result.GetValue());
}
else actionReturnValue = controller.Faild(result.Message, result.Status);
}
}
else
{
actionReturnValue = controller.Success(actionReturnValue);
}
}
return base.CreateActionResult(controllerContext, actionDescriptor, actionReturnValue);
}
示例15: GetFilters
/// <summary>
/// Retrieves information about the action filters.
/// </summary>
/// <param name="controllerContext">The controller context.</param>
/// <param name="actionDescriptor">The action descriptor.</param>
/// <returns>Information about the action filters.</returns>
protected override FilterInfo GetFilters(ControllerContext controllerContext, ActionDescriptor actionDescriptor)
{
//let the base class do the actual work as usual
var filterInfo = base.GetFilters(controllerContext, actionDescriptor);
//configure each collection of filters using the IApplicationContext
foreach (IActionFilter filter in filterInfo.ActionFilters.Where(f => f != null))
{
_context.ConfigureObject(filter, filter.GetType().FullName);
}
foreach (IAuthorizationFilter filter in filterInfo.AuthorizationFilters.Where(f => f != null))
{
_context.ConfigureObject(filter, filter.GetType().FullName);
}
foreach (IExceptionFilter filter in filterInfo.ExceptionFilters.Where(f => f != null))
{
_context.ConfigureObject(filter, filter.GetType().FullName);
}
foreach (IResultFilter filter in filterInfo.ResultFilters.Where(f => f != null))
{
_context.ConfigureObject(filter, filter.GetType().FullName);
}
return filterInfo;
}