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


C# ActionDescriptor.GetParameters方法代码示例

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


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

示例1: InvokeActionMethod

            protected override ActionResult InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary<string, object> parameters)
            {
                var uowParam = actionDescriptor.GetParameters().FirstOrDefault(x => x.ParameterType == typeof(IUnitOfWork));
                if (uowParam != null)
                {
                    var connectionKey = controllerContext.Controller.GetType().GetCustomAttribute<ConnectionKeyAttribute>();
                    if (connectionKey == null)
                        throw new ArgumentNullException("connectionKey");

                    using (var connection = SqlConnections.NewByKey(connectionKey.Value))
                    using (var uow = new UnitOfWork(connection))
                    {
                        parameters[uowParam.ParameterName] = uow;
                        var result = base.InvokeActionMethod(controllerContext, actionDescriptor, parameters);
                        uow.Commit();
                        return result;
                    }
                }

                var cnnParam = actionDescriptor.GetParameters().FirstOrDefault(x => x.ParameterType == typeof(IDbConnection));
                if (cnnParam != null)
                {
                    var connectionKey = controllerContext.Controller.GetType().GetCustomAttribute<ConnectionKeyAttribute>();
                    if (connectionKey == null)
                        throw new ArgumentNullException("connectionKey");

                    using (var cnn = SqlConnections.NewByKey(connectionKey.Value))
                    {
                        parameters[cnnParam.ParameterName] = cnn;
                        return base.InvokeActionMethod(controllerContext, actionDescriptor, parameters);
                    }
                }

                return base.InvokeActionMethod(controllerContext, actionDescriptor, parameters);
            }
开发者ID:CodeFork,项目名称:Serenity,代码行数:35,代码来源:ServiceEndpoint.cs

示例2: IsSameAction

        public bool IsSameAction(ActionDescriptor descriptor)
        {
            var desc = descriptor as ReflectedActionDescriptor;
            if (desc != null)
            {
                bool sameAction = ActionDescriptor.MethodInfo == desc.MethodInfo;
                if (sameAction)
                    return true;
            }
            ParameterDescriptor[] parameters1 = descriptor.GetParameters();

            bool same = descriptor.ControllerDescriptor.ControllerName.Equals(ActionDescriptor.ControllerDescriptor.ControllerName, StringComparison.OrdinalIgnoreCase) &&
                        descriptor.ActionName.Equals(ActionDescriptor.ActionName, StringComparison.OrdinalIgnoreCase) &&
                        (parameters1.Length == _actionParameterDescriptors.Length);

            if (same)
            {
                for (int i = parameters1.Length - 1; i >= 0; i--)
                {
                    if (parameters1[i].ParameterType == _actionParameterDescriptors[i].ParameterType)
                    {
                        continue;
                    }

                    same = false;
                    break;
                }
            }

            return same;
        }
开发者ID:hardCTE,项目名称:EasyFrameWork,代码行数:31,代码来源:FilterRegisterItem.cs

示例3: Invoke

        public bool Invoke(Action invokeMvcPipeline, ActionDescriptor actionDescriptor, ControllerContext controllerContext)
        {
            //IMvcActionInvoker is httpcontext scoped
            var mvcActionInvoker = _mvcActionInvokerResolver();
            mvcActionInvoker.Set(invokeMvcPipeline);

            var actionName = _actionNameProvider.GetName(actionDescriptor);

            //find uniqueId for behavior chain that corresponds to this action call
            var controllerType = controllerContext.Controller.GetType();
            var parameterDescriptors = actionDescriptor.GetParameters();
            var inputParameters = parameterDescriptors.ToDictionary(x => x.ParameterName, x => x.ParameterType);
            var uniqueId = _behaviorChainIdLookup.GetUniqueId(controllerType, actionName, inputParameters);

            //get the behavior chain and invoke it, using this instance of ControllerContext for it
            var arguments = new ServiceArguments();
            //provide controller context to any behaviors that need to get at it
            arguments.Set(typeof(ControllerContext), controllerContext);
            using (var nestedContainer = _container.GetNestedContainer())
            {
                var actionBehavior = nestedContainer.GetInstance<IActionBehavior>(arguments.ToExplicitArgs(), uniqueId.ToString());
                actionBehavior.Invoke();
            }
            return true;
        }
开发者ID:bobpace,项目名称:MvcToFubu,代码行数:25,代码来源:ControllerActionBehaviorChainInvoker.cs

