Table of Contents

Class ReflectionHelper

Namespace
ICSharpCode.Decompiler.TypeSystem
Assembly
ICSharpCode.Decompiler.dll

Static helper methods for reflection names.

public static class ReflectionHelper
Inheritance
ReflectionHelper
Inherited Members

Methods

FindType(ICompilation, StackType, Sign)

public static IType FindType(this ICompilation compilation, StackType stackType, Sign sign = Sign.None)

Parameters

compilation ICompilation
stackType StackType
sign Sign

Returns

IType

FindType(ICompilation, Type)

Retrieves the specified type in this compilation. Returns UnknownType if the type cannot be found in this compilation.

public static IType FindType(this ICompilation compilation, Type type)

Parameters

compilation ICompilation
type Type

Returns

IType

Remarks

This method cannot be used with open types; all type parameters will be substituted with UnknownType.

FindType(ICompilation, TypeCode)

Retrieves a built-in type using the specified type code.

public static IType FindType(this ICompilation compilation, TypeCode typeCode)

Parameters

compilation ICompilation
typeCode TypeCode

Returns

IType

GetTypeCode(IType)

Gets the type code for the specified type, or TypeCode.Empty if none of the other type codes match.

public static TypeCode GetTypeCode(this IType type)

Parameters

type IType

Returns

TypeCode

ParseReflectionName(string)

Parses a reflection name into a type reference.

public static ITypeReference ParseReflectionName(string reflectionTypeName)

Parameters

reflectionTypeName string

The reflection name of the type.

Returns

ITypeReference

A type reference that represents the reflection name.

Remarks

If the type is open (contains type parameters '`0' or '``0'), an ITypeResolveContext with the appropriate CurrentTypeDefinition/CurrentMember is required to resolve the reference to the ITypeParameter. For looking up closed, assembly qualified type names, the root type resolve context for the compilation is sufficient. When looking up a type name that isn't assembly qualified, the type reference will look in CurrentModule first, and if the type is not found there, it will look in all other assemblies of the compilation.

Exceptions

ReflectionNameParseException

The syntax of the reflection type name is invalid

See Also

SplitTypeParameterCountFromReflectionName(string)

Removes the ` with type parameter count from the reflection name.

public static string SplitTypeParameterCountFromReflectionName(string reflectionName)

Parameters

reflectionName string

Returns

string

Remarks

Do not use this method with the full name of inner classes.

SplitTypeParameterCountFromReflectionName(string, out int)

Removes the ` with type parameter count from the reflection name.

public static string SplitTypeParameterCountFromReflectionName(string reflectionName, out int typeParameterCount)

Parameters

reflectionName string
typeParameterCount int

Returns

string

Remarks

Do not use this method with the full name of inner classes.

ToTypeReference(Type)

Creates a reference to the specified type.

public static ITypeReference ToTypeReference(this Type type)

Parameters

type Type

The type to be converted.

Returns

ITypeReference

Returns the type reference.

Remarks

If the type is open (contains type parameters '`0' or '``0'), an ITypeResolveContext with the appropriate CurrentTypeDefinition/CurrentMember is required to resolve the type reference. For closed types, the root type resolve context for the compilation is sufficient.

ToTypeReference(TypeCode)

Creates a reference to the specified type.

public static ITypeReference ToTypeReference(this TypeCode typeCode)

Parameters

typeCode TypeCode

The type to be converted.

Returns

ITypeReference

Returns the type reference.