다음을 통해 공유


Extender 공급자 개체

extender 공급자는 다른 구성 요소에 속성을 제공하는 구성 요소입니다.예를 들어, ToolTip 구성 요소가 폼에 추가되면 extender 공급자는 해당 폼의 각 컨트롤에 ToolTip이라는 속성을 제공합니다.그러면 각 컨트롤의 속성 창에 ToolTip 속성이 나타나므로 개발자가 디자인 타임에 이 속성의 값을 설정할 수 있습니다.

extender 공급자가 제공하는 속성은 실제로 extender 공급자 개체 자체에 있으므로 수정되는 구성 요소의 실제 속성이 아닙니다.디자인 타임에 수정되고 있는 구성 요소의 속성 창에 이 속성이 나타납니다.그러나 런타임에는 구성 요소 자체를 통해 속성에 액세스할 수 없습니다.다음 코드 예제에서는 MyButton이라는 단추와 ToolTip 속성을 제공하는 MyToolTip이라는 ToolTip 컨트롤이 있는 폼을 만듭니다.

' This is an example of code that is NOT CORRECT!
Dim myString as String
myString = MyButton.ToolTip
// This is an example of code that is NOT CORRECT!
string myString;
myString = MyButton.ToolTip;

이 구문은 컴파일러가 ToolTip을 MyButton의 속성으로 인식하지 않기 때문에 컴파일 오류를 발생시킵니다. 그 이유는 이 속성이 실제로는 MyToolTip에서 제공되기 때문입니다.다음 예제에서는 이 속성에 올바로 액세스하는 방법을 보여 줍니다.

Dim myString as String
myString = MyToolTip.GetToolTip(MyButton)
string myString;
myString = MyToolTip.GetToolTip(MyButton);

extender 공급자는 클래스이므로 자신의 속성과 메서드를 가질 수 있습니다.다른 구성 요소에 제공되는 속성으로 지정하려면 클래스 수준에서 ProvidePropertyAttribute 특성을 적용해야 합니다.이 특성은 제공할 속성의 이름과 해당 속성을 제공할 수 있는 개체의 형식을 지정합니다.관례적으로, 제공되는 속성은 속성으로 구현되지 않고 한 쌍의 메서드로 구현됩니다.이 메서드는 제공되는 속성의 이름 시작 부분에 "Get" 및 "Set"이 추가되어 있어야 합니다.다음 예제에서는 이러한 방법을 보여 줍니다.

Imports System.ComponentModel
<ProvideProperty("MyText", GetType(Control))> Public Class MyExtender
   <ExtenderProvidedProperty()> Public Function GetMyText(acontrol as _
      Control) as String
      ' Insert code to implement function.
   End Function
   Public Sub SetMytext (acontrol as Control)
      ' Insert code to implement function.
   End Function
End Class
using System.ComponentModel;
[ProvideProperty("MyText", typeof("Control"))]
public class MyExtender
{
[ExtenderProvidedProperty()]
   public string GetMyText(Control acontrol)
   {
      // Insert code to implement method.
   }
   public void SetMyText(Control acontrol)
   {
      // Insert code to implement method.
   }
}

제공되는 속성을 구현하려면 Hashtable 또는 각 컨트롤의 속성 값을 기록하고 검색하기 위한 기타 컬렉션 개체가 필요합니다.자세한 내용은 방법: Extender 공급자 구현을 참조하십시오.

또한 모든 extender 클래스는 IExtenderProvider 인터페이스를 구현해야 합니다.이 인터페이스는 부울 값을 반환하고 디자이너에게 구성 요소가 확장 대상인지 여부를 알려 주는 CanExtend라는 단일 메서드로 구성되어 있습니다.예를 들어, 컨트롤에만 속성을 제공하는 extender를 만들 수 있습니다.다음 예제에서는 CanExtend 메서드를 구현하는 방법을 보여 줍니다.

Imports System.ComponentModel
Public Function CanExtend(ByVal extendee As Object) As Boolean _
   Implements IExtenderProvider.CanExtend
   If Typeof extendee Is Control Then
      Return True
   Else
      Return False
   End If
End Function
public bool CanExtend(object extendee) 
{
   if (extendee is Control)
      return true;
   else
      return false;
}

참고 항목

작업

방법: Extender 공급자 구현

방법: HelpLabel Extender 공급자 구현

참조

IExtenderProvider

ProvidePropertyAttribute

기타 리소스

Extender 공급자