Ejemplo n.º 1
0
    public void Compile()
    {
        OutputField.textComponent.color = _defaultTextColour;
        CompilerResults compile = CompileHelper.CompileCodeFromString(_inputField.text);

        if (compile.Errors.HasErrors)
        {
            string text = "Compile error: ";
            foreach (CompilerError error in compile.Errors)
            {
                text += '\n' + error.ToString();
            }

            var defaultColour = OutputField.textComponent.color;
            OutputField.textComponent.color = Color.red;
            OutputField.text = text;
            return;
        }

        Module     module     = compile.CompiledAssembly.GetModules()[0];
        Type       typeInfo   = null;
        MethodInfo methodInfo = null;

        if (module != null)
        {
            typeInfo = module.GetType("TestClass");
        }

        if (typeInfo != null)
        {
            methodInfo = typeInfo.GetMethod("EchoStuff");
        }

        if (methodInfo != null)
        {
            OutputField.text = (string)methodInfo.Invoke(null, new object[] { "Here's some stuff!" });
        }
    }