Assembly.IsDefined(Type, Boolean) Metódus

Definíció

Azt jelzi, hogy egy megadott attribútum lett-e alkalmazva a szerelvényre.

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

Paraméterek

attributeType
Type

A szerelvényhez ellenőrizni kívánt attribútum típusa.

inherit
Boolean

Ezt az argumentumot a rendszer figyelmen kívül hagyja az ilyen típusú objektumok esetében.

Válaszok

trueha az attribútumot alkalmazták a szerelvényre; egyéb esetben. false

Megvalósítás

Kivételek

attributeType az null.

attributeType érvénytelen típust használ.

Példák

Az alábbi példakód egy szerelvényre alkalmazza az AssemblyTitleAttribute attribútumot, majd IsDefined azt jelzi, hogy alkalmazták-e. Emellett egy nem alkalmazott attribútumot is tesztel.

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.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
'

A következőre érvényes: