相关疑难解决方法(0)

如何为特定类型查找和调用.Net TypeConverter?

我想实现一个通用的运行时类型转换函数,它使用.Net TypeConverters来进行转换.

有谁知道如何查找和调用特定类型的TypeConverter?

考虑一下这个C#示例:

//
// 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 …
Run Code Online (Sandbox Code Playgroud)

.net c# type-conversion

10
推荐指数
2
解决办法
1万
查看次数

标签 统计

.net ×1

c# ×1

type-conversion ×1