Reflector (6.5.0.135) doesn't recognise the need for a cast when a UINT is cast to a ULONG before performing a Shift Left operation.
Example:
public class ReflectorTest
{
public ulong uintShlTest(uint x)
{
return (ulong)x << 2;
}
public ulong ushortShlTest(ushort x)
{
return (ulong)x << 2;
}
}
But the Reflector produced C# code for the first method is missing the cast, and is produced as:
public class ReflectorTest
{
// Methods
public ulong uintShlTest(uint x)
{
return (x << 2);
}
public ulong ushortShlTest(ushort x)
{
return (ulong) (x << 2);
}
}
These two methods produce the exact same set of instructions in their bodies:
L_0000: nop
L_0001: ldarg.1
L_0002: conv.u8
L_0003: ldc.i4.2
L_0004: shl
L_0005: stloc.0
L_0006: br.s L_0008
L_0008: ldloc.0
L_0009: ret
Reflector recognises the need for the cast in the ushort to ulong case, but not in the uint to ulong case.
Example:
But the Reflector produced C# code for the first method is missing the cast, and is produced as:
These two methods produce the exact same set of instructions in their bodies:
L_0000: nop
L_0001: ldarg.1
L_0002: conv.u8
L_0003: ldc.i4.2
L_0004: shl
L_0005: stloc.0
L_0006: br.s L_0008
L_0008: ldloc.0
L_0009: ret
Reflector recognises the need for the cast in the ushort to ulong case, but not in the uint to ulong case.