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;
}
}
then
typeof(Tester).GetMethods()
Will return me implicit cast MethodInfo.
However, if I do:
typeof(int).GetMethods()
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.
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).
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.
If you look at System.Decimal
, however, you'll find the operators as that's implemented "just" in the framework itself.
(In a slightly similar way, string
doesn't declare a +
operator; uses of +
within C# are converted to calls to string.Concat
.)
See more on this question at Stackoverflow