当前位置: 首页>>代码示例>>C#>>正文


C# ReflectedHttpActionDescriptor.GetParameters方法代码示例

本文整理汇总了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);
            }
        }
开发者ID:chenboyi081,项目名称:asp-net-web-api-2-samples,代码行数:28,代码来源:ContactsController.cs

示例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);
            }
        }
开发者ID:chenboyi081,项目名称:asp-net-web-api-2-samples,代码行数:12,代码来源:Program.cs

示例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());
        }
开发者ID:reza899,项目名称:aspnetwebstack,代码行数:11,代码来源:ReflectedHttpActionDescriptorTest.cs


注:本文中的ReflectedHttpActionDescriptor.GetParameters方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。