Пример #1
0
        public void Default(string name, Arguments nvc)
        {
            ManagementController ma = CreateAction(Context, name);

            if (ma != null)
            {
                ma.SetManagement(this);
                string action = Utility.DefaultAction;
                if (nvc.Count > 0)
                {
                    action = nvc[0];
                    nvc.SetIndex(1);
                }
                MethodInfo method = ma.GetType().GetMethod(action, BindingFlags.Public | BindingFlags.Instance | BindingFlags.InvokeMethod | BindingFlags.IgnoreCase);
                if (method == null)
                {
                    throw new DebugException(string.Concat("Action \"", name, ".", action, "\" can not defined"));
                }

                int             argsn = 0;
                object[]        args  = null;
                ParameterInfo[] ps    = method.GetParameters();
                if (ps != null)
                {
                    argsn = ps.Length;
                }
                bool hasArgs = (ps.Length > 0 && ps[ps.Length - 1].ParameterType == TType <Arguments> .Type);
                if (nvc.Count > argsn && !hasArgs)
                {
                    StringBuilder sb = new StringBuilder(string.Concat("Action \"", name, ".", action, "("));
                    for (int i = 0; i < ps.Length; ++i)
                    {
                        if (i > 0)
                        {
                            sb.Append(", ");
                        }
                        sb.Append(ps[i].ParameterType.Name);
                    }
                    sb.Append(")\" 参数不匹配");
                    throw new DebugException(sb.ToString());
                }
                if (argsn > 0)
                {
                    args = new object[argsn];
                    for (int i = 0; i < argsn; ++i)
                    {
                        if (hasArgs && i == (argsn - 1))
                        {
                            nvc.SetIndex(i);
                            args[i] = nvc;
                        }
                        else
                        {
                            args[i] = Application.FormatParameter(ps[i], nvc[i]);
                        }
                    }
                }

                method.Invoke(ma, args);
            }
            else
            {
                NotFound();
            }
        }