Export (0) Print
Expand All

WebPartTransformerAttribute.WebPartTransformerAttribute Constructor

Initializes a new instance of the WebPartTransformerAttribute class.

Namespace: System.Web.UI.WebControls.WebParts
Assembly: System.Web (in system.web.dll)

public WebPartTransformerAttribute (
	Type consumerType,
	Type providerType
)
public WebPartTransformerAttribute (
	Type consumerType, 
	Type providerType
)
public function WebPartTransformerAttribute (
	consumerType : Type, 
	providerType : Type
)
Not applicable.

Parameters

consumerType

The Type of the interface supported by the consumer connection point.

providerType

The Type of the interface supported by the provider connection point.

Exception typeCondition

ArgumentNullException

consumerType or providerType is not specified.

InvalidOperationException

consumerType equals providerType.

The WebPartTransformerAttribute constructor sets the consumer connection point type and the provider connection point type for the transformer. These values can be retrieved through the ConsumerType property and the ProviderType property, respectively.

The following code example demonstrates the use of a WebPartTransformerAttribute attribute with a customized WebPartTransformer class. The attribute indicates that the RowToStringTransformer class can transform a provider connection point of type IWebPartRow to a consumer connection point of type IString.

This code example is part of a larger example found in the WebPartTransformer class overview.

// 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);
        }
    }
}

Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0

Community Additions

ADD
Show:
© 2014 Microsoft