可以使用反射的各种方案. [英] Various scenarious where Reflection can be used.

查看:62
本文介绍了可以使用反射的各种方案.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果你们与我分享在项目中实现的反射的用法,我将非常感激.我知道反射..但还没有机会使用它. :(
只是想知道使用它们的所有各种情况.
谢谢

I will be thankful if you guys share me the uses of reflection , that you have implemented in your project. I know about Reflection .. but haven''t got chance to use it yet. :(
Just wanted to know all various scenarios where they are used.
Thanks

推荐答案

这应该使您入门:
This should get you started: http://www.codeproject.com/search.aspx?q=Reflection+C%23&sbo=kw[^]


一个正确的问题.对于所有各种情况"的要求都是荒谬的.答案将是:这些方案的数量是无限的,最多只能是可数的.列出每种情况的快速解答"的文本长度将是无限的.想要尝试吗? :-)

反思是编程的一个巨大领域.在我看来,这个问题与某人问您的问题相同:我想使用一个类来了解所有场景.或功能.你有照片吗?

因此,您只能得到一个大致的想法.首先,您需要了解元数据的概念.基本上,如果您不了解元数据和反射的作用,那么您将不懂.NET编程.曾经使用过序列化吗?关于要序列化的对象的类型,不可能进行序列化.怎么可能呢?对象通过object.GetType()保留类型的信息,而类型System.Type递归地保留有关该类型的所有信息:所有成员,属性,其所有类型等等.

您认为PropertyGrid如何工作?您只传递对对象的引用.该组件如何知道结构?通过反思.

Reflection是所有插件的基础.请查看我过去关于该主题的答案:
创建使用可重载插件的WPF应用程序... [^ ],
AppDomain拒绝加载程序集 [使用CodeDom生成代码 [创建使用可重载插件的WPF应用程序... [ ^ ],
动态加载用户控件 [在现有实例上的C#反射InvokeMember [项目和DLL:如何使其可管理? [ ^ ].

请查看概述:
http://en.wikipedia.org/wiki/Metadata [ http://en.wikipedia.org/wiki/Reflection_%28computer_programming%29 [ ^ ].

—SA
This is not quite a correct question. The request for "all various scenarios" is just ridiculous. The answer would be: the number of those scenarios in infinite, not no more than countable. And the length of the text of the "Quick Answer" listing each of scenarios would be infinite. Care to try? :-)

Reflection is a huge field of programming. To me, it the question looks the same as someone asked you : I want to know all the scenarios using a class. Or a function. Are you getting the picture?

So, you can only get a general idea. First of all, you need to get an idea of the concept of meta-data. Basically, if you don''t know the role of meta-data and Reflection, you have no idea of .NET programming. Ever used serialization? Serialization is not possible about the types of the object being serialized. How can it be possible? The objects keep information of the type, via object.GetType(), and the type System.Type keeps all the information on the type: all members, attributes, all their type, and so on, recursively.

How do you think PropertyGrid can work? You only pass a reference to an object. How this components knows the structure? Through Reflection.

The Reflection is the base of any kinds of plug-ins. Please see my past answers on this topic:
Create WPF Application that uses Reloadable Plugins...[^],
AppDomain refuses to load an assembly[^],
code generating using CodeDom[^],
Create WPF Application that uses Reloadable Plugins...[^],
Dynamically Load User Controls[^],
C# Reflection InvokeMember on existing instance[^],
Projects and DLL''s: How to keep them managable?[^].

Please see the overview:
http://en.wikipedia.org/wiki/Metadata[^],
http://en.wikipedia.org/wiki/Reflection_%28computer_programming%29[^].

—SA


我的备用提示/技巧显示了一种用法:
My alternate tip/trick shows one use: No More Session Variable Misspellings.

Basically, reflection is used in that case to automatically initialize variables to reduce the amount of code. It also ensures you don''t mistype something, as all strings are generated based on property names.


这篇关于可以使用反射的各种方案.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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