TimeSpanMinutesConverter.ConvertFrom(ITypeDescriptorContext, CultureInfo, Object) 方法
定义
public:
override System::Object ^ ConvertFrom(System::ComponentModel::ITypeDescriptorContext ^ ctx, System::Globalization::CultureInfo ^ ci, System::Object ^ data);
public override object ConvertFrom (System.ComponentModel.ITypeDescriptorContext ctx, System.Globalization.CultureInfo ci, object data);
override this.ConvertFrom : System.ComponentModel.ITypeDescriptorContext * System.Globalization.CultureInfo * obj -> obj
Public Overrides Function ConvertFrom (ctx As ITypeDescriptorContext, ci As CultureInfo, data As Object) As Object
参数
用于类型转换的 ITypeDescriptorContext 对象。The ITypeDescriptorContext object used for type conversions.
- ci
- CultureInfo
转换期间使用的 CultureInfo 对象。The CultureInfo object used during conversion.
返回
以分钟表示 data 参数的 TimeSpan。The TimeSpan representing the data parameter in minutes.
示例
下面的代码示例演示如何自定义 ConvertFrom 方法。The following code example shows how to customize the ConvertFrom method.
public override object ConvertFrom(
ITypeDescriptorContext ctx, CultureInfo ci, object data)
{
long min = long.Parse((string)data,
CultureInfo.InvariantCulture);
return TimeSpan.FromMinutes((double)min);
}
Public Overrides Function ConvertFrom( _
ByVal ctx As ITypeDescriptorContext, _
ByVal ci As CultureInfo, ByVal data As Object) As Object
Dim min As Long = _
Long.Parse(CStr(data), CultureInfo.InvariantCulture)
Return TimeSpan.FromMinutes(System.Convert.ToDouble(min))
End Function 'ConvertFrom
注解
ConvertFrom从配置文件读取时,系统使用方法将 String 值转换为 TimeSpan 。The system uses the ConvertFrom method when reading from a configuration file to convert a String value to TimeSpan.