TimeSpanMinutesConverter.ConvertTo 方法

定义

TimeSpan 转换为 String

public:
 override System::Object ^ ConvertTo(System::ComponentModel::ITypeDescriptorContext ^ ctx, System::Globalization::CultureInfo ^ ci, System::Object ^ value, Type ^ type);
public override object ConvertTo (System.ComponentModel.ITypeDescriptorContext ctx, System.Globalization.CultureInfo ci, object value, Type type);
override this.ConvertTo : System.ComponentModel.ITypeDescriptorContext * System.Globalization.CultureInfo * obj * Type -> obj
Public Overrides Function ConvertTo (ctx As ITypeDescriptorContext, ci As CultureInfo, value As Object, type As Type) As Object

参数

ctx
ITypeDescriptorContext

用于类型转换的 ITypeDescriptorContext 对象。

ci
CultureInfo

转换期间使用的 CultureInfo 对象。

value
Object

要转换为的值。

type
Type

要转换为的类型。

返回

以分钟表示 value 参数的 String

示例

下面的代码示例演示如何自定义 ConvertTo 方法。

public override object ConvertTo(
    ITypeDescriptorContext ctx, CultureInfo ci,
    object value, Type type)
{
    ValidateType(value, typeof(TimeSpan));

    long data = (long)(((TimeSpan)value).TotalMinutes);

    return data.ToString(CultureInfo.InvariantCulture);
}
Public Overrides Function ConvertTo( _
ByVal ctx As ITypeDescriptorContext, _
ByVal ci As CultureInfo, ByVal value As Object, _
ByVal type As Type) As Object
    ValidateType(value, GetType(TimeSpan))

    Dim data As Long = _
    Fix(CType(value, TimeSpan).TotalMinutes)

    Return data.ToString(CultureInfo.InvariantCulture)

End Function 'ConvertTo

注解

写入配置文件时, ConvertTo 系统会使用 方法将 转换为 TimeSpanString

适用于