Assembly.IsDefined(Type, Boolean) Assembly.IsDefined(Type, Boolean) Assembly.IsDefined(Type, Boolean) Assembly.IsDefined(Type, Boolean) Method

Definición

Indica si se ha aplicado un atributo especificado al ensamblado.Indicates whether or not a specified attribute has been applied to the assembly.

public:
 virtual bool IsDefined(Type ^ attributeType, bool inherit);
public virtual bool IsDefined (Type attributeType, bool inherit);
abstract member IsDefined : Type * bool -> bool
override this.IsDefined : Type * bool -> bool
Public Overridable Function IsDefined (attributeType As Type, inherit As Boolean) As Boolean

Parámetros

attributeType
Type Type Type Type

Tipo del atributo personalizado que se va a comprobar para este ensamblado.The type of the attribute to be checked for this assembly.

inherit
Boolean Boolean Boolean Boolean

Se omite este argumento para los objetos de este tipo.This argument is ignored for objects of this type.

Devoluciones

Es true si el atributo se ha aplicado al ensamblado; de lo contrario, es false.true if the attribute has been applied to the assembly; otherwise, false.

Implementaciones

Excepciones

attributeType usa un tipo no válido.attributeType uses an invalid type.

Ejemplos

El siguiente ejemplo de código se aplica el AssemblyTitleAttribute atributo a un ensamblado y, a continuación, usa IsDefined para indicar si se aplicó.The following code example applies the AssemblyTitleAttribute attribute to an assembly and then uses IsDefined to indicate whether it was applied. También comprueba un atributo que no se ha aplicado.It also tests an attribute that was not applied.

using System;
using System.Reflection;

// Set an assembly attribute.
[assembly:AssemblyTitleAttribute("A title example")]


// Note that the suffix "Attribute" can be omitted:
// [assembly:AssemblyTitle("A title example")]


public class Test {

    public static void Main() {

        // Get the assembly that is executing this method.
        Assembly asm = Assembly.GetCallingAssembly();

        // Get the attribute type just defined.
        Type aType = typeof(AssemblyTitleAttribute);
        Console.WriteLine(asm.IsDefined(aType, false));

        // Try an attribute not defined.
        aType = typeof(AssemblyVersionAttribute);
        Console.WriteLine(asm.IsDefined(aType, false));
    }
}
//
//  This code example produces the following output:
//  True
//  False
//

Imports System
Imports System.Reflection

' Set an assembly attribute.
<Assembly:AssemblyTitleAttribute("A title example")>

' Note that the suffix "Attribute" can be omitted:
' <Assembly:AssemblyTitle("A title examle")>

Public Class Test
    Public Shared Sub Main()

        ' Get the assembly that is executing this method.
        Dim asm As [Assembly] = [Assembly].GetCallingAssembly

        ' Get the attribute type just defined.
        Dim aType As Type = GetType(AssemblyTitleAttribute)

        Console.WriteLine(asm.IsDefined(aType, false))

        ' Try an attribute not defined.
        aType = GetType(AssemblyVersionAttribute)

        Console.WriteLine(asm.IsDefined(aType, false))

    End Sub
End Class

' This code example produces the following output:
' True
' False
'

Se aplica a