本文整理汇总了C#中ReflectedHttpActionDescriptor.GetParameters方法的典型用法代码示例。如果您正苦于以下问题:C# ReflectedHttpActionDescriptor.GetParameters方法的具体用法?C# ReflectedHttpActionDescriptor.GetParameters怎么用?C# ReflectedHttpActionDescriptor.GetParameters使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ReflectedHttpActionDescriptor
的用法示例。
在下文中一共展示了ReflectedHttpActionDescriptor.GetParameters方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Bind
private void Bind(string methodName)
{
//创建FormatterParameterBinding对象
MethodInfo method = typeof(ContactsController).GetMethod(methodName);
HttpActionDescriptor actionDescriptor = new ReflectedHttpActionDescriptor(this.ControllerContext.ControllerDescriptor, method);
HttpParameterDescriptor parameterDescriptor = actionDescriptor.GetParameters().First();
MediaTypeFormatter[] formatters = new MediaTypeFormatter[] { new JsonMediaTypeFormatter() };
FormatterParameterBinding parameterBinding = new FormatterParameterBinding(parameterDescriptor, formatters, null);
//创建HttpActionBinding并执行
HttpActionBinding actionBinding = new HttpActionBinding(actionDescriptor,new FormatterParameterBinding[] { parameterBinding });
HttpActionContext actionContext =new HttpActionContext(this.ControllerContext, actionDescriptor);
try
{
actionBinding.ExecuteBindingAsync(actionContext, CancellationToken.None).Wait();
//获取绑定参数对象并打印相关数据
Contact contact = (Contact)actionContext.ActionArguments["contact"];
Console.WriteLine("{0,-12}: {1}", "Name", contact.Name);
Console.WriteLine("{0,-12}: {1}", "Phone No.", contact.PhoneNo);
Console.WriteLine("{0,-12}: {1}", "EmailAddress", contact.EmailAddress);
Console.WriteLine("{0,-12}: {1}", "Address", contact.Address);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
示例2: Main
static void Main(string[] args)
{
HttpControllerDescriptor controllerDescriptor = new HttpControllerDescriptor(new HttpConfiguration(), "demo", typeof(DemoController));
MethodInfo methodInfo = typeof(DemoController).GetMethod("Get");
ReflectedHttpActionDescriptor actionDescriptor = new ReflectedHttpActionDescriptor(controllerDescriptor, methodInfo);
Console.WriteLine("{0,-16}{1,-16}{2,-16}{3,-10}", "ParameterName", "ParameterType", "DefaultValue", "IsOptional");
foreach (ReflectedHttpParameterDescriptor parameter in actionDescriptor.GetParameters())
{
Console.WriteLine("{0,-16}{1,-16}{2,-16}{3,-10}", parameter.ParameterName, parameter.ParameterType.Name, parameter.DefaultValue ?? "N/A", parameter.IsOptional);
}
}
示例3: GetParameters_Returns_ActionParameters
public void GetParameters_Returns_ActionParameters()
{
Func<string, string, User> echoUserMethod = _controller.EchoUser;
ReflectedHttpActionDescriptor actionDescriptor = new ReflectedHttpActionDescriptor { MethodInfo = echoUserMethod.Method };
Collection<HttpParameterDescriptor> parameterDescriptors = actionDescriptor.GetParameters();
Assert.Equal(2, parameterDescriptors.Count);
Assert.NotNull(parameterDescriptors.Where(p => p.ParameterName == "firstName").FirstOrDefault());
Assert.NotNull(parameterDescriptors.Where(p => p.ParameterName == "lastName").FirstOrDefault());
}