我如何检测"新" MODIFER使用反射场? [英] How do I detect the "new" modifer on a field using reflection?

查看:112
本文介绍了我如何检测"新" MODIFER使用反射场?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

http://msdn.microsoft.com/en-us/library/ 435f1dw2.aspx

public class Base
{
    public string Field;
}
public class Child : Base
{
    public new string Field;
}

[TestFixture]
public class TestClass
{

    [Test]
    public void DetectNew()
    {
        var fieldInfo = typeof(Child).GetField("Field");
        //How do I tell fieldInfo has a new modifier?
        Debug.WriteLine(fieldInfo);
    }
}

编辑:我知道的方法和属性,我可以检查MethodBase.IsHideBySig。为什么犯规了类似的财产存在字段信息?

I know for Methods and Properties I can check "MethodBase.IsHideBySig". Why doesnt a similar property exist for FieldInfo?

推荐答案

只是一个猜测,但我认为你必须寻找基类(ES)为一个的成员的具有相同名字。

Just a guess, but I think you'd have to search the base-class(es) for a member with the same name.

您也可以看看生成的IL的两个领域,看看是否有是,你可以通过反射使用任何差异。

You could also take a look at the generated IL for both fields to see if there're any differences that you can use through reflection.

这篇关于我如何检测"新" MODIFER使用反射场?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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