Table of Contents

Class OverloadResolution

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

C# overload resolution (C# 4.0 spec: §7.5).

public class OverloadResolution
Inheritance
OverloadResolution
Inherited Members

Constructors

OverloadResolution(ICompilation, ResolveResult[], string[], IType[], CSharpConversions)

public OverloadResolution(ICompilation compilation, ResolveResult[] arguments, string[] argumentNames = null, IType[] typeArguments = null, CSharpConversions conversions = null)

Parameters

compilation ICompilation
arguments ResolveResult[]
argumentNames string[]
typeArguments IType[]
conversions CSharpConversions

Properties

AllowExpandingParams

Gets/Sets whether expanding 'params' into individual elements is allowed. The default value is true.

public bool AllowExpandingParams { get; set; }

Property Value

bool

AllowImplicitIn

Gets/Sets whether a value argument can be passed to an in reference parameter.

public bool AllowImplicitIn { get; set; }

Property Value

bool

AllowOptionalParameters

Gets/Sets whether optional parameters may be left at their default value. The default value is true. If this property is set to false, optional parameters will be treated like regular parameters.

public bool AllowOptionalParameters { get; set; }

Property Value

bool

ArgumentConversions

Gets the implicit conversions that are being applied to the arguments.

public IList<Conversion> ArgumentConversions { get; }

Property Value

IList<Conversion>

Arguments

Gets the arguments for which this OverloadResolution instance was created.

public IList<ResolveResult> Arguments { get; }

Property Value

IList<ResolveResult>

BestCandidate

public IParameterizedMember BestCandidate { get; }

Property Value

IParameterizedMember

BestCandidateAmbiguousWith

public IParameterizedMember BestCandidateAmbiguousWith { get; }

Property Value

IParameterizedMember

BestCandidateErrors

Returns the errors that apply to the best candidate. This includes additional errors that do not affect applicability (e.g. AmbiguousMatch, MethodConstraintsNotSatisfied)

public OverloadResolutionErrors BestCandidateErrors { get; }

Property Value

OverloadResolutionErrors

BestCandidateIsExpandedForm

public bool BestCandidateIsExpandedForm { get; }

Property Value

bool

CheckForOverflow

Gets/Sets whether ConversionResolveResults created by this OverloadResolution instance apply overflow checking. The default value is false.

public bool CheckForOverflow { get; set; }

Property Value

bool

FoundApplicableCandidate

public bool FoundApplicableCandidate { get; }

Property Value

bool

InferredTypeArguments

public IReadOnlyList<IType> InferredTypeArguments { get; }

Property Value

IReadOnlyList<IType>

IsAmbiguous

public bool IsAmbiguous { get; }

Property Value

bool

IsExtensionMethodInvocation

Gets/Sets whether the methods are extension methods that are being called using extension method syntax.

public bool IsExtensionMethodInvocation { get; set; }

Property Value

bool

Remarks

Setting this property to true restricts the possible conversions on the first argument to implicit identity, reference, or boxing conversions.

Methods

AddCandidate(IParameterizedMember)

Adds a candidate to overload resolution.

public OverloadResolutionErrors AddCandidate(IParameterizedMember member)

Parameters

member IParameterizedMember

The candidate member to add.

Returns

OverloadResolutionErrors

The errors that prevent the member from being applicable, if any. Note: this method does not return errors that do not affect applicability.

AddCandidate(IParameterizedMember, OverloadResolutionErrors)

Adds a candidate to overload resolution.

public OverloadResolutionErrors AddCandidate(IParameterizedMember member, OverloadResolutionErrors additionalErrors)

Parameters

member IParameterizedMember

The candidate member to add.

additionalErrors OverloadResolutionErrors

Additional errors that apply to the candidate. This is used to represent errors during member lookup (e.g. OverloadResolutionErrors.Inaccessible) in overload resolution.

Returns

OverloadResolutionErrors

The errors that prevent the member from being applicable, if any. Note: this method does not return errors that do not affect applicability.

AddMethodLists(IReadOnlyList<MethodListWithDeclaringType>)

Adds all candidates from the method lists.

This method implements the logic that causes applicable methods in derived types to hide all methods in base types.

public void AddMethodLists(IReadOnlyList<MethodListWithDeclaringType> methodLists)

Parameters

methodLists IReadOnlyList<MethodListWithDeclaringType>

The methods, grouped by declaring type. Base types must come first in the list.

CreateResolveResult(ResolveResult, IList<ResolveResult>, IType)

Creates a ResolveResult representing the result of overload resolution.

public CSharpInvocationResolveResult CreateResolveResult(ResolveResult targetResolveResult, IList<ResolveResult> initializerStatements = null, IType returnTypeOverride = null)

Parameters

targetResolveResult ResolveResult

The target expression of the call. May be null for static methods/constructors.

initializerStatements IList<ResolveResult>

Statements for Objects/Collections initializer. InitializerStatements

returnTypeOverride IType

If not null, use this instead of the ReturnType of the member as the type of the created resolve result.

Returns

CSharpInvocationResolveResult

GetArgumentToParameterMap()

Gets an array that maps argument indices to parameter indices. For arguments that could not be mapped to any parameter, the value will be -1.

parameterIndex = GetArgumentToParameterMap()[argumentIndex]

public IReadOnlyList<int> GetArgumentToParameterMap()

Returns

IReadOnlyList<int>

GetArgumentsWithConversions()

Returns the arguments for the method call in the order they were provided (not in the order of the parameters). Arguments are wrapped in a ConversionResolveResult if an implicit conversion is being applied to them when calling the method.

public IList<ResolveResult> GetArgumentsWithConversions()

Returns

IList<ResolveResult>

GetArgumentsWithConversionsAndNames()

Returns the arguments for the method call in the order they were provided (not in the order of the parameters). Arguments are wrapped in a ConversionResolveResult if an implicit conversion is being applied to them when calling the method. For arguments where an explicit argument name was provided, the argument will be wrapped in a NamedArgumentResolveResult.

public IList<ResolveResult> GetArgumentsWithConversionsAndNames()

Returns

IList<ResolveResult>

GetBestCandidateWithSubstitutedTypeArguments()

public IParameterizedMember GetBestCandidateWithSubstitutedTypeArguments()

Returns

IParameterizedMember

IsApplicable(OverloadResolutionErrors)

Returns whether a candidate with the given errors is still considered to be applicable.

public static bool IsApplicable(OverloadResolutionErrors errors)

Parameters

errors OverloadResolutionErrors

Returns

bool

ValidateConstraints(ITypeParameter, IType, TypeVisitor)

Validates whether the given type argument satisfies the constraints for the given type parameter.

public static bool ValidateConstraints(ITypeParameter typeParameter, IType typeArgument, TypeVisitor substitution = null)

Parameters

typeParameter ITypeParameter

The type parameter.

typeArgument IType

The type argument.

substitution TypeVisitor

The substitution that defines how type parameters are replaced with type arguments. The substitution is used to check constraints that depend on other type parameters (or recursively on the same type parameter). May be null if no substitution should be used.

Returns

bool

True if the constraints are satisfied; false otherwise.