找出如果一个属性声明为虚 [英] Find out if a property is declared virtual

查看:118
本文介绍了找出如果一个属性声明为虚的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对不起,我找了的System.Type 键入和的PropertyInfo 键入文档中,但我可以'T似乎找到我所需要的东西。

Sorry, I am looking up the System.Type type and the PropertyInfo type in the documentation but I can't seem to find the thing I need.

我如何判断一个属性(或方法或任何其他成员)被宣布虚拟在其声明类?

How do I tell if a property (or method or any other member) was declared virtual in its declaring class?

有关如

class Cat
{
    public string Name { get; set; }
    public virtual int Age { get; set; }
}



我如何告诉如果年龄财产申报虚拟或不?

推荐答案

您可以使用 IsVirtual 属性:

var isVirtual = typeof(Cat).GetProperty("Age").GetGetMethod().IsVirtual;

这篇关于找出如果一个属性声明为虚的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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