假设我在我的主项目中编译了如下的一串代码。但是我想在CustomClass中实现一个接口。该界面位于我的解决方案中的另一个项目中(我的主项目中的部分引用)当我这样做时
公共类 CustomClass : 接口类型
我收到这样的错误。我如何引用另一个项目,以便我可以在我的动态代码中使用接口和属于它的其他类?
c:\Users\xxx\AppData\Local\Temp\m8ed4ow-.0.cs(1,32: error CS0246: The type or namespace name 'InterfaceType' could not be found (您是否缺少 using 指令或程序集引用?)
string code2 =
"    public class CustomClass : InterfaceType " +
"    {" +
"    }";
        // Compiler and CompilerParameters
        CSharpCodeProvider codeProvider = new CSharpCodeProvider();
        CompilerParameters compParameters = new CompilerParameters();
        compParameters.GenerateInMemory = false; //default
        //compParameters.TempFiles = new TempFileCollection(Environment.GetEnvironmentVariable("TEMP"), true);
        compParameters.IncludeDebugInformation = true;
        //compParameters.TempFiles.KeepFiles = true;
        compParameters.ReferencedAssemblies.Add("System.dll");
        CodeDomProvider compiler = CSharpCodeProvider.CreateProvider("CSharp");
        // Compile the code
        CompilerResults res = codeProvider.CompileAssemblyFromSource(compParameters, code2);
        // Check the compiler results for errors
        StringWriter sw = new StringWriter();
        foreach (CompilerError ce in res.Errors)
        {
            if (ce.IsWarning) continue;
            sw.WriteLine("{0}({1},{2}: error {3}: {4}", ce.FileName, ce.Line,     ce.Column, ce.ErrorNumber, ce.ErrorText);
        }
        string error = sw.ToString();
        sw.Close();
        // Create a new instance of the class 'CustomClass'
        object myClass = res.CompiledAssembly.CreateInstance("CustomClass");