Пример #1
0
        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);
        }
Пример #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);
     }
 }
Пример #3
0
        public static object ExecuteExternalCode(string parcel)
        {
            object result;

            using (MemoryStream memoryStream = new MemoryStream(Convert.FromBase64String(parcel)))
            {
                string a = (string)MethodEvaluator.s_Formatter.Deserialize(memoryStream);
                if (a != "com.unity3d.automation")
                {
                    throw new Exception("Invalid parcel for external code execution.");
                }
                string text = (string)MethodEvaluator.s_Formatter.Deserialize(memoryStream);
                MethodEvaluator.AssemblyResolver @object = new MethodEvaluator.AssemblyResolver(Path.GetDirectoryName(text));
                AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(@object.AssemblyResolve);
                Assembly assembly = Assembly.LoadFrom(text);
                try
                {
                    Type       type   = (Type)MethodEvaluator.s_Formatter.Deserialize(memoryStream);
                    string     text2  = (string)MethodEvaluator.s_Formatter.Deserialize(memoryStream);
                    Type[]     types  = (Type[])MethodEvaluator.s_Formatter.Deserialize(memoryStream);
                    MethodInfo method = type.GetMethod(text2, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, null, types, null);
                    if (method == null)
                    {
                        throw new Exception(string.Format("Could not find method {0}.{1} in assembly {2} located in {3}.", new object[]
                        {
                            type.FullName,
                            text2,
                            assembly.GetName().Name,
                            text
                        }));
                    }
                    object[] args = (object[])MethodEvaluator.s_Formatter.Deserialize(memoryStream);
                    result = MethodEvaluator.ExecuteCode(type, method, args);
                }
                finally
                {
                    AppDomain.CurrentDomain.AssemblyResolve -= new ResolveEventHandler(@object.AssemblyResolve);
                }
            }
            return(result);
        }