WebPartTransformerAttribute クラス

定義

トランスフォーマーがサポートする接続ポイントの種類を識別します。

public ref class WebPartTransformerAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.Class)]
public sealed class WebPartTransformerAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Class)>]
type WebPartTransformerAttribute = class
    inherit Attribute
Public NotInheritable Class WebPartTransformerAttribute
Inherits Attribute
継承
WebPartTransformerAttribute
属性

次のコード例は、カスタマイズされた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

注釈

トランスフォーマーは、互換性のない接続ポイントを持つ 2 つの Web パーツ コントロール間でデータを変換するために使用されます。 接続ポイントは、異なるインターフェイスを介してデータを提供または使用する場合、互換性がありません。 たとえば、 IWebPartRow 型のプロバイダー接続ポイントを実装しているプロバイダーは、 IWebPartTable型のプロバイダー接続ポイントを必要としているコンシューマーに直接接続できませんでした。 代わりに、トランスフォーマーを使用して 2 つの接続ポイントを接続する必要があります。 カスタマイズされたトランスフォーマーは、 WebPartTransformer クラスからクラスを派生させることによって作成できます。

WebPartTransformerAttribute属性は、WebPartTransformer クラスに適用されます。 プロバイダー接続ポイントの種類と、トランスフォーマーがサポートするコンシューマー接続ポイントの種類を定義します。 トランスフォーマーでサポートされるコンシューマーとプロバイダーの接続ポイントの種類は、コントロール間の接続を確立するために、コンシューマーおよびプロバイダー Web パーツ コントロールの接続ポイントと一致する必要があります。 実行時に、特定のトランスフォーマーがサポートする接続ポイントの種類は、 GetConsumerType メソッドと GetProviderType メソッドを使用して取得できます。

コンストラクター

名前 説明
WebPartTransformerAttribute(Type, Type)

WebPartTransformerAttribute クラスの新しいインスタンスを初期化します。

プロパティ

名前 説明
ConsumerType

コンシューマー接続ポイントでサポートされているインターフェイスの Type を取得します。

ProviderType

プロバイダー接続ポイントでサポートされているインターフェイスの Type を取得します。

TypeId

派生クラスで実装されている場合は、この Attributeの一意の識別子を取得します。

(継承元 Attribute)

メソッド

名前 説明
Equals(Object)

このインスタンスが指定したオブジェクトと等しいかどうかを示す値を返します。

(継承元 Attribute)
GetConsumerType(Type)

トランスフォーマーが接続ポイントで受け入れ可能なコンシューマーの種類を返します。

GetHashCode()

このインスタンスのハッシュ コードを返します。

(継承元 Attribute)
GetProviderType(Type)

トランスフォーマーが接続ポイントで受け入れ可能なプロバイダーの種類を返します。

GetType()

現在のインスタンスの Type を取得します。

(継承元 Object)
IsDefaultAttribute()

派生クラスでオーバーライドされた場合、このインスタンスの値が派生クラスの既定値であるかどうかを示します。

(継承元 Attribute)
Match(Object)

派生クラスでオーバーライドされた場合、このインスタンスが指定したオブジェクトと等しいかどうかを示す値を返します。

(継承元 Attribute)
MemberwiseClone()

現在の Objectの簡易コピーを作成します。

(継承元 Object)
ToString()

現在のオブジェクトを表す文字列を返します。

(継承元 Object)

明示的なインターフェイスの実装

名前 説明
_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

一連の名前を対応する一連のディスパッチ識別子に割り当てます。

(継承元 Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

インターフェイスの型情報を取得するために使用できるオブジェクトの型情報を取得します。

(継承元 Attribute)
_Attribute.GetTypeInfoCount(UInt32)

オブジェクトが提供する型情報インターフェイスの数 (0 または 1) を取得します。

(継承元 Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

オブジェクトによって公開されるプロパティとメソッドへのアクセスを提供します。

(継承元 Attribute)

適用対象