WebPartTransformerAttribute 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
标识转换器支持的连接点的类型。
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类使用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
注解
转换器用于转换两个 Web 部件控件与不兼容的连接点之间的数据。 连接点通过不同的接口提供或使用数据时不兼容。 例如,实现类型提供程序连接点的 IWebPartRow 提供程序无法直接连接到需要类型 IWebPartTable提供程序连接点的使用者。 相反,必须使用转换器来连接两个连接点。 可以通过从 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) |