本文整理匯總了C#中ActionDescriptor類的典型用法代碼示例。如果您正苦於以下問題:C# ActionDescriptor類的具體用法?C# ActionDescriptor怎麽用?C# ActionDescriptor使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ActionDescriptor類屬於命名空間,在下文中一共展示了ActionDescriptor類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: ActionContext
/// <summary>
/// Creates a new <see cref="ActionContext"/>.
/// </summary>
/// <param name="httpContext">The <see cref="Http.HttpContext"/> for the current request.</param>
/// <param name="routeData">The <see cref="AspNet.Routing.RouteData"/> for the current request.</param>
/// <param name="actionDescriptor">The <see cref="Abstractions.ActionDescriptor"/> for the selected action.</param>
public ActionContext(
HttpContext httpContext,
RouteData routeData,
ActionDescriptor actionDescriptor)
: this(httpContext, routeData, actionDescriptor, new ModelStateDictionary())
{
}
示例2: Accept_RejectsActionMatchWithMissingParameter
public void Accept_RejectsActionMatchWithMissingParameter()
{
// Arrange
var action = new ActionDescriptor();
action.Parameters = new List<ParameterDescriptor>()
{
new ParameterDescriptor()
{
BindingInfo = new BindingInfo()
{
BindingSource = (new FromUriAttribute()).BindingSource,
},
Name = "id",
ParameterType = typeof(int),
},
};
var constraint = new OverloadActionConstraint();
var context = new ActionConstraintContext();
context.Candidates = new List<ActionSelectorCandidate>()
{
new ActionSelectorCandidate(action, new [] { constraint }),
};
context.CurrentCandidate = context.Candidates[0];
context.RouteContext = CreateRouteContext();
// Act & Assert
Assert.False(constraint.Accept(context));
}
示例3: InvokeAction
public IActionResult InvokeAction(Controller controller, ActionDescriptor actionDescriptor)
{
var methodWithIntParameter =
controller.GetType()
.GetMethods()
.FirstOrDefault(
x =>
x.Name.ToLower() == actionDescriptor.ActionName.ToLower() && x.GetParameters().Length == 1
&& x.GetParameters()[0].ParameterType == typeof(string)
&& x.ReturnType == typeof(IActionResult));
if (methodWithIntParameter == null)
{
throw new HttpNotFoundException(
string.Format(
"Expected method with signature IActionResult {0}(string) in class {1}",
actionDescriptor.ActionName,
actionDescriptor.ControllerName));
}
try
{
var actionResult =
(IActionResult)methodWithIntParameter.Invoke(controller, new object[] { actionDescriptor.Parameter });
return actionResult;
}
catch (TargetInvocationException ex)
{
throw ex.InnerException;
}
}
示例4: InvokeAction
public IActionResult InvokeAction(Controller controller, ActionDescriptor actionDescriptor)
{
/*
* Child processes that use such C run-time functions as printf() and fprintf() can behave poorly when redirected.
* The C run-time functions maintain separate IO buffers. When redirected, these buffers might not be flushed immediately after each IO call.
* As a result, the output to the redirection pipe of a printf() call or the input from a getch() call is not flushed immediately and delays, sometimes-infinite delays occur.
* This problem is avoided if the child process flushes the IO buffers after each call to a C run-time IO function.
* Only the child process can flush its C run-time IO buffers. A process can flush its C run-time IO buffers by calling the fflush() function.
*/
var methodWithIntParameter = controller.GetType()
.GetMethods()
.FirstOrDefault(x => x.Name.ToLower() == actionDescriptor.ActionName.ToLower() &&
x.GetParameters().Length == 1 &&
x.GetParameters()[0].ParameterType == typeof(string) &&
x.ReturnType == typeof(IActionResult));
if (methodWithIntParameter == null)
{
throw new HttpNotFoundException(
string.Format(
"Expected method with signature IActionResult {0}(string) in class {1}Controller",
actionDescriptor.ActionName,
actionDescriptor.ControllerName));
}
try
{
var actionResult = (IActionResult)
methodWithIntParameter.Invoke(controller, new object[] { actionDescriptor.Parameter });
return actionResult;
}
catch (TargetInvocationException ex)
{
throw ex.InnerException;
}
}
示例5: InvokingConstructorWithHomeControllerShouldReturnDefaultActionAndParameter
public void InvokingConstructorWithHomeControllerShouldReturnDefaultActionAndParameter()
{
var actionDescriptor = new ActionDescriptor("/Home");
Assert.AreEqual("Index", actionDescriptor.ActionName);
Assert.AreEqual(string.Empty, actionDescriptor.Parameter);
}
示例6: InvokingConstructorWithNormalUriShouldReturnProperlyControllerActionAndParameter
public void InvokingConstructorWithNormalUriShouldReturnProperlyControllerActionAndParameter()
{
var actionDescriptor = new ActionDescriptor("/Api/ResponseMessage/someParam123");
Assert.AreEqual("Api", actionDescriptor.ControllerName);
Assert.AreEqual("ResponseMessage", actionDescriptor.ActionName);
Assert.AreEqual("someParam123", actionDescriptor.Parameter);
}
示例7: GetFilters
protected override FilterInfo GetFilters(ControllerContext controllerContext, ActionDescriptor actionDescriptor)
{
var rubyType = ((RubyController) controllerContext.Controller).RubyType;
var controllerFilters = (Hash) RubyEngine.CallMethod(rubyType, "action_filters");
var info = controllerFilters.ToFilterInfo("controller").MergedWith(actionDescriptor.GetFilters());
return info;
}
示例8: ActionContext
protected ActionContext(ControllerContext context, ActionDescriptor action)
{
Precondition.Require(context, () => Error.ArgumentNull("context"));
Precondition.Require(action, () => Error.ArgumentNull("action"));
_action = action;
_context = context;
}
示例9: GetFilters
public IEnumerable<Filter> GetFilters(ControllerContext context, ActionDescriptor action)
{
Precondition.Require(context, () => Error.ArgumentNull("context"));
Precondition.Require(action, () => Error.ArgumentNull("action"));
if (context.Controller != null)
yield return new Filter(context.Controller, FilterScope.First, Int32.MinValue);
}
示例10: ReflectedParameterDescriptor
public ReflectedParameterDescriptor(ParameterInfo parameter, ActionDescriptor action)
: base()
{
Precondition.Require(parameter, () => Error.ArgumentNull("parameter"));
Precondition.Require(action, () => Error.ArgumentNull("action"));
_parameter = parameter;
_action = action;
_binding = new ReflectedParameterBinding(parameter);
}
示例11: GetActionAttributes
protected override IEnumerable<FilterAttribute> GetActionAttributes(ControllerContext controllerContext, ActionDescriptor actionDescriptor)
{
var attributes = base.GetActionAttributes(controllerContext, actionDescriptor);
foreach (var attribute in attributes)
{
_container.BuildUp(attribute.GetType(), attribute);
}
return attributes;
}
示例12: AuthenticationContext
public AuthenticationContext(ControllerContext controllerContext, ActionDescriptor actionDescriptor)
: base(controllerContext)
{
if (actionDescriptor == null)
{
throw new ArgumentNullException("actionDescriptor");
}
_actionDescriptor = actionDescriptor;
}
示例13: GetControllerAttributes
protected override System.Collections.Generic.IEnumerable<FilterAttribute> GetControllerAttributes(ControllerContext controllerContext, ActionDescriptor actionDescriptor)
{
var attributes = base.GetControllerAttributes(controllerContext, actionDescriptor);
foreach (var attribute in attributes)
{
_container.BuildUp(attribute);
}
return attributes;
}
示例14: OnBeforeAction
public void OnBeforeAction(ActionDescriptor actionDescriptor, HttpContext httpContext, RouteData routeData)
{
string name = this.GetNameFromRouteContext(routeData);
var telemetry = httpContext.RequestServices.GetService<RequestTelemetry>();
if (!string.IsNullOrEmpty(name) && telemetry != null && telemetry is RequestTelemetry)
{
name = httpContext.Request.Method + " " + name;
((RequestTelemetry)telemetry).Name = name;
}
}
示例15: Bind
/// <summary>
/// Executes binding action to context
/// </summary>
/// <param name="action"> </param>
/// <param name="context"> </param>
public void Bind(ActionDescriptor action, IMvcContext context) {
lock (this) {
if (null == _binders) {
Setup(action.ActionType);
}
if (_binders != null) {
foreach (var binder in _binders) {
binder.Bind(action.Action, context);
}
}
}
}