2010-06-14 69 views
3

組裝我想Reflection.Emit在內存中創建

目前在內存中創建一個組件,使用使用類的,我可以創建裝配並獲得它的使用的東西字節像

AssemblyBuilder builder = 
    AppDomain.CurrentDomain.DefineDynamicAssembly(..., 
     AssemblyBuilderAccess.Save); 

... create the assembly ... 

builder.Save(targetFileName); 

using(FileStream fs = File.Open(targetFileName, FileMode.Open)) 
{ 
    ... read the bytes from the file stream ... 
} 

但是,它通過在本地文件系統上創建文件來實現。我實際上並不需要該文件,只需要文件中的字節。

是否可以在不寫任何文件的情況下創建程序集?

回答

3

在這個時間點這是不可能的。 C#團隊正在計劃「編譯器即服務」功能,希望將其納入C#5.0中。