public abstract IsDefined ( Type attributeType, bool inherit ) : bool | ||
attributeType | Type | |
inherit | bool | |
return | bool |
using System; using System.Reflection; class MyClass { [Obsolete("This method is obsolete. Use CalculateNew instead.")] public int Calculate(int a, int b) { return a + b; } } class Program { static void Main() { MyClass obj = new MyClass(); MethodInfo method = obj.GetType().GetMethod("Calculate"); if(method.IsDefined(typeof(ObsoleteAttribute), true)) { Console.WriteLine("The method is obsolete."); } } }
using System; using System.Reflection; [Serializable] class MyClass { public int number; public string name; } class Program { static void Main() { Type type = typeof(MyClass); if(type.IsDefined(typeof(SerializableAttribute), true)) { Console.WriteLine("The class is serializable."); } } }These examples are part of the .NET framework and are included in the System.Reflection namespace.
public abstract IsDefined ( Type attributeType, bool inherit ) : bool | ||
attributeType | Type | |
inherit | bool | |
return | bool |