• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# ReflectedHttpActionDescriptor类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中ReflectedHttpActionDescriptor的典型用法代码示例。如果您正苦于以下问题:C# ReflectedHttpActionDescriptor类的具体用法?C# ReflectedHttpActionDescriptor怎么用?C# ReflectedHttpActionDescriptor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ReflectedHttpActionDescriptor类属于命名空间,在下文中一共展示了ReflectedHttpActionDescriptor类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: WrapperResolvesAuthenticationFilterFromDependencyScope

        public void WrapperResolvesAuthenticationFilterFromDependencyScope()
        {
            var builder = new ContainerBuilder();
            builder.Register<ILogger>(c => new Logger()).InstancePerDependency();
            var activationCount = 0;
            builder.Register<IAutofacAuthenticationFilter>(c => new TestAuthenticationFilter(c.Resolve<ILogger>()))
                .AsWebApiAuthenticationFilterFor<TestController>(c => c.Get())
                .InstancePerRequest()
                .OnActivated(e => activationCount++);
            var container = builder.Build();

            var resolver = new AutofacWebApiDependencyResolver(container);
            var configuration = new HttpConfiguration { DependencyResolver = resolver };
            var requestMessage = new HttpRequestMessage();
            requestMessage.Properties.Add(HttpPropertyKeys.HttpConfigurationKey, configuration);
            var contollerContext = new HttpControllerContext { Request = requestMessage };
            var controllerDescriptor = new HttpControllerDescriptor { ControllerType = typeof(TestController) };
            var methodInfo = typeof(TestController).GetMethod("Get");
            var actionDescriptor = new ReflectedHttpActionDescriptor(controllerDescriptor, methodInfo);
            var actionContext = new HttpActionContext(contollerContext, actionDescriptor);
            var context = new HttpAuthenticationContext(actionContext, Thread.CurrentPrincipal);
            var metadata = new FilterMetadata
            {
                ControllerType = typeof(TestController),
                FilterScope = FilterScope.Action,
                MethodInfo = methodInfo
            };
            var wrapper = new AuthenticationFilterWrapper(metadata);

            wrapper.OnAuthenticate(context);
            Assert.That(activationCount, Is.EqualTo(1));
        }
开发者ID:RoymanJing,项目名称:Autofac,代码行数:32,代码来源:AuthenticationFilterWrapperFixture.cs


示例3: Ctor_SetsActionsDataToken

        public void Ctor_SetsActionsDataToken()
        {
            var actions = new ReflectedHttpActionDescriptor[0];

            var route = new HttpDirectRoute("route", 0, actions);

            Assert.Equal(actions, route.Actions);
        }
开发者ID:khorchani,项目名称:aspnetwebstack,代码行数:8,代码来源:HttpDirectRouteTest.cs


示例4: IsDefined_Retruns_True_WhenParameterAttributeIsFound

 public void IsDefined_Retruns_True_WhenParameterAttributeIsFound()
 {
     UsersRpcController controller = new UsersRpcController();
     Action<User> addUserMethod = controller.AddUser;
     ReflectedHttpActionDescriptor actionDescriptor = new ReflectedHttpActionDescriptor { MethodInfo = addUserMethod.Method };
     ParameterInfo parameterInfo = addUserMethod.Method.GetParameters()[0];
     ReflectedHttpParameterDescriptor parameterDescriptor = new ReflectedHttpParameterDescriptor(actionDescriptor, parameterInfo);
 }
开发者ID:JokerMisfits,项目名称:linux-packaging-mono,代码行数:8,代码来源:ReflectedHttpParameterDescriptorTest.cs


示例5: ParameterBinderAttribute_NotNull_WhenParameterAttributeIsFound

 public void ParameterBinderAttribute_NotNull_WhenParameterAttributeIsFound()
 {
     UsersRpcController controller = new UsersRpcController();
     Action<User> addUserMethod = controller.AddUser;
     ReflectedHttpActionDescriptor actionDescriptor = new ReflectedHttpActionDescriptor { MethodInfo = addUserMethod.Method };
     ParameterInfo parameterInfo = addUserMethod.Method.GetParameters()[0];
     ReflectedHttpParameterDescriptor parameterDescriptor = new ReflectedHttpParameterDescriptor(actionDescriptor, parameterInfo);
     Assert.NotNull(parameterDescriptor.ParameterBinderAttribute);
 }
