WebPartTransformerAttribute(Type, Type) 생성자

정의

WebPartTransformerAttribute 클래스의 새 인스턴스를 초기화합니다.

public:
 WebPartTransformerAttribute(Type ^ consumerType, Type ^ providerType);
public WebPartTransformerAttribute(Type consumerType, Type providerType);
new System.Web.UI.WebControls.WebParts.WebPartTransformerAttribute : Type * Type -> System.Web.UI.WebControls.WebParts.WebPartTransformerAttribute
Public Sub New (consumerType As Type, providerType As Type)

매개 변수

consumerType
Type

Type 소비자 연결 지점에서 지원하는 인터페이스입니다.

providerType
Type

Type 공급자 연결 지점에서 지원하는 인터페이스입니다.

예외

consumerType 또는 providerType 지정되지 않았습니다.

consumerType같음 .providerType

예제

다음 코드 예제에서는 사용자 지정된 WebPartTransformerAttribute 클래스에서 WebPartTransformer 특성을 사용하는 방법을 보여 줍니다. 이 특성은 클래스가 RowToStringTransformer 형식의 공급자 연결 지점을 형식 IWebPartRow 의 소비자 연결 지점 IString으로 변환할 수 있음을 나타냅니다.

이 코드 예제는 클래스 개요에 있는 더 큰 예제의 WebPartTransformer 일부입니다.

// A transformer that transforms a row to a string.
[AspNetHostingPermission(SecurityAction.Demand,
  Level = AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermission(SecurityAction.InheritanceDemand,
  Level = AspNetHostingPermissionLevel.Minimal)]
[WebPartTransformer(typeof(IWebPartRow), typeof(IString))]
public class RowToStringTransformer : WebPartTransformer, IString
{

    private IWebPartRow _provider;
    private StringCallback _callback;

    private void GetRowData(object rowData)
    {
        PropertyDescriptorCollection props = _provider.Schema;
        if (props != null && props.Count > 0 && rowData != null)
        {
            string returnValue = String.Empty;
            foreach (PropertyDescriptor prop in props)
            {
                if (prop != props[0])
                {
                    returnValue += ", ";
                }
                returnValue += prop.DisplayName + ": " + prop.GetValue(rowData);
            }
            _callback(returnValue);
        }
        else
        {
            _callback(null);
        }
    }
    
    public override object Transform(object providerData)
    {
        _provider = (IWebPartRow)providerData;
        return this;
    }

    void IString.GetStringValue(StringCallback callback)
    {
        if (callback == null)
        {
            throw new ArgumentNullException("callback");
        }

        if (_provider != null)
        {
            _callback = callback;
            _provider.GetRowData(new RowCallback(GetRowData));
        }
        else
        {
            callback(null);
        }
    }
}
' A transformer that transforms a row to a string.
<AspNetHostingPermission(SecurityAction.Demand, _
   Level:=AspNetHostingPermissionLevel.Minimal)> _
<AspNetHostingPermission(SecurityAction.InheritanceDemand, _
   Level:=AspNetHostingPermissionLevel.Minimal)> _
<WebPartTransformer(GetType(IWebPartRow), GetType(IString))> _
Public Class RowToStringTransformer
    Inherits WebPartTransformer
    Implements IString

    Private _provider As IWebPartRow
    Private _callback As StringCallback

    Private Sub GetRowData(ByVal rowData As Object)
        Dim props As PropertyDescriptorCollection = _provider.Schema

        If ((Not (props Is Nothing)) AndAlso (props.Count > 0) _
          AndAlso (Not (rowData Is Nothing))) Then
            Dim returnValue As String = String.Empty
            For Each prop As PropertyDescriptor In props
                If Not (prop Is props(0)) Then
                    returnValue += ", "
                End If
                returnValue += prop.DisplayName.ToString() + ": " + _
                    prop.GetValue(rowData).ToString()
            Next
            _callback(returnValue)
        Else
            _callback(Nothing)
        End If
    End Sub

    Public Overrides Function Transform(ByVal providerData As Object) As Object
        _provider = CType(providerData, IWebPartRow)
        Return Me
    End Function


    Sub GetStringValue(ByVal callback As StringCallback) _
       Implements IString.GetStringValue
        If (callback Is Nothing) Then
            Throw New ArgumentNullException("callback")
        End If

        If (Not (_provider Is Nothing)) Then
            _callback = callback
            _provider.GetRowData(New RowCallback(AddressOf GetRowData))
        Else
            callback(Nothing)
        End If
    End Sub
End Class

설명

WebPartTransformerAttribute 생성자는 변환기에 대한 소비자 연결 지점 유형 및 공급자 연결 지점 형식을 설정합니다. 이러한 값은 각각 속성과 ConsumerType 속성을 통해 ProviderType 검색할 수 있습니다.

적용 대상