获取基类类型 [英] Getting the base class type

查看:78
本文介绍了获取基类类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




假设我有一个名为A的类继承自B,它继承自C.



GetType(A).BaseType返回GetType(C);我可以将A转换为C来获得C.



如何判断A是否使用其类型从B继承?我需要使用B的方法。



- Rix



我的尝试:



几个小时尝试各种基于继承的东西

解决方案

如果你的意思是动态的 - 即在运行时而不是设计/编译时 - 然后使用 Type.BaseType属性(系统) [ ^ ]

如果您的意思是设计或编译时间,那么Intellisense会告诉您哪些方法可用,那么问题是什么?

Hi
Let's say I have a class called A which inherits from B, which inherits from C.

GetType(A).BaseType returns GetType(C); I could cast A to C to get C.

How can I figure out whether A inherits from B using its type? I need to use B's methods.

- Rix

What I have tried:

A few hours of trying various inheritance-based things

解决方案

If you mean dynamically - i.e. at runtime rather than design/compile time - then use the Type.BaseType Property (System)[^]
If you mean at design or compile time, then Intellisense will tell you what methods are available, so what is the problem?


这篇关于获取基类类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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