Click here to Skip to main content
15,885,782 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted
Comments
BillWoodruff 2-Dec-13 5:14am    
That's an interesting idea, but, I wonder how these Properties are now a problem for you, and why you wish to display them ? Perhaps for analyzing code before migrating it to later versions of the FrameWork ?

Is it not enough they show up in IntelliSense as struck-out Text, and, if you type one, you get a special pop-up telling you it's obsolete complete with a link ?

It is interesting that you can compile without error using one: if I type this.AutoScale = true; in WinForm code, using FrameWork 4.5, there's no compiler error even though AutoScale is, indeed, obsolete.

gwithey 2-Dec-13 6:30am    
I wish to display them for regression testing of these properties to display any that are currently deprecated or non brawsable within a property grid.

1 solution

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:
C#
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("   ****");
            }
        }
    }
 
Share this answer
 
v2
Comments
gwithey 2-Dec-13 6:28am    
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.
OriginalGriff 2-Dec-13 6:55am    
Answer updated
gwithey 2-Dec-13 8:14am    
Thanks for the help with this, it allows me to at least determine which ones are obsolete and indicate this within the UI.

I still don't know if these could be linked to and display a property grid that relates to a control instance opposed to its type. However will see what i can do.

Thanks George

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900