gpt4 book ai didi

c# - 在运行时编译 *.cs 文件并访问成员

转载 作者:太空宇宙 更新时间:2023-11-03 14:25:40 24 4
gpt4 key购买 nike

是否可以在运行时编译一个 cs 文件,以便我可以像访问普通类一样访问它?

在实践中,我读出一个文本文件并将其信息存储在一个类结构中。之后,我需要在我的应用程序中访问类成员。

我现在做了什么:我编译了 cs 文件并使用这个例子创建了一个 dll http://msdn.microsoft.com/en-us/library/system.codedom.compiler.compilerparameters.generateexecutable.aspx

我把它改成:

String exeName = String.Format(@"{0}\{1}.dll",
System.Environment.CurrentDirectory,
sourceFile.Name.Replace(".", "_"));

cp.GenerateExecutable = false;
cp.OutputAssembly = Name;
cp.GenerateInMemory = true;
cp.TreatWarningsAsErrors = false;

那现在呢?

编辑:这对我有帮助吗:

[DllImport("srec_struct_cs.dll", SetLastError = true)]

最佳答案

现在您可以使用 AppDomain.Load 之一加载程序集了过载。

关于c# - 在运行时编译 *.cs 文件并访问成员,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4126969/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com