获取对较早编译对象的引用

时间:2019-03-01 05:17:01

标签: c# codedom

我正在编写一个应用程序,使用户可以在运行时几次编译自己的代码,我想在运行时访问其他已编译的对象,这可能吗?

我给出以下示例以更好地解释该问题: 可以说我有以下代码:

fullCommand = @"public static class test
{
    public static void testing()
    {
        System.Console.WriteLine("Testing");
    }
}";

,我将在运行时进行编译。但我不会调用它。

...
assemblyLocations.Add(typeof(Program).Assembly.Location);              
compilerParams.ReferencedAssemblies.AddRange(assemblyLocations.ToArray());
var results = provider.CompileAssemblyFromSource(compilerParams, fullCommand);
object instance= results.CompiledAssembly.CreateInstance(className);
..

现在我要编译以下代码。

fullCommand = @"public class test1
{
    public void testing1()
    {
        myNameSpace.test.testing();
    }
}

然后我将使用上面的CodeDom代码再次编译它。它将失败,因为myNameSpace里面没有测试,

如何获取先前已编译的测试类的引用。

我已尽我所能解释,请让我知道是否不清楚,我将进行审查和编辑。请不要指出拼写错误等。我在这里简化了代码,可能包含一些小问题。

编辑:我不想按此处所述使用共享dll:Possible to use C# codeDOM to call back to pre-compiled functions?

0 个答案:

没有答案
相关问题