网络编程 | 站长之家 | 网页制作 | 图形图象 | 操作系统 | 冲浪宝典 | 软件教学 | 网络办公 | 邮件系统 | 网络安全 | 认证考试 | 系统进程
Firefox | IE | Maxthon | 迅雷 | 电驴 | BitComet | FlashGet | QQ | QQ空间 | Vista | 输入法 | Ghost | Word | Excel | wps | Powerpoint
asp | .net | php | jsp | Sql | c# | Ajax | xml | Dreamweaver | FrontPages | Javascript | css | photoshop | fireworks | Flash | Cad | Discuz!
当前位置 > 网站建设学院 > 网络编程 > ASP文摘
Tag:注入,存储过程,分页,安全,优化,xmlhttp,fso,jmail,application,session,防盗链,stream,无组件,组件,md5,乱码,缓存,加密,验证码,算法,cookies,ubb,正则表达式,水印,索引,日志,压缩,base64,url重写,上传,控件,Web.config,JDBC,函数,内存,PDF,迁移,结构,破解,编译,配置,进程,分词,IIS,Apache,Tomcat,phpmyadmin,Gzip,触发器,socket
网络编程:ASP教程,ASP.NET教程,PHP教程,JSP教程,C#教程,数据库,XML教程,Ajax,Java,Perl,Shell,VB教程,Delphi,C/C++教程,软件工程,J2EE/J2ME,移动开发
本月文章推荐
..NET目标(二).
.用VB构建Internet的应用.
.代码大战:哪种语言会赢得开发的.
.ASP.NET升级能力探讨(三).
.影响IIS性能的几个因素(1).
.ASP值多少钱,还能值钱多久。.
.IIS组建Intranet完全手册(一).
.从VB 6.0到VB.NET的转换(4).
.从本质上看网页(asp,jsp)的编.
.ASP.NET升级能力探讨(一).
.VBScript与JScript谁怕谁(1).
..NET让新一代因特网变成现实(1).
..NET框架与网络服务(下).
.主页制作的五十个秘诀.
.IIS组建Intranet完全手册(三).
.VBScript与JScript谁怕谁(2).
.动态网页制作(二).
.Serv-U :快速构建功能强大的FTP.
.微软下一代网络服务器IIS7前瞻.
.技术分析:.NET的优势与劣势.

.net的reflection (2)

发表日期:2001-4-18


一旦得到类对象,上表中所列的方法就能被叫来调用reflaction.第一个例子将检查在CSharpReflectionSamples.Reflect类中的得到方法的信息。第一块代码用来定义类中的每个方法的名字,第二块代码将阐述得到方法信息。向下面所展示的,我们将用一个数组来保存用GetMethod()方法返回的方法信息。MethodInfo类包含信息为方法的名字,不管是否是虚拟的,它都是可见的,等等。

namespace CSharpReflectionSamples
{
using System;
using System.Reflection;

/// <summary>
/// Summary description for Client.
/// </summary>
public class Client
{
public static void Main()
{
// the typeof operator and the GetType method
// both return a 'Type' object.
Type type1 = typeof(Reflect);
Reflect objTest = new Reflect(0);
Type type2 = objTest.GetType();

Console.WriteLine("Type of objTest is {0}", type2);
Console.WriteLine();
// pause
Console.ReadLine();

// reflect method information
MethodInfo[] minfo = type1.GetMethods();
// iterate through methods
foreach (MethodInfo m in minfo)
{
Console.WriteLine(m);
}
Console.WriteLine();
}
}
}

下一个例子将展示动态得到对象有可能接触的每个构造器的信息。类似与上面的例子,我们将返回一个包含每个构造器的信息ConstructorInfo对象。

namespace CSharpReflectionSamples
{
using System;
using System.Reflection;

/// <summary>
/// Summary description for Client.
/// </summary>
public class Client
{
public static void Main()
{
// the typeof operator and the GetType method
// both return a 'Type' object.
Type type1 = typeof(Reflect);
Reflect objTest = new Reflect(0);
Type type2 = objTest.GetType();

Console.WriteLine("Type of objTest is {0}", type2);
Console.WriteLine();
// pause
Console.ReadLine();

// reflect constructors
ConstructorInfo[] cinfo = type1.GetConstructors();
// iterate through constructors
foreach (ConstructorInfo c in cinfo)
{
Console.WriteLine(c);
}
}
}
}

最后一部分,也许是reflection名字空间中最激动人心的部分,是在运行时动态调用类方法。有两种方法,首先,我们将建立一个数组来存储参数,这些参数被构造器用来建造对象。第二,一个System.Object对象将对抗CreateInstance方法的对象。以得到想得到对象的例子。最后,当我们有了对象的资料,我们能够调用任何使用MethodParm数组的方法。下面是代码:

namespace CSharpReflectionSamples
{
using System;
using System.Reflection;

/// <summary>
/// Summary description for Client.
/// </summary>
public class Client
{
public static void Main()
{
// the typeof operator and the GetType method
// both return a 'Type' object.
Type type1 = typeof(Reflect);
Reflect objTest = new Reflect(0);
Type type2 = objTest.GetType();



// dynamic creation and invocation
// instantiate the Reflect object, passing
// a value of 1 to the constructor
object[] oConstructParms = new object[] {1};
object obj = Activator.CreateInstance(type1, oConstructParms);
// invoke method of reflect object
object[] oMethodParms = new object[] {17};
int intResult = (int)type1.InvokeMember("AMethod", BindingFlags.Default |
BindingFlags.InvokeMethod, null, obj, oMethodParms);
Console.WriteLine("Result of calling AMethod on {0} is {1}",
type1.Name, intResult);
// pause
Console.ReadLine();
}
}
}


这篇文章阐述了.net Reflaction的基础,在下一部分,我将和大家讨论进一步的话题,比如,动态发布中间语言,旗帜绑定,和中间语言原则。


上一篇:.net的reflection (1)  人气:10211
下一篇:从VB 6.0到VB.NET的转换(1) 人气:14870
浏览全部的内容 Dreamweaver插件下载 网页广告代码 祝你圣诞节快乐 2009年新年快乐