获取的"类型;类型"在C#中反思 [英] Getting the type of a "Type" in C# reflection
问题描述
这是更难的文档找到比我想象的。无论如何,我有键入
某些情况下。我如何才能找到他们是否代表了类,方法,接口等?
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.
这篇关于获取的"类型;类型"在C#中反思的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!