-10
A
回答
2
反射提供封裝程序集,模塊和類型的對象(類型爲Type)。您可以使用反射來動態創建類型的實例,將類型綁定到現有對象,或從現有對象獲取類型並調用其方法或訪問其字段和屬性
我已經使用反射動態加載在Reflection的幫助下組裝並顯示其形式。
Step 1: Loading an assembly form the specified path.
string path = Directory.GetCurrentDirectory() + @"\dynamicdll.dll";
try
{
asm = Assembly.LoadFrom(path);
}
catch (Exception)
{
}
Step 2: Getting all forms of an assembly dynamically & adding them to the list type.
List<Type> FormsToCall = new List<Type>();
Type[] types = asm.GetExportedTypes();
foreach (Type t in types)
{
if (t.BaseType.Name == "Form")
FormsToCall.Add(t);
}
Step 3:
int FormCnt = 0;
Type ToCall;
while (FormCnt < FormsToCall.Count)
{
ToCall = FormsToCall[FormCnt];
//Creates an instance of the specified type using the constructor that best matches the specified parameters.
object ibaseObject = Activator.CreateInstance(ToCall);
Form ToRun = ibaseObject as Form;
try
{
dr = ToRun.ShowDialog();
if (dr == DialogResult.Cancel)
{
cancelPressed = true;
break;
}
else if (dr == DialogResult.Retry)
{
FormCnt--;
continue;
}
}
catch (Exception)
{
}
FormCnt++;
}
相關問題
- 1. 喜歡的東西Opencart的對Java
- 2. ViewPager喜歡AndroidTV中BrowseFragment的東西
- 3. 喜歡的東西SQL 「LIKE」,但在PHP
- 4. 喜歡的東西在Objective-C
- 5. DataDirectory是什麼意思?任何其他的東西喜歡它?
- 6. 我想喜歡的東西的功能
- 7. 喜歡的東西adjustsImageWhenDisabled:對的UIBarButtonItem
- 8. 喜歡的東西輸入型日期
- 9. 喜歡facebook上的東西通過android
- 10. EXIF喜歡的東西視頻
- 11. 喜歡的東西expand.grid名單
- 12. 如何在laravel 5.5中做出喜歡和不喜歡的東西?
- 13. 喜歡的東西在鳳凰城的框架或部分
- 14. 喜歡的東西isFirst/isLast會在PlayFramework 2.x的模板
- 15. 喜歡的東西jQuery的.resizable但沒有div的內部
- 16. 簡單的推送通知沒有gcm喜歡的東西
- 17. 將多個「喜歡」的按鈕鏈接到同一個東西
- 18. 喜歡的東西ast.literal_eval執行變量賦值
- 19. 貝寶捐出你喜歡的東西下載
- 20. 喜歡的東西視圖狀態和會話
- 21. 尋找值喜歡的東西,但排除在MySQL中的已知項目
- 22. SonarJ喜歡.NET的工具
- 23. jQuery的:),而不是活的()思考(,生成的東西
- 24. .NET等效爲Java加密的東西
- 25. 如何使正則表達式「更喜歡」某些東西?
- 26. 什麼是適合REST的方式來「喜歡」Rails 3中的某些東西?
- 27. Android - 獲取聯繫人的電話號碼喜歡的東西正在輸入
- 28. GWT類的東西在.NET中
- 29. jquery喜歡在c#中擴展。.net
- 30. 在Facebook上顯示喜歡的喜歡數量喜歡按鈕
也許['的System.Reflection。*'](http://msdn.microsoft.com/library/system.reflection.aspx)? –
是的,它被稱爲反射。你想知道什麼? –
任何教程如何在.Net中使用它? – Krunal