Ejemplo n.º 1
0
            public SandboxResult Run(string className, string resultProperty, byte[] compiledAssembly)
            {
                var assembly = Assembly.Load(compiledAssembly);
                assembly.EntryPoint.Invoke(null, new object[] { });

                var console = (StringWriter)assembly.GetType("Script").GetField("__Console").GetValue(null);

                var result = new SandboxResult
                             {
                                 ConsoleOutput = console.ToString(),
                                 ReturnValue = assembly.GetType(className).GetProperty(resultProperty).GetValue(null, null)
                             };

                return result;
            }
Ejemplo n.º 2
0
            public SandboxResult Run(string className, string methodName, string resultProperty, byte[] compiledAssembly)
            {
                if (className == null)
                {
                    throw new ArgumentNullException("className");
                }

                if (methodName == null)
                {
                    throw new ArgumentNullException("methodName");
                }

                if (resultProperty == null)
                {
                    throw new ArgumentNullException("resultProperty");
                }

                if (compiledAssembly == null)
                {
                    throw new ArgumentNullException("compiledAssembly");
                }

                var returnValue = (object)null;

                var assembly = Assembly.Load(compiledAssembly);

                var targetType = assembly.GetType(className, true);

                var target = targetType.GetMethod(methodName);
                var console = (StringWriter)assembly.GetType("Script", true).GetField("__Console").GetValue(null);

                try
                {
                    target.Invoke(null, new object[0]);
                    returnValue = assembly.GetType(className).GetProperty(resultProperty).GetValue(null, null);
                }
                catch (Exception exc)
                {
                    returnValue = exc;
                }

                var result = new SandboxResult
                             {
                                 ConsoleOutput = console.ToString(),
                                 ReturnValue = returnValue
                             };

                return result;
            }