示例4: GetFilters

        public IEnumerable<System.Web.Mvc.Filter> GetFilters(ControllerContext controllerContext, ActionDescriptor actionDescriptor)
        {
            //if ((controllerContext.Controller is ProductController || controllerContext.Controller is ProductsController) &&
            //    actionDescriptor.ActionName.Equals("ProductList", 
            //    StringComparison.InvariantCultureIgnoreCase))
            if ((actionDescriptor.ControllerDescriptor.ControllerName == "Product" || actionDescriptor.ControllerDescriptor.ControllerName == "Products") &&
                actionDescriptor.ActionName.Equals("ProductList", StringComparison.InvariantCultureIgnoreCase))
            {
                if (controllerContext.RouteData.Values["area"] != null &&
                    (controllerContext.RouteData.Values["area"].ToString() == "Admin" || controllerContext.RouteData.Values["area"].ToString() == "Vendor"))
                {
                    //return new List<System.Web.Mvc.Filter>() { new System.Web.Mvc.Filter(this, FilterScope.Action, 0) };
                }
            }

            if ((actionDescriptor.ControllerDescriptor.ControllerName == "Home") &&
                actionDescriptor.ActionName.Equals("Index",
                StringComparison.InvariantCultureIgnoreCase))
            {
                return new List<System.Web.Mvc.Filter>() { new System.Web.Mvc.Filter(this, FilterScope.Action, 0) };
            }

            var a = actionDescriptor.GetCustomAttributes(true);
            var b = actionDescriptor.GetFilterAttributes(true);
            var c = actionDescriptor.GetParameters();

            return new List<System.Web.Mvc.Filter>();
        }
开发者ID:mhsohail,项目名称:Livetameion_3.7,代码行数:28,代码来源:ActionFilters.cs

示例5: GetParameterValues

        protected virtual IDictionary<string, object> GetParameterValues(ControllerContext controllerContext, ActionDescriptor actionDescriptor)
        {
            Dictionary<string, object> parametersDict = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase);
            ParameterDescriptor[] parameterDescriptors = actionDescriptor.GetParameters();

            foreach (ParameterDescriptor parameterDescriptor in parameterDescriptors)
            {
                parametersDict[parameterDescriptor.ParameterName] = GetParameterValue(controllerContext, parameterDescriptor);
            }
            return parametersDict;
        }
开发者ID:arbium,项目名称:democratia2,代码行数:11,代码来源:MainController.cs

示例6: GetFilters

        ///// <summary>
        ///// Provides filters to apply to the specified action.
        ///// </summary>
        ///// <param name="controllerContext">The current controllerContext.</param>
        ///// <param name="actionDescriptor">The action descriptor for the action to provide filters for.</param>
        ///// <returns>
        ///// The filters to apply to the specified action.
        ///// </returns>
        public IEnumerable<Filter> GetFilters(ControllerContext controllerContext, ActionDescriptor actionDescriptor)
        {
            // Actions with a bound parameter of type ODataQueryOptions do not support the query filter
            // The assumption is that the action will handle the querying within the action implementation
            var apiActionDescriptor = actionDescriptor as ApiActionDescriptor;
            if (apiActionDescriptor != null && IsIQueryable(apiActionDescriptor.ReturnType) &&
                !actionDescriptor.GetParameters().Any(parameter => typeof(ODataQueryOptions).IsAssignableFrom(parameter.ParameterType)))
            {
                return new Filter[] { new Filter(QueryFilter, FilterScope.Global, null) };
            }

            return Enumerable.Empty<Filter>();
        }
开发者ID:dax70,项目名称:MvcApi,代码行数:21,代码来源:QueryFilterProvider.cs

示例7: GetParameterValues

 protected override IDictionary<string, object> GetParameterValues(ControllerContext cc, ActionDescriptor ad)
 {
     var ps = ad.GetParameters();
     var r = base.GetParameterValues(cc, ad);
     var a = cc.RouteData.Values["args"];
     var arg = (string) (defAct != null ? cc.RouteData.Values["action"] : a);
     var args = !string.IsNullOrEmpty(arg) ? arg.Split('/') : null;
     var rr = new Dictionary<string, object>();
     if (r.Count == 0)
     {
         return rr;
     }
     if (r.Count == 1)
     {
         if (!string.IsNullOrEmpty(arg))
         {
             foreach (var o in r)
             {
                 rr[o.Key] = Convert.ChangeType(arg, ps[0].ParameterType);
             }
         }
         else
         {
             ParseParameters(cc, r, rr);
         }
     }
     else
     {
         if (args != null && args.Length > 0)
         {
             int p = 0;
             foreach (var i in r)
             {
                 if (p >= args.Length)
                 {
                     break;
                 }
                 var par = ps[p];
                 rr[i.Key] = Convert.ChangeType(args[p], par.ParameterType);
                 p++;
             }
         }
         else
         {
             ParseParameters(cc, r, rr);
         }
     }
     return rr;
 }
