you can achieve it by Reflection ,
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Reflection" %><script language="C#" runat=server>void Page_Load(Object source, EventArgs e) { output.Text = "<pre>" + GetTypes.Go() + "</pre>";
}class GetTypes
{
public static string Go()
{
StringWriter strWriter = new StringWriter();
Console.SetOut(strWriter); //获取 mscorlib 程序集, 它是在其中定义的一个对象
Assembly a = typeof(Object).Module.Assembly; //获取此程序集中的所有类型
Type [] types = a.GetTypes (); //让我们来看看它们,并在执行时收集一点数据。
int numValueTypes = 0;
int numInterfaces = 0;
int numClasses = 0;
int numArrays = 0; Console.WriteLine ("从程序集“{0}”中获取所有类型", a.GetName());
Console.WriteLine("将只列出接口类型。");
Console.WriteLine ("----------------------------------");
foreach (Type t in types)
{
if (t.IsClass) numClasses++;
if (t.IsValueType) numValueTypes++;
if (t.IsArray) numArrays++; if (t.IsInterface) {
Console.WriteLine (t.Name + ""); //仅输出接口的名称
numInterfaces++;
}
} //写出汇总
Console.WriteLine("-----------------------------------");
Console.WriteLine("在库 {1} 中的 {0} 个类型中:", types.Length, typeof(Object).Module.ToString());
Console.WriteLine ("{0} 个是接口(已列出)", numInterfaces);
Console.WriteLine ("{0} 个是值类型", numValueTypes);
Console.WriteLine ("{0} 个是类", numClasses);
Console.WriteLine ("{0} 个是数组", numArrays); Console.WriteLine("-----------------------------------");
Console.WriteLine(); //使用其文件名加载此程序集
try {
Assembly b = Assembly.LoadFrom
("c:/program files/microsoft.Net/.NET FrameworkDK/samples/quIckstart/howto/samples/reflection/gettypes/GetTypes.exe"); Console.WriteLine ("从程序集“{0}”中获取所有类型", b.GetName());
Console.WriteLine("-----------------------------------"); //获取此程序集的类型
Type [] types2 = b.GetTypes ();
foreach (Type t in types2)
{
Console.WriteLine (t.FullName + ""); //类型不多,所以我们可以将它们全部输出
}
}
catch (Exception) {
// 只是防备在指定的目录中找不到文件
Console.WriteLine("未找到对保存此应用程序的程序集信息的");
Console.WriteLine("文件的引用。");
Console.WriteLine("请更改此页的源文件,以在其他目录中查找");
} Console.WriteLine("-----------------------------------"); return strWriter.ToString();
}}//一些其他的任意类,以便程序集的此模块属于具有一些类型的程序集的一部分
public class TestClass1
{
}public class TestClass2
{
}</script>
<html>
<head>
<link rel="stylesheet" href="intro.css">
</head><body style="background-color:f6e4c6">
<p> <table>
<tr align=left><td><b>下面的示例列出给定程序集的类型</b>。我们说明如何获取包含此特定代码的程序集的类型,以及如何从 MSCorLib 程序集获取信息。由于 MSCorLib 中有太多类型,我们在此示例中选择了只显示接口(而这仍将产生一个包含 100 个以上接口的列表)。
<hr>
</td></tr> <tr><td><h4><asp:label id="output" runat="server"/></h4></td></tr>
</table></body>
</html>
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Reflection" %><script language="C#" runat=server>void Page_Load(Object source, EventArgs e) { output.Text = "<pre>" + GetTypes.Go() + "</pre>";
}class GetTypes
{
public static string Go()
{
StringWriter strWriter = new StringWriter();
Console.SetOut(strWriter); //获取 mscorlib 程序集, 它是在其中定义的一个对象
Assembly a = typeof(Object).Module.Assembly; //获取此程序集中的所有类型
Type [] types = a.GetTypes (); //让我们来看看它们,并在执行时收集一点数据。
int numValueTypes = 0;
int numInterfaces = 0;
int numClasses = 0;
int numArrays = 0; Console.WriteLine ("从程序集“{0}”中获取所有类型", a.GetName());
Console.WriteLine("将只列出接口类型。");
Console.WriteLine ("----------------------------------");
foreach (Type t in types)
{
if (t.IsClass) numClasses++;
if (t.IsValueType) numValueTypes++;
if (t.IsArray) numArrays++; if (t.IsInterface) {
Console.WriteLine (t.Name + ""); //仅输出接口的名称
numInterfaces++;
}
} //写出汇总
Console.WriteLine("-----------------------------------");
Console.WriteLine("在库 {1} 中的 {0} 个类型中:", types.Length, typeof(Object).Module.ToString());
Console.WriteLine ("{0} 个是接口(已列出)", numInterfaces);
Console.WriteLine ("{0} 个是值类型", numValueTypes);
Console.WriteLine ("{0} 个是类", numClasses);
Console.WriteLine ("{0} 个是数组", numArrays); Console.WriteLine("-----------------------------------");
Console.WriteLine(); //使用其文件名加载此程序集
try {
Assembly b = Assembly.LoadFrom
("c:/program files/microsoft.Net/.NET FrameworkDK/samples/quIckstart/howto/samples/reflection/gettypes/GetTypes.exe"); Console.WriteLine ("从程序集“{0}”中获取所有类型", b.GetName());
Console.WriteLine("-----------------------------------"); //获取此程序集的类型
Type [] types2 = b.GetTypes ();
foreach (Type t in types2)
{
Console.WriteLine (t.FullName + ""); //类型不多,所以我们可以将它们全部输出
}
}
catch (Exception) {
// 只是防备在指定的目录中找不到文件
Console.WriteLine("未找到对保存此应用程序的程序集信息的");
Console.WriteLine("文件的引用。");
Console.WriteLine("请更改此页的源文件,以在其他目录中查找");
} Console.WriteLine("-----------------------------------"); return strWriter.ToString();
}}//一些其他的任意类,以便程序集的此模块属于具有一些类型的程序集的一部分
public class TestClass1
{
}public class TestClass2
{
}</script>
<html>
<head>
<link rel="stylesheet" href="intro.css">
</head><body style="background-color:f6e4c6">
<p> <table>
<tr align=left><td><b>下面的示例列出给定程序集的类型</b>。我们说明如何获取包含此特定代码的程序集的类型,以及如何从 MSCorLib 程序集获取信息。由于 MSCorLib 中有太多类型,我们在此示例中选择了只显示接口(而这仍将产生一个包含 100 个以上接口的列表)。
<hr>
</td></tr> <tr><td><h4><asp:label id="output" runat="server"/></h4></td></tr>
</table></body>
</html>
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货