Classe AttributeTable

Uma tabela de atributos de metadados para definir o comportamento e a aparência de tempo de design.

Hierarquia de herança

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

Namespace:  Microsoft.Windows.Design.Metadata
Assembly:  Microsoft.Windows.Design.Extensibility (em Microsoft.Windows.Design.Extensibility.dll)

Sintaxe

'Declaração
Public NotInheritable Class AttributeTable
public sealed class AttributeTable
public ref class AttributeTable sealed
[<Sealed>]
type AttributeTable =  class end
public final class AttributeTable

O tipo AttributeTable expõe os membros a seguir.

Propriedades

  Nome Descrição
Propriedade pública AttributedTypes Obtém uma enumeração de todos os tipos que têm as substituições de atributo de algum tipo, por exemplo, em uma propriedade ou o próprio tipo.

Início

Métodos

  Nome Descrição
Método público ContainsAttributes Retorna um valor que indica se esta tabela contém todos os metadados para o tipo especificado.
Método público Equals Determina se o especificado Object é igual a atual Object. (Herdado de Object.)
Método protegido Finalize Permite que um objeto tentar liberar recursos e executar outras operações de limpeza antes que ele é recuperado pela coleta de lixo. (Herdado de Object.)
Método público GetCustomAttributes(Assembly) Retorna uma enumeração de todos os atributos fornecidos para o assembly especificado.
Método público GetCustomAttributes(Type) Retorna uma enumeração de todos os atributos fornecidos para o tipo especificado.
Método público GetCustomAttributes(Type, String) Retorna uma enumeração de todos os atributos fornecidos para o tipo especificado e o nome do membro.
Método público GetHashCode Serves as a hash function for a particular type. (Herdado de Object.)
Método público GetType Obtém o Type da instância atual. (Herdado de Object.)
Método protegido MemberwiseClone Cria uma cópia superficial do atual Object. (Herdado de Object.)
Método público ToString Retorna um string que representa o objeto atual. (Herdado de Object.)

Início

Comentários

Use o AttributeTable classe para associar os atributos de metadados de tempo de design com todos os tipos de Windows Presentation Foundation (WPF).

Para criar uma tabela de atributos, chame o CreateTable método de AttributeTableBuilder classe. For more information, see Fornecimento de metadados de tempo de design.

Uma tabela de atributos é essencialmente um dicionário de somente leitura, mas suas chaves e valores são calculados separadamente. É eficiente para consultar uma tabela de atributos se ele contiver atributos para um determinado tipo. O conjunto real de atributos é criada de demanda.

Exemplos

O exemplo de código a seguir mostra como criar e preencher uma tabela de atributos. For more information, see Walkthrough: Criando um adorno em tempo de 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;
            }
        }
    }
}

Acesso thread-safe

Quaisquer membros static (Shared no Visual Basic) públicos deste tipo são thread-safe. Não há garantia de que qualquer membro de instância seja thread-safe.

Consulte também

Referência

Namespace Microsoft.Windows.Design.Metadata

AttributeTableBuilder

Outros recursos

Fornecimento de metadados de tempo de design