AttributeTable, classe

Table d'attributs de métadonnées pour définir l'apparence et le comportement au moment du design.

Hiérarchie d'héritage

System.Object
  Microsoft.Windows.Design.Metadata.AttributeTable

Espace de noms :  Microsoft.Windows.Design.Metadata
Assembly :  Microsoft.Windows.Design.Extensibility (dans Microsoft.Windows.Design.Extensibility.dll)

Syntaxe

'Déclaration
Public NotInheritable Class AttributeTable
public sealed class AttributeTable
public ref class AttributeTable sealed
[<Sealed>]
type AttributeTable =  class end
public final class AttributeTable

Le type AttributeTable expose les membres suivants.

Propriétés

  Nom Description
Propriété publique AttributedTypes Obtient une énumération de tous les types comportant des substitutions d'attribut, quelles qu'elles soient, par exemple sur une propriété ou sur le type lui-même.

Début

Méthodes

  Nom Description
Méthode publique ContainsAttributes Retourne une valeur qui indique si cette table contient des métadonnées pour le type spécifié.
Méthode publique Equals Détermine si l'Object spécifié est égal à l'Object en cours. (Hérité de Object.)
Méthode protégée Finalize Autorise un objet à tenter de libérer des ressources et d'exécuter d'autres opérations de nettoyage avant qu'il ne soit récupéré par l'opération garbage collection. (Hérité de Object.)
Méthode publique GetCustomAttributes(Assembly) Retourne une énumération de tous les attributs fournis pour l'assembly spécifié.
Méthode publique GetCustomAttributes(Type) Retourne une énumération de tous les attributs fournis pour le type spécifié.
Méthode publique GetCustomAttributes(Type, String) Retourne une énumération de tous les attributs fournis pour le type et le nom de membre spécifiés.
Méthode publique GetHashCode Sert de fonction de hachage pour un type particulier. (Hérité de Object.)
Méthode publique GetType Obtient le Type de l'instance actuelle. (Hérité de Object.)
Méthode protégée MemberwiseClone Crée une copie superficielle de l'objet Object actif. (Hérité de Object.)
Méthode publique ToString Retourne une chaîne qui représente l'objet actuel. (Hérité de Object.)

Début

Notes

Utilisez la classe AttributeTable pour associer des attributs de métadonnées au moment du design aux types Windows Presentation Foundation (WPF).

Pour créer une table d'attributs, appelez la méthode CreateTable de la classe AttributeTableBuilder. Pour plus d'informations, consultez Mise à disposition de métadonnées au moment du design.

Une table d'attributs est essentiellement un dictionnaire en lecture seule, mais ses clés et valeurs sont calculées séparément. Il est plus efficace d'interroger une table d'attributs lorsqu'elle contient des attributs pour un type particulier. Le jeu réel d'attributs est créé à la demande.

Exemples

L'exemple de code suivant indique comment créer et remplir une table d'attributs. Pour plus d'informations, consultez Procédure pas à pas : création d'un ornement au moment du design.

Imports System
Imports System.Collections
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Reflection
Imports System.Text
Imports System.Windows.Media
Imports System.Windows.Controls
Imports System.Windows

Imports Microsoft.Windows.Design
Imports Microsoft.Windows.Design.Features
Imports Microsoft.Windows.Design.Metadata

' The ProvideMetadata assembly-level attribute indicates to designers
' that this assembly contains a class that provides an attribute table. 
<Assembly: ProvideMetadata(GetType(CustomControlLibrary.VisualStudio.Design.Metadata))> 

' Container for any general design-time metadata to initialize.
' Designers look for a type in the design-time assembly that 
' implements IProvideAttributeTable. If found, designers instantiate
' this class and access its AttributeTable property automatically.
Friend Class Metadata
    Implements IProvideAttributeTable

    ' Accessed by the designer to register any design-time metadata.
    Public ReadOnly Property AttributeTable() As AttributeTable _
        Implements IProvideAttributeTable.AttributeTable
        Get
            Dim builder As New AttributeTableBuilder()

            ' Apply the ReadOnlyAttribute to the Background property 
            ' of the Button class.
            builder.AddCustomAttributes(GetType(Button), "Background", New ReadOnlyAttribute(True))

            Dim attributes As AttributeTable = builder.CreateTable()

            Dim hasCustomAttributes As Boolean = attributes.ContainsAttributes(GetType(Button))

            Dim types As IEnumerable(Of Type) = attributes.AttributedTypes

            ' The following code shows how to retrieve custom attributes
            ' using the GetCustomAttributes method overloads.
            Dim attrs0 As IEnumerable = attributes.GetCustomAttributes(GetType(Button))

            Dim attrs1 As IEnumerable = attributes.GetCustomAttributes(GetType(Button), "Background")

            Return attributes
        End Get
    End Property
End Class
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Reflection;
using System.Text;
using System.Windows.Media;
using System.Windows.Controls;
using System.Windows;

using Microsoft.Windows.Design.Features;
using Microsoft.Windows.Design.Metadata;

// The ProvideMetadata assembly-level attribute indicates to designers
// that this assembly contains a class that provides an attribute table. 
[assembly: ProvideMetadata(typeof(CustomControlLibrary.VisualStudio.Design.Metadata))]
namespace CustomControlLibrary.VisualStudio.Design
{
    // Container for any general design-time metadata to initialize.
    // Designers look for a type in the design-time assembly that 
    // implements IProvideAttributeTable. If found, designers instantiate 
    // this class and access its AttributeTable property automatically.
    internal class Metadata : IProvideAttributeTable
    {
        // Accessed by the designer to register any design-time metadata.
        public AttributeTable AttributeTable
        {
            get
            {
                AttributeTableBuilder builder = new AttributeTableBuilder();

                // Apply the ReadOnlyAttribute to the Background property 
                // of the Button class.
                builder.AddCustomAttributes(
                    typeof(Button),
                    "Background",
                    new ReadOnlyAttribute(true));

                AttributeTable attributes = builder.CreateTable();

                bool hasCustomAttributes = attributes.ContainsAttributes(typeof(Button));

                IEnumerable<Type> types = attributes.AttributedTypes;

                // The following code shows how to retrieve custom attributes
                // using the GetCustomAttributes method overloads.
                IEnumerable attrs0 = attributes.GetCustomAttributes(typeof(Button));

                IEnumerable attrs1 = attributes.GetCustomAttributes(
                    typeof(Button),
                    "Background");

                return attributes;
            }
        }
    }
}

Sécurité des threads

Tous les membres static (Shared en Visual Basic) publics de ce type sont thread-safe. Il n'est pas garanti que les membres d'instance soient thread-safe.

Voir aussi

Référence

Microsoft.Windows.Design.Metadata, espace de noms

AttributeTableBuilder

Autres ressources

Mise à disposition de métadonnées au moment du design