.Net TypeConverters를 사용하여 변환을 수행하는 범용 런타임 유형 변환 함수를 구현하고 싶습니다.특정 유형의 .Net TypeConverter를 검색하고 호출하는 방법은 무엇입니까?
누구든지 특정 유형의 TypeConverter를 검색하고 호출하는 방법을 알고 있습니까? 당신은 ASP.NET의 ViewState에 당신이 무엇을 유사한 기능을한다는 것을 고려해 볼 수 있습니다
//
// Convert obj to the type specified by 'toType'.
//
object ConvertTo(object obj, Type toType)
{
if (TypeIsEqualOrDerivesFrom(obj.GetType(), toType)) <-- I know how to implement this.
{
// The type of obj is the same as the type specified by 'toType' or
// the type of obj derives from the type specified by 'toType'.
return obj;
}
if (TypeConverterExists(obj.GetType(), toType) <-- How do I implement this?
{
// There exists a type convertor that is capable of converting from
// the type of obj to the type specified by 'toType'.
return InvokeTypeConverter(obj, toType); <-- How do I implement this?
}
throw new TypeConversionFailedException();
}
돈 태그에 'dotnet'을 사용하지 마십시오. –