Share via


메타데이터 필터링

메타데이터 필터링을 통해 디자이너는 디자인 타임에 구성 요소 또는 컨트롤에 의해 노출되는 속성, 특성 및 이벤트 집합을 수정할 수 있습니다.

예를 들어 Control에는 해당 컨트롤의 표시 여부를 결정하는 Visible 속성이 있습니다. 그러나, 개발자가 디자인 화면에 컨트롤을 놓을 수 있도록 컨트롤은 이 속성의 값에 관계없이 디자인 타임에 항상 표시되어야 합니다. Control 디자이너는 디자인 타임에 Visible 속성을 고유한 특정 속성으로 바꾸고 나중에 이 속성의 런타임 값을 복원할 수 있습니다.

메타데이터 필터링을 수행하려면 디자이너는 IDesignerFilter 인터페이스를 구현하거나, 디자인 타임 환경의 모든 구성 요소에 대해 메타데이터 필터링을 수행할 수 있는 디자인 타임 서비스 공급자에 ITypeDescriptorFilterService 구현을 추가해야 합니다.

디자인 타임에 구성 요소를 선택하면 속성 브라우저에서 TypeDescriptor의 메서드를 통해 해당 구성 요소의 특성, 이벤트 및 속성을 쿼리합니다. 디자인 모드로 구성 요소의 특정, 이벤트 및 속성을 쿼리할 때 IDesignerFilter 인터페이스를 구현하는 구성 요소에 대한 모든 디자이너에서 해당 구성 요소가 반환하는 특성, 이벤트 및 속성 집합을 수정할 수 있습니다. 그런 다음 서비스에서 특성, 이벤트 및 속성 필터링을 수행할 수 있도록 모든 활성 ITypeDescriptorFilterService의 메서드가 호출됩니다.

구성 요소에 대해 TypeDescriptorRefresh 메서드가 호출되는 경우, 속성 창을 새로 고치는 경우, 디자인 모드가 설정 또는 다시 설정되는 경우, 기본 선택 내용이 설정되는 경우 일반적으로 디자인 모드에서 해당 구성 요소의 특성, 이벤트 및 속성을 쿼리합니다. 다른 경우에는 디자인 타임 환경 또는 다른 개체의 메서드가 TypeDescriptor의 메서드를 호출할 수 있습니다.

구성 요소 메타데이터 필터링에 대한 IDesignerFilter 인터페이스

IDesignerFilter 인터페이스는 메서드 집합을 정의합니다. 이런 메서드는 디자인 타임에 디자이너에서 관리하는 구성 요소에 의해 노출되는 속성, 이벤트 또는 특성을 변경하기 위해 디자이너에서 재정의 및 구현할 수 있습니다.

IDesignerFilter 인터페이스의 각 메서드에는 "Pre" 또는 "Post"라는 접두사가 붙습니다. 각 메서드의 접미사로는 추가, 변경 또는 제거할 수 있는 멤버 형식에 따라 "Attributes", "Events" 또는 "Properties"가 붙습니다. 특성, 이벤트 또는 속성을 추가하려면 이름이 "Pre"로 시작되는 관련 메서드를 사용합니다. 특성, 이벤트 또는 속성을 변경하거나 제거하려면 이름이 "Post"로 시작되는 관련 메서드를 사용합니다. 이름이 "Pre"로 시작되는 메서드는 이름이 "Post"로 시작되는 메서드 바로 앞에서 호출됩니다.

하나 이상의 특성을 추가하려면 메서드에 전달되는 IDictionary에 새 System.Attribute를 추가하는 PreFilterAttributes 메서드를 재정의합니다. 사전의 키는 특성의 형식 ID입니다. 하나 이상의 특성을 변경하거나 제거하려면 PostFilterAttributes 메서드를 재정의합니다.

하나 이상의 이벤트를 추가하려면 메서드에 전달되는 IDictionary에 새 EventDescriptor를 추가하는 PreFilterEvents 메서드를 재정의합니다. 사전의 키는 이벤트의 이름입니다. 하나 이상의 이벤트를 변경하거나 제거하려면 PostFilterEvents 메서드를 재정의합니다.

하나 이상의 속성을 추가하려면 메서드에 전달되는 IDictionary에 새 PropertyDescriptor를 추가하는 PreFilterProperties 메서드를 재정의합니다. 사전의 키는 속성의 이름입니다. 하나 이상의 속성을 변경하거나 제거하려면 PostFilterProperties 메서드를 재정의합니다.

참고

클래스에서 IDesignerFilter를 구현하는 디자이너를 확장하는 경우, 각 PostMethodName 메서드는 자체의 고유 특성을 변경한 후 기본 클래스의 해당 PostMethodName 메서드를 호출해야 하고 각 PreMethodName 메서드는 자체의 고유 특성을 변경하기 전에 기본 클래스의 해당 PreMethodName 메서드를 호출해야 합니다.

다음 코드 예제 블록에서는 IDesignerFilter 인터페이스의 메서드 시그니처를 보여 줍니다.

Public Interface IDesignerFilter
   Sub PostFilterAttributes(attributes As IDictionary)
   Sub PostFilterEvents(events As IDictionary)
   Sub PostFilterProperties(properties As IDictionary)
   Sub PreFilterAttributes(attributes As IDictionary)
   Sub PreFilterEvents(events As IDictionary)
   Sub PreFilterProperties(properties As IDictionary)
