DataSourceCacheDurationConverter 類別

定義

提供型別轉換子 (Type Converter),將 32 位元帶正負號的整數物件與其他資料來源控制項快取期間表示相互轉換。

public ref class DataSourceCacheDurationConverter : System::ComponentModel::Int32Converter
public class DataSourceCacheDurationConverter : System.ComponentModel.Int32Converter
type DataSourceCacheDurationConverter = class
    inherit Int32Converter
Public Class DataSourceCacheDurationConverter
Inherits Int32Converter
繼承
DataSourceCacheDurationConverter

範例

下列程式碼範例示範如何在支援使用 TypeConverterAttribute 屬性快取的資料來源控制項上裝飾 屬性。 在此範例中,資料來源控制項支援快取語意,並公開在其他 ASP.NET 資料來源控制項之後建立模型的三個屬性: EnableCachingCacheDurationCacheExpirationPolicy 。 屬性 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 類別的新執行個體。

方法

CanConvertFrom(ITypeDescriptorContext, Type)

判斷 DataSourceCacheDurationConverter 是否可以將特定來源類型的物件轉換成 Int32 物件。

CanConvertFrom(Type)

傳回值,指出這個轉換子是否可將指定之型別的物件轉換為這個轉換子的型別。

(繼承來源 TypeConverter)
CanConvertTo(ITypeDescriptorContext, Type)

取得值,指出 DataSourceCacheDurationConverter 執行個體是否可以將物件轉換成指定的目的型別。

CanConvertTo(Type)

傳回值,指出這個轉換子是否可以將物件轉換成指定的型別。

(繼承來源 TypeConverter)
ConvertFrom(ITypeDescriptorContext, CultureInfo, Object)

將指定的物件轉換為 Int32 物件。

ConvertFrom(Object)

會將指定值轉換為這個轉換子的型別。

(繼承來源 TypeConverter)
ConvertFromInvariantString(ITypeDescriptorContext, String)

會使用不區分的文化特性和指定的內容,將指定的字串轉換為這個轉換子的型別。

(繼承來源 TypeConverter)
ConvertFromInvariantString(String)

會使用不因文化特性而異,將指定字串轉換為這個轉換子的型別。

(繼承來源 TypeConverter)
ConvertFromString(ITypeDescriptorContext, CultureInfo, String)

會使用指定內容和文化特性資訊,將指定文字轉換為物件。

(繼承來源 TypeConverter)
ConvertFromString(ITypeDescriptorContext, String)

會使用指定的內容,將指定文字轉換為物件。

(繼承來源 TypeConverter)
ConvertFromString(String)

會將指定的文字轉換成物件。

(繼承來源 TypeConverter)
ConvertTo(ITypeDescriptorContext, CultureInfo, Object, Type)

將指定的物件轉換為另一個型別。

ConvertTo(Object, Type)

會使用引數,將指定值物件轉換成指定型別。

(繼承來源 TypeConverter)
ConvertToInvariantString(ITypeDescriptorContext, Object)

會使用指定的內容,將指定值轉換成不因文化特性而異的字串表示。

(繼承來源 TypeConverter)
ConvertToInvariantString(Object)

會將指定值轉換成不因文化特性而異的字串表示。

(繼承來源 TypeConverter)
ConvertToString(ITypeDescriptorContext, CultureInfo, Object)

會使用指定的內容和文化特性資訊,將指定值轉換為字串表示。

(繼承來源 TypeConverter)
ConvertToString(ITypeDescriptorContext, Object)

會使用指定的內容,將指定值轉換為字串表示。

(繼承來源 TypeConverter)
ConvertToString(Object)

會將指定值轉換成字串表示。

(繼承來源 TypeConverter)
CreateInstance(IDictionary)

重新建立 Object,需為物件提供一組屬性值。

(繼承來源 TypeConverter)
CreateInstance(ITypeDescriptorContext, IDictionary)

使用指定的內容,建立與這個 TypeConverter 相關聯之類型的執行個體,並為物件提供一組屬性值。

(繼承來源 TypeConverter)
Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetConvertFromException(Object)

傳回要在無法執行轉換時擲回的例外狀況。

(繼承來源 TypeConverter)
GetConvertToException(Object, Type)

傳回要在無法執行轉換時擲回的例外狀況。

(繼承來源 TypeConverter)
GetCreateInstanceSupported()

傳回值,指出在這個物件上變更值時是否需要呼叫 CreateInstance(IDictionary) 方法來建立新值。

(繼承來源 TypeConverter)
GetCreateInstanceSupported(ITypeDescriptorContext)

傳回在這個物件上變更值是否需要呼叫 CreateInstance(IDictionary) 來建立新的值,並使用指定的內容。

(繼承來源 TypeConverter)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetProperties(ITypeDescriptorContext, Object)

會使用指定的內容,傳回由值參數所指定之陣列型別的屬性集合。

(繼承來源 TypeConverter)
GetProperties(ITypeDescriptorContext, Object, Attribute[])

使用指定的內容和屬性 (attribute),傳回由該值參數所指定之陣列類型的屬性 (property) 集合。

(繼承來源 TypeConverter)
GetProperties(Object)

傳回由值參數所指定的陣列型別的屬性集合。

(繼承來源 TypeConverter)
GetPropertiesSupported()

傳回值,指出這個物件是否支援屬性。

(繼承來源 TypeConverter)
GetPropertiesSupported(ITypeDescriptorContext)

使用指定的內容,傳回這個物件是否支援屬性。

(繼承來源 TypeConverter)
GetStandardValues()

從為這個型別轉換子所設計的資料型別預設內容中,會傳回標準值的集合。

(繼承來源 TypeConverter)
GetStandardValues(ITypeDescriptorContext)

傳回 DataSourceCacheDurationConverter 執行個體設計使用之資料型別的標準值集合。

GetStandardValuesExclusive()

傳回值,指出從 GetStandardValues() 所傳回的標準值集合是否為獨佔清單。

(繼承來源 TypeConverter)
GetStandardValuesExclusive(ITypeDescriptorContext)

使用指定內容,指定從 GetStandardValues 方法所傳回的標準值集合是否為獨佔清單。

GetStandardValuesSupported()

傳回這個物件是否支援可以從清單中選取的標準值集合。

(繼承來源 TypeConverter)
GetStandardValuesSupported(ITypeDescriptorContext)

使用指定的內容,指定 DataSourceCacheDurationConverter 物件是否支援可從清單中選取的標準值集。

GetType()

取得目前執行個體的 Type

(繼承來源 Object)
IsValid(ITypeDescriptorContext, Object)

傳回指定值物件對這個類型和指定的內容是否有效。

(繼承來源 TypeConverter)
IsValid(Object)

會傳回指定值物件是否對這個型別有效。

(繼承來源 TypeConverter)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
SortProperties(PropertyDescriptorCollection, String[])

排序屬性的集合。

(繼承來源 TypeConverter)
ToString()

傳回代表目前物件的字串。

(繼承來源 Object)

適用於

另請參閱