什么是asp.net中的反射 [英] what is reflection in asp.net

查看:90
本文介绍了什么是asp.net中的反射的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是dinakar.我想知道我们在哪里以及如何使用反射

hi this is dinakar. i want to know where and how do we use reflection

推荐答案

MSDN文章 [使用反射来扩展.NET程序 [
Start from here[^] and also have a look at this MSDN article[^].

This CP article might be of interest too: Using reflection to extend .NET programs[^]

P.S: Try a sample application. If you encounter any difficulties post on CP and you will get lots of suggestions & improvements.


该类或结构是代码.有关每种类型具有哪些成员,其名称和类型以及每种方法的签名的数据-所有这些都是元数据.

取任何类型的初始化变量.它始终具有方法object.GetType,该方法返回类System.Type的对象.对于类型,可以使用typeof运算符,该运算符还返回类System.Type的实例.查找此类:
http://msdn.microsoft.com/en-us/library/system .type.aspx [^ ],另请参见 http://en.wikipedia.org/wiki/Type_class [ http://en.wikipedia.org/wiki/Reflection_(computer_science) [http://msdn.microsoft.com/en-us/library/system.attribute.aspx [ ^ ]).一个可以动态加载程序集(请参见类System.Reflection.Assembly http://msdn.microsoft .com/en-us/library/system.reflection.assembly.aspx [ ^ ]),并将其用于开发和使用插件.

请参阅我过去的答案,以解释基于Reflection的插件架构的骨架:
创建使用可重载插件的WPF应用程序... [ ^ ],
AppDomain拒绝加载程序集 [使用CodeDom生成代码 [创建使用可重载插件的WPF应用程序... [ ^ ].

甚至可以即时编译代码并立即在应用程序中使用它,请参阅上面的我的最后两个链接.最后,甚至可以即时生成( emit )代码,请参见System.Reflection.Emit http://www.codeproject.com/search.aspx?doctypeid=1&q= Reflection.Emit [ ^ ].

—SA
The class or structure is code. The data about what members every type has, their names and types, what are the signature of each method — all this is meta-data.

Take a initialized variable of any type. It always has a method object.GetType which returns the object of the class System.Type. For a type, you can use typeof operator which also returns the instance of the class System.Type. Look a this class: http://msdn.microsoft.com/en-us/library/system.type.aspx[^], see also http://en.wikipedia.org/wiki/Type_class[^].

You will find that all the meta-data is available through this class. It''s also possible to instantiate new objects of the type based on the Type''s invocation methods, read or modify properties of the instance. All this is called Reflection. See http://en.wikipedia.org/wiki/Reflection_(computer_science)[^].

It has many application. Using just meta-data approach one can persist data, generate IU on the fly based on pure data (and meta-data added with the use of .NET attributes, see http://msdn.microsoft.com/en-us/library/system.attribute.aspx[^]). One can load assemblies dynamically (see the class System.Reflection.Assembly, http://msdn.microsoft.com/en-us/library/system.reflection.assembly.aspx[^]) and use it for developing and using plug-ins.

See my past answers explaining a skeleton of plug-in architecture based on Reflection:
Create WPF Application that uses Reloadable Plugins...[^],
AppDomain refuses to load an assembly[^],
code generating using CodeDom[^],
Create WPF Application that uses Reloadable Plugins...[^].

One can even compile code on the fly and use it immediately in the application, see last two of my links above. Finally, one can even generate (emit) code on the fly, see System.Reflection.Emit, http://msdn.microsoft.com/en-us/library/system.reflection.emit.aspx[^].

There is a number of CodeProject articles on the interesting topic of System.Reflection.Emit, see:
http://www.codeproject.com/search.aspx?doctypeid=1&q=Reflection.Emit[^].

—SA


这篇关于什么是asp.net中的反射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