Class TypeUtils
- Namespace
- ICSharpCode.Decompiler.TypeSystem
- Assembly
- ICSharpCode.Decompiler.dll
public static class TypeUtils
- Inheritance
-
TypeUtils
- Inherited Members
Fields
NativeIntSize
public const int NativeIntSize = 6
Field Value
Methods
GetEnumUnderlyingType(IType)
If type is an enumeration type, returns the underlying type. Otherwise, returns type unmodified.
public static IType GetEnumUnderlyingType(this IType type)
Parameters
type
IType
Returns
GetLargerType(IType, IType)
public static IType GetLargerType(IType type1, IType type2)
Parameters
Returns
GetSign(IType)
Gets the sign of the input type.
public static Sign GetSign(this IType type)
Parameters
type
IType
Returns
Remarks
Integer types (including IntPtr/UIntPtr) return the sign as expected.
Floating point types and decimal
are considered to be signed.
char
, bool
and pointer types (e.g. void*
) are unsigned.
Enums have a sign based on their underlying type.
All other types return Sign.None
.
GetSize(StackType)
Gets the size of the input stack type.
public static int GetSize(this StackType type)
Parameters
type
StackType
Returns
- int
- 4 for
I4
, - 8 for
I8
, NativeIntSize
forI
andRef
,- 0 otherwise (O, F, Void, Unknown).
- 4 for
GetSize(IType)
Gets the size (in bytes) of the input type.
Returns NativeIntSize
for pointer-sized types.
Returns 0 for structs and other types of unknown size.
public static int GetSize(this IType type)
Parameters
type
IType
Returns
GetStackType(IType)
Gets the stack type corresponding to this type.
public static StackType GetStackType(this IType type)
Parameters
type
IType
Returns
IsCSharpNativeIntegerType(IType)
Gets whether the type is a C# 9 native integer type: nint or nuint.
Returns false for (U)IntPtr.
public static bool IsCSharpNativeIntegerType(this IType type)
Parameters
type
IType
Returns
IsCSharpPrimitiveIntegerType(IType)
Gets whether the type is a C# primitive integer type: byte, sbyte, short, ushort, int, uint, long and ulong.
Unlike the ILAst, C# does not consider bool, enums, pointers or IntPtr to be integers.
public static bool IsCSharpPrimitiveIntegerType(this IType type)
Parameters
type
IType
Returns
IsCSharpSmallIntegerType(IType)
Gets whether the type is a C# small integer type: byte, sbyte, short or ushort.
Unlike the ILAst, C# does not consider bool, char or enums to be small integers.
public static bool IsCSharpSmallIntegerType(this IType type)
Parameters
type
IType
Returns
IsCompatiblePointerTypeForMemoryAccess(IType, IType)
Gets whether reading/writing an element of accessType from the pointer is equivalent to reading/writing an element of the pointer's element type.
public static bool IsCompatiblePointerTypeForMemoryAccess(IType pointerType, IType accessType)
Parameters
Returns
Remarks
The access semantics may sligthly differ on read accesses of small integer types, due to zero extension vs. sign extension when the signs differ.
IsCompatibleTypeForMemoryAccess(IType, IType)
Gets whether reading/writing an element of accessType from the pointer is equivalent to reading/writing an element of the memoryType.
public static bool IsCompatibleTypeForMemoryAccess(IType memoryType, IType accessType)
Parameters
Returns
Remarks
The access semantics may sligthly differ on read accesses of small integer types, due to zero extension vs. sign extension when the signs differ.
IsFloatType(StackType)
Gets whether the type is an IL floating point type. Returns true for F4 or F8.
public static bool IsFloatType(this StackType type)
Parameters
type
StackType
Returns
IsIntegerType(StackType)
Gets whether the type is an IL integer type. Returns true for I4, I, or I8.
public static bool IsIntegerType(this StackType type)
Parameters
type
StackType
Returns
IsSmallIntegerType(IType)
Gets whether the type is a small integer type. Small integer types are:
- bool, sbyte, byte, char, short, ushort
- any enums that have a small integer type as underlying type
public static bool IsSmallIntegerType(this IType type)
Parameters
type
IType
Returns
ToKnownTypeCode(PrimitiveType)
Maps the PrimitiveType values to the corresponding KnownTypeCodes.
public static KnownTypeCode ToKnownTypeCode(this PrimitiveType primitiveType)
Parameters
primitiveType
PrimitiveType
Returns
ToKnownTypeCode(StackType, Sign)
public static KnownTypeCode ToKnownTypeCode(this StackType stackType, Sign sign = Sign.None)
Parameters
Returns
ToPrimitiveType(StackType, Sign)
public static PrimitiveType ToPrimitiveType(this StackType stackType, Sign sign = Sign.None)
Parameters
Returns
ToPrimitiveType(IType)
Maps the KnownTypeCode values to the corresponding PrimitiveTypes.
public static PrimitiveType ToPrimitiveType(this IType type)
Parameters
type
IType
Returns
ToPrimitiveType(KnownTypeCode)
Maps the KnownTypeCode values to the corresponding PrimitiveTypes.
public static PrimitiveType ToPrimitiveType(this KnownTypeCode knownTypeCode)
Parameters
knownTypeCode
KnownTypeCode