Tag: system codedom compiler

使用System.CodeDom生成扩展方法

有没有人试过在.NET 4.0下使用System.CodeDom生成扩展方法? 似乎没有任何方法可以将CodeMemberMethod或CodeParameterDeclarationExpression指定为扩展方法/参数。 如果这是不可能的,有什么好的解决方法吗? 谢谢

如何将嵌入式资源作为字节数组读取而不将其写入磁盘?

在我的应用程序中,我使用CodeDom.Compiler从source.cs文件编译另一个程序,并在编译时使用以下命令嵌入一些资源(exe和dll文件): // …. rest of code if (provider.Supports(GeneratorSupport.Resources)) { cp.EmbeddedResources.Add(“MyFile.exe”); } if (provider.Supports(GeneratorSupport.Resources)) { cp.EmbeddedResources.Add(“New.dll”); } // ….rest of code 在编译文件中,我需要将嵌入资源作为字节数组读取。 现在我通过使用下面的函数和使用将资源提取到磁盘来实现这一点 File.ReadAllBytes(“extractedfile.exe”); File.ReadAllBytes(“extracteddll.dll”); 我使用此函数将两个文件解压缩到磁盘后执行此操作: public static void ExtractSaveResource(String filename, String location) { // Assembly assembly = Assembly.GetExecutingAssembly(); System.Reflection.Assembly a = System.Reflection.Assembly.GetExecutingAssembly(); // Stream stream = assembly.GetManifestResourceStream(“Installer.Properties.mydll.dll”); // or whatever // string my_namespace = a.GetName().Name.ToString(); […]