[英]How to Create an Instance of a Class in runtime derived from ObservableCollection<T>?
[英]How to create class at runtime from file
是否可以在運行時從文件創建一個類而無需解析它?
如果不是從文件中檢索類屬性,構造函數和方法的最佳方法是什么? 考慮到文件可能有多個類,就像典型的cs文件一樣。
是的,可以在運行時從文件創建一個類。
您可以在MS.NET中使用運行時編譯器(反射)
看看這里
如果您使用的是ASP.NET,請查看BuildManager.GetCompiledAssembly 。
這是一個示例用法:
Assembly a = BuildManager.GetCompiledAssembly("~/TestClass.cs");
foreach (Type t in a.GetExportedTypes()) {
object obj = Activator.CreateInstance(t)
// Do something with obj...
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.