获取的&QUOT类型;类型"在C#中反思 [英] Getting the type of a "Type" in C# reflection

查看:151
本文介绍了获取的&QUOT类型;类型"在C#中反思的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是更难的文档找到比我想象的。无论如何,我有键入某些情况下。我如何才能找到他们是否代表了类,方法,接口等?

This is harder to find in the docs than I imagined. Anyway, I have some instances of Type. How can I find out if they represent classes, methods, interfaces, etc?


class Bla { ... }
typeof(Bla).GetKindOrWhatever() // need to get something like "Class"

(我使用单在Linux上但不应该'T影响的问题,我在做移植的代码)

(I'm using Mono on Linux but that shouldn't affect the question, I'm making portable code)

推荐答案

Type.IsClass 可能有助于在这里。 。此外 Type.IsInterface

Type.IsClass might help here. Also Type.IsInterface.

看看...
http://msdn.microsoft.com/en-us/library/system.type%5Fmembers.aspx

有上键入不少IsXxxx属性。希望这些会做你想做的。

There are quite a few "IsXxxx" properties on Type. Hopefully these will do what you want.

顺便说一句,你应该检查出对SO这个问题的其他问题,包括这一个...

By the way, you should check out other questions on this subject on SO, including this one...

http://stackoverflow.com/questions/1661913/typeofsystem-枚举isclass假

...如果你要来检查类型是枚举类型,因为有一些奇怪的(但可预见的)结果。

... if the types you're going to be checking are enum types, as there are some strange (but predictable) results.

这篇关于获取的&QUOT类型;类型"在C#中反思的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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