1
31
我刚刚遇到了同样的问题,我使用Reflector来查看changeType的源代码。ChangeType在3种情况下引发异常:
在检查完这3个之后,就可以保证它可以被转换。因此,您可以通过自己检查这三件事来节省大量性能并删除Try/Catch块:
|
2
8
检查Reflector中的convert.changeType方法时,我在静态构造函数中发现了这一点:
最后,这个方法只是检查源是否实现IConvertible,或者目标是否是上面的converttypes之一。所以你的方法应该是这样的(非常粗糙):
|
3
1
我已经编写了一个小框架,其中包括一个转换类,它可以做的比System.Convert类更多。如果您有兴趣使用它,可以从下载 CodePlex . 它没有能力确定是否可以在值之间进行转换,但这似乎是一个很好的添加功能。 它包括根据以下内容转换值的能力:
|
4
0
基于这两个问题的答案,我提出了这个问题(需要C 7)
生产代码示例:
这将使用0启动所有可能的属性。 |
Robert King · Unity C#语法问题-转换位置 1 年前 |
JBryanB · 如何从基本抽象类访问类属性 1 年前 |
law · 检查答案按钮的输入字符串格式不正确 2 年前 |
i_sniff_ket · 在unity之外使用unity类 2 年前 |