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


C# Controller.GetType方法代码示例

本文整理汇总了C#中Controller.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# Controller.GetType方法的具体用法?C# Controller.GetType怎么用?C# Controller.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Controller的用法示例。


在下文中一共展示了Controller.GetType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AssertFieldsAreNotNull

        public static void AssertFieldsAreNotNull( Controller controller )
        {
            var allReadOnlyFields = new List<FieldInfo>();

            Type controllerType = controller.GetType();
            while ( controllerType != null )
            {
                var fields =
                    controllerType
                        .GetFields( BindingFlags.NonPublic | BindingFlags.Instance )
                        .Where( x => x.IsInitOnly );
                allReadOnlyFields.AddRange( fields );
                controllerType = controllerType.BaseType;
            }

            var fieldsWithNullValue = allReadOnlyFields
                .Where( x => x.GetValue( controller ) == null )
                .ToList();

            if ( fieldsWithNullValue.Count > 0 )
            {
                Console.WriteLine( "The Following " + fieldsWithNullValue.Count + " fields are not set" );
                fieldsWithNullValue.ForEach( x => Console.WriteLine( x.Name ) );
                Assert.Fail();
            }
        }
开发者ID:RendaniTshinakaho,项目名称:PseudoCQRS,代码行数:26,代码来源:HasSetAllDependenciesControllerHelper.cs

示例2: 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;
            }
        }
开发者ID:MichaelaIvanova,项目名称:Telerik-Software-Academy,代码行数:35,代码来源:ActionInvoker.cs

示例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;
            }
        }
开发者ID:exploitx3,项目名称:HighQualityCode,代码行数:30,代码来源:ActionInvoker.cs

示例4: IsHavePower

        private bool IsHavePower(IList<EmpModFunc> empModFuncs, Controller serviceBase, FuncEnum funcName)
        {
            bool retVal = false;

            string cls = serviceBase.GetType().FullName;

            if (empModFuncs != null)
            {
                foreach (EmpModFunc empModFunc in empModFuncs)
                {
                    //查找用户是否存在类的权限
                    if (empModFunc.ModFunc.Cls.Equals(cls))
                    {
                        if (empModFunc.FuncNames == null)
                        {
                            empModFunc.FuncNames = "";
                        }
                        //把函数枚举转为字符串形式,如"|Add|"
                        string funcNameStr = "|" + funcName + "|";
                        //查找函数权限
                        int find = empModFunc.FuncNames.IndexOf(funcNameStr);
                        if (find > -1)
                        {
                            retVal = true;
                            break;
                        }
                    }
                }
            }
            return retVal;
        }
开发者ID:iEasyJob,项目名称:EasyJob,代码行数:31,代码来源:PowerActionFilterAttribute.cs

示例5: AssertAttribute

        private static void AssertAttribute(Controller controller, string actionMethodName, Type attribute, Type[] parameterTypes)
        {
            var type = controller.GetType();
            var methodInfo = type.GetMethod(actionMethodName, parameterTypes ?? new Type[0]);
            var attributes = methodInfo.GetCustomAttributes(attribute, true);

            Assert.IsTrue(attributes.Any(), string.Format("{0} not found on action {1}", attribute.Name, actionMethodName));
        }
开发者ID:jk915,项目名称:set-locale,代码行数:8,代码来源:ControllerTestHelper.cs

示例6: CustomActionParamsMapper

        /// <summary>
        /// Initializes a new instance of the <see cref="CustomActionParamsMapper"/> class.
        /// </summary>
        /// <param name="controller">The controller.</param>
        /// <param name="routeTemplateResolver">This function should return the route template that the mapper will use.</param>
        /// <param name="actionName">Name of the action.</param>
        /// <exception cref="System.ArgumentNullException">routeTemplateResolver</exception>
        public CustomActionParamsMapper(Controller controller, Func<string> routeTemplateResolver, string actionName = CustomActionParamsMapper.DefaultActionName)
            : base(controller)
        {
            if (routeTemplateResolver == null)
                throw new ArgumentNullException("routeTemplateResolver");

            this.actionName = actionName;
            this.actionMethod = controller.GetType().GetMethod(this.actionName, BindingFlags.Instance | BindingFlags.Public);
            this.routeTemplateResolver = routeTemplateResolver;
        }
开发者ID:rfavillejr,项目名称:feather,代码行数:17,代码来源:CustomActionParamsMapper.cs

示例7: CreateControllerContext

        private static ControllerContext CreateControllerContext(Controller controller)
        {
            if (HttpContext.Current == null) throw new InvalidOperationException("HttpContext unavailable");

            var routeData = new RouteData();
            if (routeData.Values.ContainsKey("controller") == false && routeData.Values.ContainsKey("Controller") == false)
            {
                routeData.Values.Add("controller", controller.GetType().Name.ToLower().Replace("controller", ""));
            }
            return new ControllerContext(new HttpContextWrapper(HttpContext.Current), routeData, controller);
        }
开发者ID:fengweijp,项目名称:higlabo,代码行数:11,代码来源:ControllerExtensions.cs

示例8: GetAttributesFor

        public static IEnumerable<Type> GetAttributesFor(Controller controller, String methodName)
        {
            var type = controller.GetType();
            var methodInfo = type.GetMethod(methodName);

            if (methodInfo == null)
                return Enumerable.Empty<Type>();

            var methodAttributes = methodInfo.GetCustomAttributes(false);
            return methodAttributes.Select(a => a.GetType());
        }
