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


C# ReflectedHttpActionDescriptor类代码示例

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


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


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