public static object Eval(string assemblyFile, string typeName, string methodName, Type[] paramTypes, object[] args)
        {
            string directoryName = Path.GetDirectoryName(assemblyFile);

            MethodEvaluator.AssemblyResolver @object = new MethodEvaluator.AssemblyResolver(directoryName);
            AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(@object.AssemblyResolve);
            object result;

            try
            {
                Assembly   assembly = Assembly.LoadFrom(assemblyFile);
                MethodInfo method   = assembly.GetType(typeName, true).GetMethod(methodName, BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, null, paramTypes, null);
                if (method == null)
                {
                    throw new ArgumentException(string.Format("Method {0}.{1}({2}) not found in assembly {3}!", new object[]
                    {
                        typeName,
                        methodName,
                        MethodEvaluator.ToCommaSeparatedString <Type>(paramTypes),
                        assembly.FullName
                    }));
                }
                result = method.Invoke(null, args);
            }
            finally
            {
                AppDomain.CurrentDomain.AssemblyResolve -= new ResolveEventHandler(@object.AssemblyResolve);
            }
            return(result);
        }
Exemple #2
0
 public static object Eval(string assemblyFile, string typeName, string methodName, System.Type[] paramTypes, object[] args)
 {
     MethodEvaluator.AssemblyResolver assemblyResolver = new MethodEvaluator.AssemblyResolver(Path.GetDirectoryName(assemblyFile));
     AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(assemblyResolver.AssemblyResolve);
     try
     {
         Assembly   assembly = Assembly.LoadFrom(assemblyFile);
         MethodInfo method   = assembly.GetType(typeName, true).GetMethod(methodName, BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, (Binder)null, paramTypes, (ParameterModifier[])null);
         if (method == null)
         {
             throw new ArgumentException(string.Format("Method {0}.{1}({2}) not found in assembly {3}!", (object)typeName, (object)methodName, (object)MethodEvaluator.ToCommaSeparatedString <System.Type>((IEnumerable <System.Type>)paramTypes), (object)assembly.FullName));
         }
         return(method.Invoke((object)null, args));
     }
     finally
     {
         AppDomain.CurrentDomain.AssemblyResolve -= new ResolveEventHandler(assemblyResolver.AssemblyResolve);
     }
 }