コード例 #1
0
 protected virtual void ExecuteRule(string ruleId)
 {
     MethodInfo[] methods = GetType().GetMethods((BindingFlags.Public | (BindingFlags.NonPublic | BindingFlags.Instance)));
     foreach (MethodInfo method in methods)
     {
         object[] ruleBindings = method.GetCustomAttributes(typeof(RuleAttribute), true);
         foreach (RuleAttribute ra in ruleBindings)
         {
             if (ra.Id == ruleId)
             {
                 BlockRule(ruleId);
                 ParameterInfo[] parameters = method.GetParameters();
                 object[]        arguments  = new object[parameters.Length];
                 for (int i = 0; (i < parameters.Length); i++)
                 {
                     ParameterInfo p = parameters[i];
                     FieldValue    v = SelectFieldValueObject(p.Name);
                     if (v != null)
                     {
                         if (p.ParameterType.Equals(typeof(FieldValue)))
                         {
                             arguments[i] = v;
                         }
                         else
                         {
                             try
                             {
                                 arguments[i] = DataControllerBase.ConvertToType(p.ParameterType, v.Value);
                             }
                             catch (Exception)
                             {
                             }
                         }
                     }
                 }
                 method.Invoke(this, arguments);
             }
         }
     }
 }
コード例 #2
0
        public List <T> ToList <T>()

        {
            Type     objectType = typeof(T);
            List <T> list       = new List <T>();

            object[] args  = new object[1];
            Type[]   types = new Type[Fields.Count];
            for (int j = 0; (j < Fields.Count); j++)
            {
                System.Reflection.PropertyInfo propInfo = objectType.GetProperty(Fields[j].Name);
                if (propInfo != null)
                {
                    types[j] = propInfo.PropertyType;
                }
            }
            foreach (object[] row in Rows)
            {
                T   instance = ((T)(objectType.Assembly.CreateInstance(objectType.FullName)));
                int i        = 0;
                foreach (DataField field in Fields)
                {
                    try
                    {
                        Type fieldType = types[i];
                        if (fieldType != null)
                        {
                            args[0] = DataControllerBase.ConvertToType(fieldType, row[i]);
                            objectType.InvokeMember(field.Name, System.Reflection.BindingFlags.SetProperty, null, instance, args);
                        }
                    }
                    catch (Exception)
                    {
                    }
                    i++;
                }
                list.Add(instance);
            }
            return(list);
        }
コード例 #3
0
        private bool InternalExecuteMethod(ActionArgs args, ActionResult result, ActionPhase phase, bool viewMatch, bool argumentMatch)
        {
            _arguments = args;
            _result    = result;
            bool success = false;

            MethodInfo[] methods = GetType().GetMethods((BindingFlags.Public | (BindingFlags.NonPublic | BindingFlags.Instance)));
            foreach (MethodInfo method in methods)
            {
                object[] filters = method.GetCustomAttributes(typeof(ControllerActionAttribute), true);
                foreach (ControllerActionAttribute action in filters)
                {
                    if (((action.Controller == args.Controller) || (!(String.IsNullOrEmpty(args.Controller)) && Regex.IsMatch(args.Controller, action.Controller))) && ((!(viewMatch) && String.IsNullOrEmpty(action.View)) || (action.View == args.View)))
                    {
                        if ((action.CommandName == args.CommandName) && ((!(argumentMatch) && String.IsNullOrEmpty(action.CommandArgument)) || (action.CommandArgument == args.CommandArgument)))
                        {
                            if (action.Phase == phase)
                            {
                                ParameterInfo[] parameters = method.GetParameters();
                                if ((parameters.Length == 2) && ((parameters[0].ParameterType == typeof(ActionArgs)) && (parameters[1].ParameterType == typeof(ActionResult))))
                                {
                                    method.Invoke(this, new object[] {
                                        args,
                                        result
                                    });
                                }
                                else
                                {
                                    object[] arguments = new object[parameters.Length];
                                    for (int i = 0; (i < parameters.Length); i++)
                                    {
                                        ParameterInfo p = parameters[i];
                                        FieldValue    v = SelectFieldValueObject(p.Name);
                                        if (v != null)
                                        {
                                            if (p.ParameterType.Equals(typeof(FieldValue)))
                                            {
                                                arguments[i] = v;
                                            }
                                            else
                                            {
                                                try
                                                {
                                                    arguments[i] = DataControllerBase.ConvertToType(p.ParameterType, v.Value);
                                                }
                                                catch (Exception)
                                                {
                                                }
                                            }
                                        }
                                    }
                                    method.Invoke(this, arguments);
                                    success = true;
                                }
                            }
                        }
                    }
                }
            }
            return(success);
        }