Exemple #1
0
        MethodInfo GetMethod(object target, object[] args)
        {
            try
            {
                foreach (MethodInfo info in FunctionNode.GetMethods(target))
                {
                    if (0 == string.Compare(info.Name, this.name, StringComparison.OrdinalIgnoreCase))
                    {
                        ParameterInfo[] parameters = info.GetParameters();
                        if (parameters.Length == args.Length)
                        {
                            bool found = true;
                            for (int i = 0; i < args.Length; i++)
                            {
                                Type   paramType = parameters[i].ParameterType;
                                object arg       = args[i];

                                if (null == arg)
                                {
                                    // null can be used only if reference types (!IsValueType)
                                    // or nullable type (int?)
                                    if (!paramType.IsValueType || null != Nullable.GetUnderlyingType(paramType))
                                    {
                                        continue;
                                    }
                                }
                                else
                                {
                                    if (paramType.IsAssignableFrom(arg.GetType()))
                                    {
                                        continue;
                                    }
                                }

                                found = false;
                                break;
                            }

                            if (found)
                            {
                                return(info);
                            }
                        }
                    }
                }
                return(null);
            }
            catch (Exception e)
            {
                Trace.WriteLine("" + e);
                return(null);
            }
        }
Exemple #2
0
 private MethodInfo GetMethod(object target, object[] args)
 {
     try
     {
         foreach (MethodInfo method in FunctionNode.GetMethods(target))
         {
             if (string.Compare(method.Name, this.name, StringComparison.OrdinalIgnoreCase) == 0)
             {
                 ParameterInfo[] parameters = method.GetParameters();
                 if (parameters.Length == args.Length)
                 {
                     bool flag = true;
                     for (int index = 0; index < args.Length; ++index)
                     {
                         Type   parameterType = parameters[index].ParameterType;
                         object obj           = args[index];
                         if (obj == null)
                         {
                             if (!parameterType.IsValueType || (object)Nullable.GetUnderlyingType(parameterType) != null)
                             {
                                 continue;
                             }
                         }
                         else if (parameterType.IsAssignableFrom(obj.GetType()))
                         {
                             continue;
                         }
                         flag = false;
                         break;
                     }
                     if (flag)
                     {
                         return(method);
                     }
                 }
             }
         }
         return((MethodInfo)null);
     }
     catch (Exception ex)
     {
         return((MethodInfo)null);
     }
 }