开发者ID:cidthecoatrack,项目名称:CourseCentral,代码行数:11,代码来源:AttributeProvider.cs

示例9: Log

 internal void Log(string userName, string action, Controller sender)
 {
     Log log = new Log()
     {
         UserName = userName,
         Action = action,
         Time = DateTime.Now,
         Controller = sender.GetType().Namespace,
     };
     _logRepo.Create(log);
 }
开发者ID:NickABoen,项目名称:CIS526_TeamProjects,代码行数:11,代码来源:LogController.cs

示例10: ProtectsFromOverposting

        protected void ProtectsFromOverposting(Controller controller, String postMethod, String properties)
        {
            MethodInfo methodInfo = controller
                .GetType()
                .GetMethods()
                .First(method =>
                    method.Name == postMethod &&
                    method.IsDefined(typeof(HttpPostAttribute), false));

            BindAttribute actual = methodInfo
                .GetParameters()
                .First()
                .GetCustomAttribute<BindAttribute>(false);

            Assert.Equal(properties, actual.Exclude);
        }
开发者ID:vmpay,项目名称:VisualStudio,代码行数:16,代码来源:ControllerTests.cs

示例11: ProtectsFromOverposting

        protected void ProtectsFromOverposting(Controller controller, String postMethod, String value)
        {
            MethodInfo methodInfo = controller
                .GetType()
                .GetMethods()
                .First(method =>
                    method.Name == postMethod &&
                    method.IsDefined(typeof(HttpPostAttribute), false));

            CustomAttributeData actual = methodInfo
                .GetParameters()
                .First()
                .CustomAttributes
                .Single(attr => attr.AttributeType == typeof(BindAttribute));

            Assert.Equal(value, actual.NamedArguments.Single().TypedValue.Value);
            Assert.Equal("Exclude", actual.NamedArguments.Single().MemberName);
        }
开发者ID:vothlizard,项目名称:MVC.Template,代码行数:18,代码来源:AControllerTests.cs

示例12: GetControllerPathTransformations

        private static IList<Func<string, string>> GetControllerPathTransformations(Controller controller, string customPath)
        {
            var packagesManager = new PackagesManager();
            var currentPackage = packagesManager.GetCurrentPackage();
            var pathTransformations = new List<Func<string, string>>();

            if (controller.RouteData != null && controller.RouteData.Values.ContainsKey("widgetName"))
            {
                var widgetName = (string)controller.RouteData.Values["widgetName"];
                var controllerType = FrontendManager.ControllerFactory.ResolveControllerType(widgetName);
                var widgetVp = FrontendControllerFactory.AppendDefaultPath(FrontendManager.VirtualPathBuilder.GetVirtualPath(controllerType));
                pathTransformations.Add(FrontendControllerFactory.GetPathTransformation(widgetVp, currentPackage, widgetName));
            }

            var controllerVp = customPath ?? FrontendControllerFactory.AppendDefaultPath(FrontendManager.VirtualPathBuilder.GetVirtualPath(controller.GetType().Assembly));
            pathTransformations.Add(FrontendControllerFactory.GetPathTransformation(controllerVp, currentPackage));

            return pathTransformations;
        }
开发者ID:vkoppaka,项目名称:feather,代码行数:19,代码来源:FrontendControllerFactory.cs

示例13: ItemNotFound

        public static ViewResultBase ItemNotFound(Controller trigger, String message)
        {
            ObjectServices.Logger.CreateLogger(trigger.GetType()).Warn("Item Not Found! Message = {0}", message);

            ErrorViewModel viewmodel = new ErrorViewModel();
            viewmodel.ErrorText = message;
            viewmodel.ErrorRequestPath = trigger.HttpContext.Request.Url.AbsoluteUri;

            if (trigger.Request.UrlReferrer != null)
            {
                viewmodel.ReturnUrl = trigger.Request.UrlReferrer.AbsoluteUri;
            }

            ViewDataDictionary viewData = new ViewDataDictionary
            {
                Model = viewmodel
            };

            ViewResultBase viewresult = trigger.Request.IsAjaxRequest() ? (ViewResultBase)new PartialViewResult() : (ViewResultBase)new ViewResult();
            viewresult.ViewName = "ItemNotFound";
            viewresult.ViewData = viewData;

            return viewresult;
        }
开发者ID:gest01,项目名称:DomainArchitecture,代码行数:24,代码来源:ErrorViewBuilder.cs

示例14: HandleUnknownAction

 private static void HandleUnknownAction(Controller controller, string actionName)
 {
     throw new HttpException(0x194, string.Format(SR.GetString("Controller_UnknownAction"), new object[] { actionName, controller.GetType().FullName }));
 }
开发者ID:jason1234,项目名称:CMS,代码行数:4,代码来源:ModuleExecutor.cs

示例15: ActionIsSecuredByPermission

        private bool ActionIsSecuredByPermission(Controller controller, string actionName, string permissionId)
        {
            var methodInfo = controller.GetType().GetMethod(actionName);
            if (methodInfo == null)
                throw new InvalidOperationException("Action named '" + actionName + "' not found.");

            var attributes = methodInfo.GetCustomAttributes(typeof(UmbracoAuthorizeAttribute), true);
            if (attributes.Length == 0)
                return false;

            return attributes.Cast<UmbracoAuthorizeAttribute>().Any(x => x.Permissions.Length > 0 && x.Permissions.Contains(permissionId));
        }
开发者ID:paulsuart,项目名称:rebelcmsxu5,代码行数:12,代码来源:ContentEditorControllerTests.cs


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