|
Este artículo proviene de un motor de traducción automática. Mueva el puntero sobre las frases del artículo para ver el texto original. Más información.
|
Traducción
Original
|
Attribute.IsDefined (Método) (MemberInfo, Type, Boolean)
Espacio de nombres: System
Ensamblado: mscorlib (en mscorlib.dll)
Parámetros
- element
- Tipo: System.Reflection.MemberInfo
Objeto derivado de la clase MemberInfo que describe un constructor, evento, campo, método, tipo o miembro de propiedad de una clase.
- attributeType
- Tipo: System.Type
Tipo, o tipo base, del atributo personalizado que se va a buscar.
- inherit
- Tipo: System.Boolean
Si es true, especifica que se busquen también los atributos personalizados de los antecesores de element.
Valor devuelto
Tipo: System.Boolean| Excepción | Condición |
|---|---|
| ArgumentNullException | |
| ArgumentException | |
| NotSupportedException |
Nota |
|---|
using System; using System.Reflection; namespace IsDef4CS { public class TestClass { // Assign the Obsolete attribute to a method. [Obsolete("This method is obsolete. Use Method2 instead.")] public void Method1() {} public void Method2() {} } public class DemoClass { static void Main(string[] args) { // Get the class type to access its metadata. Type clsType = typeof(TestClass); // Get the MethodInfo object for Method1. MethodInfo mInfo = clsType.GetMethod("Method1"); // See if the Obsolete attribute is defined for this method. bool isDef = Attribute.IsDefined(mInfo, typeof(ObsoleteAttribute)); // Display the result. Console.WriteLine("The Obsolete Attribute {0} defined for {1} of class {2}.", isDef ? "is" : "is not", mInfo.Name, clsType.Name); // If it's defined, display the attribute's message. if (isDef) { ObsoleteAttribute obsAttr = (ObsoleteAttribute)Attribute.GetCustomAttribute( mInfo, typeof(ObsoleteAttribute)); if (obsAttr != null) Console.WriteLine("The message is: \"{0}\".", obsAttr.Message); else Console.WriteLine("The message could not be retrieved."); } } } } /* * Output: * The Obsolete Attribute is defined for Method1 of class TestClass. * The message is: "This method is obsolete. Use Method2 instead.". */
Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (no se admite el rol Server Core), Windows Server 2008 R2 (se admite el rol Server Core con SP1 o versiones posteriores; no se admite Itanium)
.NET Framework no admite todas las versiones de todas las plataformas. Para obtener una lista de las versiones compatibles, vea Requisitos de sistema de .NET Framework.
Nota