Table of Contents

Class TypeInference

Namespace
ICSharpCode.Decompiler.CSharp.Resolver
Assembly
ICSharpCode.Decompiler.dll

Implements C# 4.0 Type Inference (§7.5.2).

public sealed class TypeInference
Inheritance
TypeInference
Inherited Members

Constructors

TypeInference(ICompilation)

public TypeInference(ICompilation compilation)

Parameters

compilation ICompilation

Properties

Algorithm

Gets/Sets the type inference algorithm used.

public TypeInferenceAlgorithm Algorithm { get; set; }

Property Value

TypeInferenceAlgorithm

Methods

FindTypeInBounds(IReadOnlyList<IType>, IReadOnlyList<IType>)

Finds a type that satisfies the given lower and upper bounds.

public IType FindTypeInBounds(IReadOnlyList<IType> lowerBounds, IReadOnlyList<IType> upperBounds)

Parameters

lowerBounds IReadOnlyList<IType>
upperBounds IReadOnlyList<IType>

Returns

IType

GetBestCommonType(IList<ResolveResult>, out bool)

Gets the best common type (C# 4.0 spec: §7.5.2.14) of a set of expressions.

public IType GetBestCommonType(IList<ResolveResult> expressions, out bool success)

Parameters

expressions IList<ResolveResult>
success bool

Returns

IType

InferTypeArguments(IReadOnlyList<ITypeParameter>, IReadOnlyList<ResolveResult>, IReadOnlyList<IType>, out bool, IReadOnlyList<IType>)

Performs type inference.

public IType[] InferTypeArguments(IReadOnlyList<ITypeParameter> typeParameters, IReadOnlyList<ResolveResult> arguments, IReadOnlyList<IType> parameterTypes, out bool success, IReadOnlyList<IType> classTypeArguments = null)

Parameters

typeParameters IReadOnlyList<ITypeParameter>

The method type parameters that should be inferred.

arguments IReadOnlyList<ResolveResult>

The arguments passed to the method.

parameterTypes IReadOnlyList<IType>

The parameter types of the method.

success bool

Out: whether type inference was successful

classTypeArguments IReadOnlyList<IType>

Class type arguments. These are substituted for class type parameters in the formal parameter types when inferring a method group or lambda.

Returns

IType[]

The inferred type arguments.

InferTypeArgumentsFromBounds(IReadOnlyList<ITypeParameter>, IType, IEnumerable<IType>, IEnumerable<IType>, out bool)

Infers type arguments for the typeParameters occurring in the targetType so that the resulting type (after substition) satisfies the given bounds.

public IType[] InferTypeArgumentsFromBounds(IReadOnlyList<ITypeParameter> typeParameters, IType targetType, IEnumerable<IType> lowerBounds, IEnumerable<IType> upperBounds, out bool success)

Parameters

typeParameters IReadOnlyList<ITypeParameter>
targetType IType
lowerBounds IEnumerable<IType>
upperBounds IEnumerable<IType>
success bool

Returns

IType[]