Share via


AttributeTableBuilder 類別

建立用於定義設計階段中繼資料的屬性表格。

繼承階層架構

System.Object
  Microsoft.Windows.Design.Metadata.AttributeTableBuilder

命名空間:  Microsoft.Windows.Design.Metadata
組件:  Microsoft.Windows.Design.Extensibility (在 Microsoft.Windows.Design.Extensibility.dll 中)

語法

'宣告
Public Class AttributeTableBuilder
public class AttributeTableBuilder
public ref class AttributeTableBuilder
type AttributeTableBuilder =  class end
public class AttributeTableBuilder

AttributeTableBuilder 型別會公開下列成員。

建構函式

  名稱 說明
公用方法 AttributeTableBuilder 初始化 AttributeTableBuilder 類別的新執行個體。

回頁首

方法

  名稱 說明
公用方法 AddCallback 會加入需要指定之型別的中繼資料時,所叫用的回呼。
公用方法 AddCustomAttributes(Assembly, array<Attribute[]) 將所提供屬性陣列的內容加入至表格產生器。
公用方法 AddCustomAttributes(Type, array<Attribute[]) 會將所提供屬性的內容加入至表格產生器。
公用方法 AddCustomAttributes(Type, String, array<Attribute[]) 會將屬性 (Attribute) 加入至具有指定名稱的成員。
公用方法 AddTable 會將所提供屬性表格的內容加入至表格產生器。
公用方法 CreateTable 會建立屬性表格,其中包含透過 AddCustomAttributes 呼叫所提供的全部屬性定義。
公用方法 Equals 判斷指定的 Object 和目前的 Object 是否相等。 (繼承自 Object)。
受保護的方法 Finalize 允許物件在記憶體回收進行回收之前,嘗試釋放資源並執行其他清除作業。 (繼承自 Object)。
公用方法 GetHashCode 做為特定型別的雜湊函式。 (繼承自 Object)。
公用方法 GetType 取得目前執行個體的 Type。 (繼承自 Object)。
受保護的方法 MemberwiseClone 建立目前 Object 的淺層複本 (Shallow Copy)。 (繼承自 Object)。
公用方法 ToString 傳回表示目前物件的字串。 (繼承自 Object)。
公用方法 ValidateTable 這個方法是用來確認所建立的屬性表格是否包含有效的屬性資訊。

回頁首

備註

若要建立屬性表格,必須從建立 AttributeTableBuilder 類別的執行個體開始。 接著再呼叫 AddCustomAttributes 多載,將中繼資料加入至屬性表格產生器 (Builder)。 完成加入中繼資料的動作後,您必須呼叫 CreateTable 方法,從屬性表格產生器提供屬性表格。 屬性表格產生器方法支援回呼委派,因此會延後建立屬性表格,直到有需求為止。

如果您要加入許多屬性,則可以使用 AttributeCallbackBuilder 類別 (而非 AttributeTableBuilder 類別)。 這個方式會延後建立屬性,直到設計工具要求目標型別的中繼資料為止。

範例

在下列程式碼範例中,會說明如何使用 AttributeTableBuilder 類別,建立屬性表格並填入內容。 如需詳細資訊,請參閱逐步解說:建立設計階段裝飾項

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.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 IRegisterMetadata. If found, designers instantiate 
' this class and call its Register() method 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()

            builder.AddCustomAttributes( _
                GetType(Button), _
                New DefaultPropertyAttribute("Content"))

            ' 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()

            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();

                builder.AddCustomAttributes(
                    typeof(Button),
                    new DefaultPropertyAttribute("Content"));

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

                AttributeTable attributes = builder.CreateTable();

                return attributes;
            }
        }
    }
}

執行緒安全

這個型別的任何 Public static (在 Visual Basic 中為 Shared) 成員都具備執行緒安全。並非所有的執行個體成員都是安全執行緒。

請參閱

參考

Microsoft.Windows.Design.Metadata 命名空間

AttributeTable

AttributeCallbackBuilder