开发者ID:reza899,项目名称:aspnetwebstack,代码行数:9,代码来源:ReflectedHttpParameterDescriptorTest.cs


示例6: Ctor_SetsActionsDataToken

        public void Ctor_SetsActionsDataToken()
        {
            var actions = new ReflectedHttpActionDescriptor[0];

            var route = HttpRouteBuilder.BuildDirectRoute("route", 0, actions);

            var actualActions = route.DataTokens[RouteKeys.ActionsDataTokenKey];
            Assert.Equal(actions, actualActions);
        }
开发者ID:normalian,项目名称:aspnetwebstack,代码行数:9,代码来源:HttpDirectRouteTest.cs


示例7: IsOptional_Returns_True_ForOptionalParameter

 public void IsOptional_Returns_True_ForOptionalParameter()
 {
     UsersRpcController controller = new UsersRpcController();
     MethodInfo methodWithOptionalParam = GetType().GetMethod("MethodWithOptionalParam", BindingFlags.Static | BindingFlags.NonPublic);
     ReflectedHttpActionDescriptor actionDescriptor = new ReflectedHttpActionDescriptor { MethodInfo = methodWithOptionalParam };
     ParameterInfo parameterInfo = methodWithOptionalParam.GetParameters()[0];
     ReflectedHttpParameterDescriptor parameterDescriptor = new ReflectedHttpParameterDescriptor(actionDescriptor, parameterInfo);
     Assert.True(parameterDescriptor.IsOptional);
 }
开发者ID:reza899,项目名称:aspnetwebstack,代码行数:9,代码来源:ReflectedHttpParameterDescriptorTest.cs


示例8: CreateBuilderWithoutResolverAndBuild_AddsDefaultValuesAsOptional

        public void CreateBuilderWithoutResolverAndBuild_AddsDefaultValuesAsOptional()
        {
            var actions = new ReflectedHttpActionDescriptor[] { new ReflectedHttpActionDescriptor() };
            var route = BuildWithoutResolver("movies/{id}", actions);
            route.Defaults.Add("id", RouteParameter.Optional);

            var routeData = route.GetRouteData("", new HttpRequestMessage(HttpMethod.Get, "http://localhost/movies"));

            Assert.Equal(RouteParameter.Optional, routeData.Values["id"]);
        }
开发者ID:KevMoore,项目名称:aspnetwebstack,代码行数:10,代码来源:DirectRouteProviderContextTests.cs


示例9: GetFilters_ReturnsEmptyCollection_ForNonQueryableActions

        public void GetFilters_ReturnsEmptyCollection_ForNonQueryableActions(string actionName)
        {
            HttpConfiguration config = new HttpConfiguration();
            HttpControllerDescriptor controllerDescriptor = new HttpControllerDescriptor(config, "FilterProviderTest", typeof(FilterProviderTestController));
            HttpActionDescriptor actionDescriptor = new ReflectedHttpActionDescriptor(controllerDescriptor, typeof(FilterProviderTestController).GetMethod(actionName));

            FilterInfo[] filters = new QueryFilterProvider(new EnableQueryAttribute()).GetFilters(config, actionDescriptor).ToArray();

            Assert.Empty(filters);
        }
开发者ID:huangw-t,项目名称:aspnetwebstack,代码行数:10,代码来源:QueryableFilterProviderTest.cs


示例10: GetRouteData_AddsDefaultValuesAsNull

        public void GetRouteData_AddsDefaultValuesAsNull()
        {
            var actions = new ReflectedHttpActionDescriptor[] { new ReflectedHttpActionDescriptor() };
            var route = new HttpDirectRoute("movies/{id}", 0, actions);
            route.Defaults.Add("id", RouteParameter.Optional);

            var routeData = route.GetRouteData("", new HttpRequestMessage(HttpMethod.Get, "http://localhost/movies"));

            Assert.Null(routeData.Values["id"]);
        }
