using System; using System.Reflection; class MyClass { [Obsolete("This property is no longer supported")] public int MyProperty { get; set; } } class Program { static void Main() { PropertyInfo myProperty = typeof(MyClass).GetProperty("MyProperty"); bool isObsoleteDefined = myProperty.IsDefined(typeof(ObsoleteAttribute), false); Console.WriteLine($"Is Obsolete defined for 'MyProperty'? {isObsoleteDefined}"); } }
Is Obsolete defined for 'MyProperty'? True
using System; using System.ComponentModel; using System.Reflection; class MyClass { [Browsable(false)] public int MyProperty { get; set; } } class Program { static void Main() { PropertyInfo myProperty = typeof(MyClass).GetProperty("MyProperty"); bool isBrowsableDefined = myProperty.IsDefined(typeof(BrowsableAttribute), false); Console.WriteLine($"Is Browsable defined for 'MyProperty'? {isBrowsableDefined}"); } }
Is Browsable defined for 'MyProperty'? TrueLibrary: The IsDefined method is part of the System.Reflection library.