End Interface
public interface IDesignerFilter {
    void PostFilterAttributes(IDictionary attributes);
    void PostFilterEvents(IDictionary events);
    void PostFilterProperties(IDictionary properties);
    void PreFilterAttributes(IDictionary attributes);
    void PreFilterEvents(IDictionary events);
    void PreFilterProperties(IDictionary properties);
}

다음 코드 예제에서는 연결된 구성 요소에 디자이너의 Color 속성을 추가하는 IDesignerFilter 구현 방법을 보여 줍니다. System.Design.dll에 대한 참조를 추가해야 합니다.

Imports System
Imports System.ComponentModel
Imports System.ComponentModel.Design
Imports System.Drawing
Imports System.Windows.Forms
Imports System.Windows.Forms.Design

Namespace IDesignerFilterSample
 _
    Public Class DesignerFilterDesigner
        Inherits ComponentDesigner        

        ' Designer color property to add to component.
        Public Property TestColor() As Color
            Get
                Return Me.intcolor
            End Get
            Set(ByVal Value As Color)
                Me.intcolor = Value
            End Set
        End Property

        ' Color for TestColor property.
        Private intcolor As Color = Color.Azure

        Public Function DesignerFilterDesigner()
        End Function 'DesignerFilterDesigner

        ' Adds a color property of this designer to the component.
        Protected Overrides Sub PreFilterProperties(ByVal properties As System.Collections.IDictionary)
            MyBase.PreFilterProperties(properties)
            ' Adds a test property to the component.
            properties.Add("TestColor", TypeDescriptor.CreateProperty(GetType(DesignerFilterDesigner), "TestColor", GetType(System.Drawing.Color), Nothing))
        End Sub 'PreFilterProperties

    End Class 'DesignerFilterDesigner

    ' Component with which the DesignerFilterDesigner is associated.
    <Designer(GetType(DesignerFilterDesigner))>  _    
    Public Class TestComponent
        Inherits Component

        Public Function TestComponent()
        End Function 'TestComponent
    End Class 'TestComponent

End Namespace
using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Drawing;
using System.Windows.Forms;
using System.Windows.Forms.Design;

namespace IDesignerFilterSample
{
   public class DesignerFilterDesigner : ComponentDesigner, IDesignerFilter
   {
      // Designer color property to add to component.
      public Color TestColor
      {
         get
         { return this.intcolor;   }
         set
         { this.intcolor = value; }
      }

      // Color for TestColor property.
      private Color intcolor = Color.Azure;

      public DesignerFilterDesigner()
      {}

      // Adds a color property of this designer to the component.
      protected override void PreFilterProperties(System.Collections.IDictionary properties)
      {
         base.PreFilterProperties(properties);
         // Adds a test property to the component.
         properties.Add("TestColor", TypeDescriptor.CreateProperty(typeof(DesignerFilterDesigner), "TestColor", typeof(System.Drawing.Color), null));
      }
   }

   // Component with which the DesignerFilterDesigner is associated.
   [Designer(typeof(DesignerFilterDesigner))]
   public class TestComponent : Component
   {
      public TestComponent()
      {}
   }
}

IDesignerFilter 인터페이스를 사용하여 속성 필터링을 구현하는 Windows Forms 컨트롤 디자이너 예제를 보려면 Windows Forms 디자이너 샘플을 참조하십시오.

전역 디자인 모드 메타데이터 필터링에 대한 ITypeDescriptorFilterService

디자인 모드에 있는 ComponentSite 속성에 의해 반환된 ISite에 의해 구현된 IServiceContainer 인터페이스의 AddService 메서드를 사용하여 디자인 타임에 서비스를 제공하는 서비스 공급자에 ITypeDescriptorFilterService 구현을 추가하여 디자인 타임 프로젝트의 구성 요소에 메타데이터 필터링을 제공할 수 있습니다.

다음 코드 예제에서는 ExampleFilterService라는 ITypeDescriptorFilterService 서비스를 추가하는 방법을 보여 줍니다.

IDesignerHost dh = (IDesignerHost)this.Component.GetService(typeof(IDesignerHost));
if( dh != null )
{
   // First gets any previous ITypeDescriptorFilterService to replace when 
   // the current service is removed, and to call if the new service 
   // implements service chaining.
   ITypeDescriptorFilterService itdfs = 
   (ITypeDescriptorFilterService)dh.GetService(    typeof(ITypeDescriptorFilterService));
   
   oldService = (ITypeDescriptorFilterService)dh.GetService(
   typeof(ITypeDescriptorFilterService));
         
   if(oldService != null)
      // Removes any old ITypeDescriptorFilterService.
      dh.RemoveService(typeof(ITypeDescriptorFilterService));
         
   // Adds an ExampleFilterService that implements service chaining.
   dh.AddService(typeof(ITypeDescriptorFilterService), 
   new ExampleFilterService(oldService));
}

ITypeDescriptorFilterService 구현 예제를 보려면 ITypeDescriptorFilterService 클래스에 대한 참조 문서를 참조하십시오.

참고 항목

작업

방법: 디자인 모드에서 구성 요소의 특성, 이벤트 및 속성 조정

개념

기본 디자이너 클래스

디자이너 동사

방법: 컨트롤에 대한 디자이너 구현

형식 설명자 개요

기타 리소스

사용자 지정 디자이너