开发者ID:khorchani,项目名称:aspnetwebstack,代码行数:10,代码来源:HttpDirectRouteTest.cs


示例11: GetCustomAttributes_AttributeType_Returns_ParameterAttributes

        public void GetCustomAttributes_AttributeType_Returns_ParameterAttributes()
        {
            UsersRpcController controller = new UsersRpcController();
            Action<User> addUserMethod = controller.AddUser;
            ReflectedHttpActionDescriptor actionDescriptor = new ReflectedHttpActionDescriptor { MethodInfo = addUserMethod.Method };
            ParameterInfo parameterInfo = addUserMethod.Method.GetParameters()[0];
            ReflectedHttpParameterDescriptor parameterDescriptor = new ReflectedHttpParameterDescriptor(actionDescriptor, parameterInfo);
            IEnumerable<FromBodyAttribute> attributes = parameterDescriptor.GetCustomAttributes<FromBodyAttribute>();

            Assert.Equal(1, attributes.Count());
        }
开发者ID:JokerMisfits,项目名称:linux-packaging-mono,代码行数:11,代码来源:ReflectedHttpParameterDescriptorTest.cs


示例12: Default_Constructor

        public void Default_Constructor()
        {
            ReflectedHttpActionDescriptor actionDescriptor = new ReflectedHttpActionDescriptor();

            Assert.Null(actionDescriptor.ActionName);
            Assert.Null(actionDescriptor.Configuration);
            Assert.Null(actionDescriptor.ControllerDescriptor);
            Assert.Null(actionDescriptor.MethodInfo);
            Assert.Null(actionDescriptor.ReturnType);
            Assert.NotNull(actionDescriptor.Properties);
        }
开发者ID:reza899,项目名称:aspnetwebstack,代码行数:11,代码来源:ReflectedHttpActionDescriptorTest.cs


示例13: GetCustomAttributes_Returns_ParameterAttributes

        public void GetCustomAttributes_Returns_ParameterAttributes()
        {
            UsersRpcController controller = new UsersRpcController();
            Action<User> addUserMethod = controller.AddUser;
            ReflectedHttpActionDescriptor actionDescriptor = new ReflectedHttpActionDescriptor { MethodInfo = addUserMethod.Method };
            ParameterInfo parameterInfo = addUserMethod.Method.GetParameters()[0];
            ReflectedHttpParameterDescriptor parameterDescriptor = new ReflectedHttpParameterDescriptor(actionDescriptor, parameterInfo);
            object[] attributes = parameterDescriptor.GetCustomAttributes<object>().ToArray();

            Assert.Equal(1, attributes.Length);
            Assert.Equal(typeof(FromBodyAttribute), attributes[0].GetType());
        }
开发者ID:reza899,项目名称:aspnetwebstack,代码行数:12,代码来源:ReflectedHttpParameterDescriptorTest.cs


示例14: LogExit_should_log_with_exit_text

        public void LogExit_should_log_with_exit_text()
        {
            var helper = new ActionLogHelperTestDouble(_loggerMock.Object);

            var controllerDescriptor = new HttpControllerDescriptor { ControllerType = typeof(ActionLogHelper) };
            var actionDescriptor = new ReflectedHttpActionDescriptor { ControllerDescriptor = controllerDescriptor };

            helper.LogExit(actionDescriptor);

            Assert.AreEqual(actionDescriptor, helper.ActionDescriptorGiven);
            Assert.AreEqual(ActionLogHelper.ExitingText, helper.PrefixGiven);
        }
开发者ID:isalo,项目名称:Mvc4ServicesBook,代码行数:12,代码来源:ActionLogHelperTests.cs


