Table of Contents

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

int

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

IType

GetLargerType(IType, IType)

public static IType GetLargerType(IType type1, IType type2)

Parameters

type1 IType
type2 IType

Returns

IType

GetSign(IType)

Gets the sign of the input type.

public static Sign GetSign(this IType type)

Parameters

type IType

Returns

Sign

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 for I and Ref,
  • 0 otherwise (O, F, Void, Unknown).

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

int

GetStackType(IType)

Gets the stack type corresponding to this type.

public static StackType GetStackType(this IType type)

Parameters

type IType

Returns

StackType

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

bool

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

bool

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

bool

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

pointerType IType
accessType IType

Returns

bool

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

memoryType IType
accessType IType

Returns

bool

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

bool

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

bool

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

bool

ToKnownTypeCode(PrimitiveType)

Maps the PrimitiveType values to the corresponding KnownTypeCodes.

public static KnownTypeCode ToKnownTypeCode(this PrimitiveType primitiveType)

Parameters

primitiveType PrimitiveType

Returns

KnownTypeCode

ToKnownTypeCode(StackType, Sign)

public static KnownTypeCode ToKnownTypeCode(this StackType stackType, Sign sign = Sign.None)

Parameters

stackType StackType
sign Sign

Returns

KnownTypeCode

ToPrimitiveType(StackType, Sign)

public static PrimitiveType ToPrimitiveType(this StackType stackType, Sign sign = Sign.None)

Parameters

stackType StackType
sign Sign

Returns

PrimitiveType

ToPrimitiveType(IType)

Maps the KnownTypeCode values to the corresponding PrimitiveTypes.

public static PrimitiveType ToPrimitiveType(this IType type)

Parameters

type IType

Returns

PrimitiveType

ToPrimitiveType(KnownTypeCode)

Maps the KnownTypeCode values to the corresponding PrimitiveTypes.

public static PrimitiveType ToPrimitiveType(this KnownTypeCode knownTypeCode)

Parameters

knownTypeCode KnownTypeCode

Returns

PrimitiveType