Class CSharpPrimitiveCast
- Namespace
- ICSharpCode.Decompiler.Util
- Assembly
- ICSharpCode.Decompiler.dll
Static helper method for converting between primitive types.
public static class CSharpPrimitiveCast
- Inheritance
-
CSharpPrimitiveCast
- Inherited Members
Methods
Cast(TypeCode, object, bool)
Performs a conversion between primitive types. Unfortunately we cannot use Convert.ChangeType because it has different semantics (e.g. rounding behavior for floats, overflow, etc.), so we write down every possible primitive C# cast and let the compiler figure out the exact semantics. And we have to do everything twice, once in a checked-block, once in an unchecked-block.
public static object Cast(TypeCode targetType, object input, bool checkForOverflow)
Parameters
Returns
Exceptions
- OverflowException
Overflow checking is enabled and an overflow occurred.
- InvalidCastException
The cast is invalid, e.g. casting a boolean to an integer.