反射基础知识
我对反射很陌生,在尝试理解类型时遇到了困难。
Assembly 到底是什么意思以及 Assembly.GetTypes()
返回什么?另外,如果您对从 GetTypes()
命令获取的“类型”调用类似 GetGenericArguments()
的内容,那么它到底会做什么?
谢谢
I am new to reflection and am hitting a brick wall trying to understand types.
What exactly does Assembly mean and what does Assembly.GetTypes()
return? Also if you call something like GetGenericArguments()
on a 'type' you get from the GetTypes()
command, what does that do exactly?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在本例中,程序集是 dll 或 exe 文件。
Assembly.GetTypes() 返回该程序集中的所有类型。
如果您有泛型类型
Type.GetGenericArguments 返回
T
和V
。Assembly is a dll or exe file in this case.
Assembly.GetTypes() returns all types in that assembly.
If you have a generic type
Type.GetGenericArguments returns the
T
and theV
.调用
Assembly.GetTypes()
返回程序集中定义的所有类型和接口。调用
Type.GetGenericArguments()
返回为泛型类型指定的所有泛型参数。这可能不是最清楚的解释,一个例子会有所帮助:Calling
Assembly.GetTypes()
returns all the types and interfaces that are defined in the assembly.Calling
Type.GetGenericArguments()
returns all the generic parameters specified for a generic type. This might not be the clearest explanation, an example would help:程序集包含运行或存储有关对象(即具有方法/属性/事件的类/结构)信息的代码。
类型是描述其他类的类。
http://msdn.microsoft.com /en-us/library/system.type%28v=vs.71%29.aspx
Assemblies contain code that runs, or stores information about objects i.e. classes/structures which have methods/properties/events.
A type is a class that describes other classes.
http://msdn.microsoft.com/en-us/library/system.type%28v=vs.71%29.aspx
.NET 中的程序集是一个 *.dll 文件,它是通过编译类库(和其他)项目类型生成的
Assembly.GetTypes()
返回该程序集中所有类型的数组,即说出所有的课程和课程装配体内的结构。进一步阅读
Assembly.GetTypes
< /a>System.Type
An assembly in .NET is a *.dll file which is produced by compiling a Class Library (and other) project types
Assembly.GetTypes()
returns an array of all the Types in that assembly, which is to say all the Classes & Structs inside the assembly.Further Reading
Assembly.GetTypes
System.Type