摘要:[原文作者]:Kit George
[原文链接]:LINQ Cookbook, Recipe 4: Find all complex types in a given assembly (Kit George)
准备材料:
- Visual Studio 2008 (Beta2 或更高版本)
- 一个需要分析的程序集 (在这个例子中, 我们使用了用来存储字符串的mscorlib.dll 程序集)
- 一个 “复杂类型”的字义. 在这个例子中, 复杂类型包含10个以上public方法,而且至少有一个方法具有3个以上的参数.
类别: LINQ-To-Objects, LINQ and types, LINQ and WinForms
制作方法:
- 打开 Visual Studio 2008, 点击菜单 “文件/新建项目”. 找到并双击 ”Windows 窗体应用程序” 图标.
- 拖放一个 Listbox 到窗体上,调整Listbox的高度. 再拖放一个按钮到窗体上
- 双击这个按钮, 并将以下代码添加到按钮的事件处理函数中:
Dim q = From type In System.Reflection.Assembly.GetAssembly( _
GetType(String)).GetTypes(), _
m In type.GetMethods() _
Where type.IsPublic _
AndAlso type.GetMethods.Length > 10 _
AndAlso m.GetParameters.Length > 3 _
Select type Distinct
ListBox1.Items.AddRange(q.ToArray)...[
阅读全文]