DataSourceCacheDurationConverter 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
提供一个类型转换器,用于将 32 位有符号整数对象转换为数据源控制缓存持续时间表示形式和从数据源控制缓存持续时间表示形式。
public ref class DataSourceCacheDurationConverter : System::ComponentModel::Int32Converter
public class DataSourceCacheDurationConverter : System.ComponentModel.Int32Converter
type DataSourceCacheDurationConverter = class
inherit Int32Converter
Public Class DataSourceCacheDurationConverter
Inherits Int32Converter
- 继承
示例
下面的代码示例演示如何在支持使用 TypeConverterAttribute 属性进行缓存的数据源控件上修饰属性。 在此示例中,数据源控件支持缓存语义,并公开三个按其他 ASP.NET 数据源控件建模的属性:EnableCaching、CacheDuration 和 CacheExpirationPolicy。 该 CacheDuration 属性使用 DataSourceCacheDurationConverter 类型转换器。
using System;
using System.ComponentModel;
using System.Web.UI;
[ NonVisualControl() ]
public class SomeDataSource : DataSourceControl
{
// Implementation of a custom data source control.
// The SdsCache object is an imaginary cache object
// provided for this example. It has not actual
// implementation.
private SdsCache m_sdsCache = new SdsCache();
internal SdsCache Cache {
get { return m_sdsCache; }
}
[TypeConverterAttribute(typeof(DataSourceCacheDurationConverter))]
public int CacheDuration {
get { return Cache.Duration; }
}
public DataSourceCacheExpiry CacheExpirationPolicy {
get { return Cache.Expiry; }
set { Cache.Expiry = value; }
}
public bool EnableCaching {
get { return Cache.Enabled; }
set { Cache.Enabled = value; }
}
protected override DataSourceView GetView(string viewName)
{
throw new Exception("The method or operation is not implemented.");
}
// ...
}
<NonVisualControl()> _
Public Class SomeDataSource
Inherits DataSourceControl
' Implementation of a custom data source control.
' The SdsCache object is an imaginary cache object
' provided for this example. It has not actual
' implementation.
Private myCache As New SdsCache()
Friend ReadOnly Property Cache() As SdsCache
Get
Return myCache
End Get
End Property
<TypeConverterAttribute(GetType(DataSourceCacheDurationConverter))> _
Public ReadOnly Property CacheDuration() As Integer
Get
Return Cache.Duration
End Get
End Property
Public Property CacheExpirationPolicy() As DataSourceCacheExpiry
Get
Return Cache.Expiry
End Get
Set
Cache.Expiry = value
End Set
End Property
Public Property EnableCaching() As Boolean
Get
Return Cache.Enabled
End Get
Set
Cache.Enabled = value
End Set
End Property
Protected Overrides Function GetView(ByVal viewName As String) As System.Web.UI.DataSourceView
Throw New Exception("The method or operation is not implemented.")
End Function
' Continue implementation of data source control.
' ...
End Class
注解
ASP.NET 支持缓存的数据源控件通常提供一个 CacheDuration 属性,该属性可以设置为控件缓存数据的秒数。 值 0 表示这些缓存上下文中的“Infinite”,类 DataSourceCacheDurationConverter 负责此显式转换。
页面开发人员不使用该 DataSourceCacheDurationConverter 类。 控制开发支持缓存的数据源控件的开发人员,以及 TypeConverterAttribute 属性来修饰表示自定义数据源控件的缓存持续时间设置的属性。
构造函数
| 名称 | 说明 |
|---|---|
| DataSourceCacheDurationConverter() |
初始化 DataSourceCacheDurationConverter 类的新实例。 |