开发者ID:mind0n,项目名称:hive,代码行数:49,代码来源:JoyActionInvoker.cs

示例8: FormatParams

 /// <summary>
 /// 格式化Action的参数字符串
 /// </summary>
 /// <param name="action"></param>
 /// <returns></returns>
 public static string FormatParams(ActionDescriptor action)
 {
     var param = action.GetParameters();
     var result = new StringBuilder();
     if (param.Length > 0)
     {
         foreach (var item in param)
         {
             result.Append(string.Format("Type:{0}, Name:{1}; ", item.ParameterType, item.ParameterName));
         }
         return result.ToString();
     }
     else
     {
         return null;
     }
 }
开发者ID:Partialsky,项目名称:AspNetIdentityPermission,代码行数:22,代码来源:ActionPermissionService.cs

示例9: GetParameterValues

        protected override IDictionary<string, object> GetParameterValues(ControllerContext controllerContext, ActionDescriptor actionDescriptor) {
            var directRequest = controllerContext.HttpContext.Items[DirectRequest.DirectRequestKey] as DirectRequest;
            var parametersDict = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase);
            ParameterDescriptor[] parameterDescriptors = actionDescriptor.GetParameters();

            if (directRequest == null) {
                throw new NullReferenceException(DirectResources.Common_DirectRequestIsNull);
            }

            if (!directRequest.IsFormPost && directRequest.Data != null) {
                controllerContext.Controller.ValueProvider = new DirectValueProvider(directRequest, parameterDescriptors);
            }

            foreach (ParameterDescriptor parameterDescriptor in parameterDescriptors) {
                parametersDict[parameterDescriptor.ParameterName] = GetParameterValue(controllerContext, parameterDescriptor);
            }
            return parametersDict;
        }
开发者ID:taskeenkayani,项目名称:ext-direct-mvc,代码行数:18,代码来源:DirectMethodInvoker.cs

示例10: GetSamplePath

        private static string GetSamplePath(RequestContext requestContext, ActionDescriptor action) {
            var urlHelper = new UrlHelper(requestContext);

            var actionNameAttrib = action.GetCustomAttributes(inherit: true).OfType<ActionNameAttribute>().FirstOrDefault();

            // This is tricky because some of the action parameters may not be meant to come from the route.
            // e.g. they could come from a POST body.
            // In that case, they may end up as bogus query string params on the path, which is a bit buggy
            var routeValues = new RouteValueDictionary();
            foreach (ParameterDescriptor param in action.GetParameters()) {
                routeValues.Add(param.ParameterName, GetDefaultValue(param));
            }

            return urlHelper.Action(
                actionNameAttrib != null ? actionNameAttrib.Name : action.ActionName,
                action.ControllerDescriptor.ControllerName.ToLowerInvariant(),
                routeValues);
        }
开发者ID:abuhmead1987,项目名称:Presentations,代码行数:18,代码来源:ControllerDetailer.cs

示例11: GetParameterValues

        protected override IDictionary<string, object> GetParameterValues(ControllerContext controllerContext, ActionDescriptor actionDescriptor)
        {
            var parametersDict = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase);
            var parameterDescriptors = actionDescriptor.GetParameters();

            if (_isJsonRequest)
            {
                //ִ��Json������ƴװ
                if (parameterDescriptors.Length == 1)
                    parametersDict[parameterDescriptors[0].ParameterName] = GetJsonParameterValue(controllerContext, parameterDescriptors[0]);
                else
                {
                    foreach (var parameterDescriptor in parameterDescriptors)
                    {
                        //parametersDict[parameterDescriptor.ParameterName] = GetParameterValue(controllerContext, parameterDescriptor);
                        parametersDict[parameterDescriptor.ParameterName] = GetJsonDictValue(controllerContext,
                                                                                             parameterDescriptor);
                    }
                }

            }
            else
            {
                foreach (var parameterDescriptor in parameterDescriptors)
                {
                    parametersDict[parameterDescriptor.ParameterName] = GetParameterValue(controllerContext, parameterDescriptor);
                }
            }

            return parametersDict;
        }
开发者ID:BGCX262,项目名称:zxd-svn-to-git,代码行数:31,代码来源:ZxdControllerActionInvoker.cs

示例12: GetActionSign

 /// <summary>
 /// 获取Action的方法签名
 /// </summary>
 /// <param name="descriptor">The descriptor.</param>
 /// <returns></returns>
 private string GetActionSign(ActionDescriptor descriptor)
 {
     return string.Format("{0}({1})", GetActionHttpAttr(descriptor), GetActionParamsString(descriptor.GetParameters()));
 }
开发者ID:kinsen,项目名称:LotteryVoteMVC,代码行数:9,代码来源:UserAuthorizeAttribute.cs


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