示例15: ControllerDescriptor_Property

        public void ControllerDescriptor_Property()
        {
            ReflectedHttpActionDescriptor actionDescriptor = new ReflectedHttpActionDescriptor();
            HttpControllerDescriptor controllerDescriptor = new HttpControllerDescriptor();

            Assert.Reflection.Property<ReflectedHttpActionDescriptor, HttpControllerDescriptor>(
                 instance: actionDescriptor,
                 propertyGetter: ad => ad.ControllerDescriptor,
                 expectedDefaultValue: null,
                 allowNull: false,
                 roundTripTestValue: controllerDescriptor);
        }
开发者ID:KevMoore,项目名称:aspnetwebstack,代码行数:12,代码来源:ReflectedHttpActionDescriptorTest.cs


示例16: 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


示例17: GetFilters_ReturnsQueryableFilter_ForQueryableActions

        public void GetFilters_ReturnsQueryableFilter_ForQueryableActions(string actionName)
        {
            HttpConfiguration config = new HttpConfiguration();
            HttpControllerDescriptor controllerDescriptor = new HttpControllerDescriptor(config, "FilterProviderTest", typeof(FilterProviderTestController));
            HttpActionDescriptor actionDescriptor = new ReflectedHttpActionDescriptor(controllerDescriptor, typeof(FilterProviderTestController).GetMethod(actionName));

            FilterInfo[] filters = new QueryFilterProvider(new EnableQueryAttribute()).GetFilters(config, actionDescriptor).ToArray();

            Assert.Equal(1, filters.Length);
            Assert.Equal(FilterScope.Global, filters[0].Scope);
            EnableQueryAttribute filter = Assert.IsType<EnableQueryAttribute>(filters[0].Instance);
        }
开发者ID:huangw-t,项目名称:aspnetwebstack,代码行数:12,代码来源:QueryableFilterProviderTest.cs


示例18: MethodInfo_Property

        public void MethodInfo_Property()
        {
            ReflectedHttpActionDescriptor actionDescriptor = new ReflectedHttpActionDescriptor();
            Action action = new Action(() => { });

            Assert.Reflection.Property<ReflectedHttpActionDescriptor, MethodInfo>(
                 instance: actionDescriptor,
                 propertyGetter: ad => ad.MethodInfo,
                 expectedDefaultValue: null,
                 allowNull: false,
                 roundTripTestValue: action.Method);
        }
开发者ID:reza899,项目名称:aspnetwebstack,代码行数:12,代码来源:ReflectedHttpActionDescriptorTest.cs


示例19: Main

 static void Main(string[] args)
 {
     Console.WriteLine("{0,-12}{1,-10}", "ActionName", "HttpMethod");
     HttpControllerDescriptor controllerDescriptor = new HttpControllerDescriptor(new HttpConfiguration(), "demo", typeof(DemoController));
     foreach (MethodInfo methodInfo in typeof(DemoController).GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance))
     {
         ReflectedHttpActionDescriptor actionDescriptor = new ReflectedHttpActionDescriptor(controllerDescriptor, methodInfo);
         foreach (HttpMethod httpMethod in actionDescriptor.SupportedHttpMethods)
         {
             Console.WriteLine("{0,-12}{1,-10}", actionDescriptor.ActionName, httpMethod);
         }
     }
 }
开发者ID:chenboyi081,项目名称:asp-net-web-api-2-samples,代码行数:13,代码来源:Program.cs


示例20: LogAction_should_log_with_format_string

        public void LogAction_should_log_with_format_string()
        {
            var helper = new ActionLogHelper(_loggerMock.Object);

            const string prefix = "pre";

            var controllerDescriptor = new HttpControllerDescriptor {ControllerType = typeof (ActionLogHelper)};
            var actionDescriptor = new ReflectedHttpActionDescriptor {ControllerDescriptor = controllerDescriptor};

            helper.LogAction(actionDescriptor, prefix);

            _loggerMock.Verify(x => x.DebugFormat(ActionLogHelper.LogTextFormatString, prefix, typeof(ActionLogHelper).FullName, null));
        }
开发者ID:isalo,项目名称:Mvc4ServicesBook,代码行数:13,代码来源:ActionLogHelperTests.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Reflector类代码示例发布时间:2022-05-24
下一篇:
C# Referrer类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap