c#中不推荐使用的属性 [英] Deprecated Properties in c#

查看:214
本文介绍了c#中不推荐使用的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我想知道这是否可行,因为我还没有看到这些内容。



是否可以在属性网格中仅显示已弃用的属性。



类似的说明也可以用非可浏览的属性。



我看不到这种查询方式或只用这些项目专门填充网格。



在此先感谢George

Hi All,

I am wondering if this is possible as i have not yet seen anything along these lines.

Would it be possible to be able to display only deprecated properties in a property grid.

On a similar note could this also be done with non browsable attributes.

I cannot see a way of querying this or specifically populating the grid with only these items.

Thanks in advance George

推荐答案

IFAIK,no - 折旧属性在类定义中不会更改 - 它们仅通过文档折旧。



但是有 ObsoleteAttribute属性 [ ^ ]你可以通过Reflection拿起并显示你的身份F。但是,这确实依赖于我的MS改变的类型包括属性 - 这是无法保证的。显然,您需要使用框架的最新版本来检查房产是否已过时!





嗨OriginalGriff,



多亏了这个,我查看了文档,它是一个有用的资源,用于显示.Net目前已弃用的属性dll等。



我一直在尝试使用反射来查询过时的属性,但还没有发现这样做的方法,并且在资源中看不到任何可能导致我这样做的事情= s。



我想我的原始目标可能看似奇怪但理想情况下我想在单独的属性网格中显示折旧,普通和不可浏览的属性。这是为了允许测试所有属性。






我刚试了一下,而且非常简单:

IFAIK, no - depreciated properties aren't changed in the class definition - they are depreciated via the documentation only.

There is however the ObsoleteAttribute Attribute[^] which you could pick up on via Reflection and display yourself. However, this does rely on the type being changed my MS to include the attribute - and that can't be guaranteed. Obviously, you need to use the "latest" version of the framework in order to check if a property is obsolete!


"Hi OriginalGriff,

Thanks for this, i have looked though the documentation and it is a useful resource for showing the currently deprecated properties dlls etc in .Net.

I have been trying to query the obsolete attribute using reflection but have not yet discovered a method of doing so and could not see anything which may lead me to this within the resource =s.

I suppose my original goal may seem odd but ideally i want to display depreciated,normal and non browsable properties in separate property grids. This is to allow testing of all attributes.



I just tried it quickly, and it's pretty simple:
Type t = typeof(MyClass);
foreach (System.Reflection.PropertyInfo p in t.GetProperties())
    {
    var x = p.GetCustomAttributes(false).ToDictionary(a => a.GetType().Name, a => a);
    Console.WriteLine(p.Name);
    foreach (string k in x.Keys)
        {
        Console.WriteLine("   " + x[k]);
        if (x[k] is ObsoleteAttribute)
            {
            Console.WriteLine("   ****");
            }
        }
    }


这篇关于c#中不推荐使用的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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