反映op_implicit表 [英] Reflect op_implicit table
问题描述
我目前正在寻求建立动态的类型转换器,
I'm currently looking to build dynamic type converter,
例如,我可以很容易做到:
for example, I can easily do :
public struct Tester
{
public int Hello;
public static implicit operator int(Tester d)
{
return d.Hello;
}
public static implicit operator float(Tester d)
{
return d.Hello;
}
}
然后
typeof(Tester).GetMethods()
将返回我隐式转换的MethodInfo。
Will return me implicit cast MethodInfo.
不过,如果我做的:
typeof(int).GetMethods()
这将不返回任何op_implicit
It will not return any op_implicit
我已经看到了,你可以看到表此处,但我想知道是否有可能从框架本身反映了它。
I've seen that you can see the table here , but I was wondering if it's possible to reflect it from the framework itself.
请注意,这不是一个真正的阻塞问题,如果它是不可能的,我会从手工表添加转换器,但我会很明显preFER有这个动态生成的(更清洁,更不容易出错)。
Please note that it's not really a blocking issue, if it's not possible, I'll add converters from the table manually, but I would obviously prefer to have this dynamically built (cleaner and less error prone).
推荐答案
经营者的基本类型没有在框架中定义 - 他们是CLI本身的一部分;他们有自己的特殊说明,基本上是这样。有没有IL参与,没有方法,所以没有一个的MethodInfo
来参考一下。
The operators for the primitive types aren't defined in the framework - they're part of the CLI itself; they have their own special instructions, basically. There's no IL involved, no methods, so nothing for a MethodInfo
to refer to.
如果你看一下 System.Decimal
,但是,你会发现运营商是在框架本身实现公正。
If you look at System.Decimal
, however, you'll find the operators as that's implemented "just" in the framework itself.
(在略的类似的方法,字符串
未声明 +
经营者;对 +
C#中的用途被转换成调用 string.Concat
)
(In a slightly similar way, string
doesn't declare a +
operator; uses of +
within C# are converted to calls to string.Concat
.)
这篇关于反映op_implicit表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!