Table of Contents

Class CSharpResolver

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

Contains the main resolver logic.

public class CSharpResolver : ICodeContext, ITypeResolveContext, ICompilationProvider
Inheritance
CSharpResolver
Implements
Inherited Members

Remarks

This class is thread-safe.

Constructors

CSharpResolver(CSharpTypeResolveContext)

public CSharpResolver(CSharpTypeResolveContext context)

Parameters

context CSharpTypeResolveContext

CSharpResolver(ICompilation)

public CSharpResolver(ICompilation compilation)

Parameters

compilation ICompilation

Properties

CheckForOverflow

Gets whether the current context is checked.

public bool CheckForOverflow { get; }

Property Value

bool

Compilation

Gets the compilation used by the resolver.

public ICompilation Compilation { get; }

Property Value

ICompilation

CurrentMember

Gets the current member definition that is used to look up identifiers as parameters or type parameters.

public IMember CurrentMember { get; }

Property Value

IMember

CurrentObjectInitializer

Gets the current object initializer. This usually is an InitializedObjectResolveResult or (for nested initializers) a semantic tree based on an InitializedObjectResolveResult. Returns ErrorResolveResult if there is no object initializer.

public ResolveResult CurrentObjectInitializer { get; }

Property Value

ResolveResult

CurrentObjectInitializerType

Gets the type of the object currently being initialized. Returns SharedTypes.Unknown if no object initializer is currently open (or if the object initializer has unknown type).

public IType CurrentObjectInitializerType { get; }

Property Value

IType

CurrentTypeDefinition

Gets the current type definition.

public ITypeDefinition CurrentTypeDefinition { get; }

Property Value

ITypeDefinition

CurrentTypeResolveContext

Gets the current type resolve context.

public CSharpTypeResolveContext CurrentTypeResolveContext { get; }

Property Value

CSharpTypeResolveContext

CurrentUsingScope

Gets the current using scope that is used to look up identifiers as class names.

public ResolvedUsingScope CurrentUsingScope { get; }

Property Value

ResolvedUsingScope

IsInObjectInitializer

Gets whether this context is within an object initializer.

public bool IsInObjectInitializer { get; }

Property Value

bool

IsWithinLambdaExpression

Gets whether the resolver is currently within a lambda expression or anonymous method.

public bool IsWithinLambdaExpression { get; }

Property Value

bool

LocalVariables

Gets all currently visible local variables and lambda parameters. Does not include method parameters.

public IEnumerable<IVariable> LocalVariables { get; }

Property Value

IEnumerable<IVariable>

Methods

AddVariables(Dictionary<string, IVariable>)

Adds new variableŝ or lambda parameters to the current block.

public CSharpResolver AddVariables(Dictionary<string, IVariable> variables)

Parameters

variables Dictionary<string, IVariable>

Returns

CSharpResolver

CreateMemberLookup()

Creates a MemberLookup instance using this resolver's settings.

public MemberLookup CreateMemberLookup()

Returns

MemberLookup

CreateMemberLookup(NameLookupMode)

Creates a MemberLookup instance using this resolver's settings.

public MemberLookup CreateMemberLookup(NameLookupMode lookupMode)

Parameters

lookupMode NameLookupMode

Returns

MemberLookup

GetDefaultValue(IType)

public static object GetDefaultValue(IType type)

Parameters

type IType

Returns

object

GetExtensionMethods(IType, string, IReadOnlyList<IType>, bool)

Gets the extension methods that are called 'name' and are applicable with a first argument type of 'targetType'.

public List<List<IMethod>> GetExtensionMethods(IType targetType, string name = null, IReadOnlyList<IType> typeArguments = null, bool substituteInferredTypes = false)

Parameters

targetType IType

Type of the 'this' argument

name string

Name of the extension method. Pass null to retrieve all extension methods.

typeArguments IReadOnlyList<IType>

Explicitly provided type arguments. An empty list will return all matching extension method definitions; a non-empty list will return SpecializedMethods for all extension methods with the matching number of type parameters.

substituteInferredTypes bool

Specifies whether to produce a SpecializedMethod when type arguments could be inferred from targetType. This parameter is only used for inferred types and has no effect if typeArguments is non-empty.

Returns

List<List<IMethod>>

Remarks

The results are stored in nested lists because they are grouped by using scope. That is, for "using SomeExtensions; namespace X { using MoreExtensions; ... }", the return value will be new List { new List { all extensions from MoreExtensions }, new List { all extensions from SomeExtensions } }

GetExtensionMethods(string, IReadOnlyList<IType>)

Gets all extension methods that are available in the current context.

public List<List<IMethod>> GetExtensionMethods(string name = null, IReadOnlyList<IType> typeArguments = null)

Parameters

name string

Name of the extension method. Pass null to retrieve all extension methods.

typeArguments IReadOnlyList<IType>

Explicitly provided type arguments. An empty list will return all matching extension method definitions; a non-empty list will return SpecializedMethods for all extension methods with the matching number of type parameters.

Returns

List<List<IMethod>>

Remarks

The results are stored in nested lists because they are grouped by using scope. That is, for "using SomeExtensions; namespace X { using MoreExtensions; ... }", the return value will be new List { new List { all extensions from MoreExtensions }, new List { all extensions from SomeExtensions } }

GetUserDefinedOperatorCandidates(IType, string)

public IEnumerable<IParameterizedMember> GetUserDefinedOperatorCandidates(IType type, string operatorName)

Parameters

type IType
operatorName string

Returns

IEnumerable<IParameterizedMember>

IsEligibleExtensionMethod(IType, IMethod, bool, out IType[])

Checks whether the specified extension method is eligible on the target type.

public static bool IsEligibleExtensionMethod(IType targetType, IMethod method, bool useTypeInference, out IType[] outInferredTypes)

Parameters

targetType IType

Target type that is passed as first argument to the extension method.

method IMethod

The extension method.

useTypeInference bool

Whether to perform type inference for the method. Use false if method is already parameterized (e.g. when type arguments were given explicitly). Otherwise, use true.

outInferredTypes IType[]

If the method is generic and useTypeInference is true, and at least some of the type arguments could be inferred, this parameter receives the inferred type arguments. Since only the type for the first parameter is considered, not all type arguments may be inferred. If an array is returned, any slot with an uninferred type argument will be set to the method's corresponding type parameter.

Returns

bool

IsVariableReferenceWithSameType(ResolveResult, string, out TypeResolveResult)

public bool IsVariableReferenceWithSameType(ResolveResult rr, string identifier, out TypeResolveResult trr)

Parameters

rr ResolveResult
identifier string
trr TypeResolveResult

Returns

bool

LookupSimpleNameOrTypeName(string, IReadOnlyList<IType>, NameLookupMode)

public ResolveResult LookupSimpleNameOrTypeName(string identifier, IReadOnlyList<IType> typeArguments, NameLookupMode lookupMode)

Parameters

identifier string
typeArguments IReadOnlyList<IType>
lookupMode NameLookupMode

Returns

ResolveResult

PopObjectInitializer()

public CSharpResolver PopObjectInitializer()

Returns

CSharpResolver

PushObjectInitializer(ResolveResult)

Pushes the type of the object that is currently being initialized.

public CSharpResolver PushObjectInitializer(ResolveResult initializedObject)

Parameters

initializedObject ResolveResult

Returns

CSharpResolver

ResolveAlias(string)

Looks up an alias (identifier in front of :: operator)

public ResolveResult ResolveAlias(string identifier)

Parameters

identifier string

Returns

ResolveResult

ResolveArrayCreation(IType, ResolveResult[], ResolveResult[])

Resolves an array creation.

public ArrayCreateResolveResult ResolveArrayCreation(IType elementType, ResolveResult[] sizeArguments, ResolveResult[] initializerElements = null)

Parameters

elementType IType

The array element type. Pass null to resolve an implicitly-typed array creation.

sizeArguments ResolveResult[]

The size arguments. The length of this array will be used as the number of dimensions of the array type. The resolver may mutate this array to wrap elements in ConversionResolveResults!

initializerElements ResolveResult[]

The initializer elements. May be null if no array initializer was specified. The resolver may mutate this array to wrap elements in ConversionResolveResults!

Returns

ArrayCreateResolveResult

ResolveArrayCreation(IType, int[], ResolveResult[])

Resolves an array creation.

public ArrayCreateResolveResult ResolveArrayCreation(IType elementType, int[] sizeArguments, ResolveResult[] initializerElements = null)

Parameters

elementType IType

The array element type. Pass null to resolve an implicitly-typed array creation.

sizeArguments int[]

The size arguments. The length of this array will be used as the number of dimensions of the array type. Negative values will be treated as errors.

initializerElements ResolveResult[]

The initializer elements. May be null if no array initializer was specified. The resolver may mutate this array to wrap elements in ConversionResolveResults!

Returns

ArrayCreateResolveResult

ResolveAssignment(AssignmentOperatorType, ResolveResult, ResolveResult)

public ResolveResult ResolveAssignment(AssignmentOperatorType op, ResolveResult lhs, ResolveResult rhs)

Parameters

op AssignmentOperatorType
lhs ResolveResult
rhs ResolveResult

Returns

ResolveResult

ResolveBaseReference()

Resolves 'base'.

public ResolveResult ResolveBaseReference()

Returns

ResolveResult

ResolveBinaryOperator(BinaryOperatorType, ResolveResult, ResolveResult)

public ResolveResult ResolveBinaryOperator(BinaryOperatorType op, ResolveResult lhs, ResolveResult rhs)

Parameters

op BinaryOperatorType
lhs ResolveResult
rhs ResolveResult

Returns

ResolveResult

ResolveCast(IType, ResolveResult)

public ResolveResult ResolveCast(IType targetType, ResolveResult expression)

Parameters

targetType IType
expression ResolveResult

Returns

ResolveResult

ResolveCondition(ResolveResult)

Converts the input to bool using the rules for boolean expressions. That is, operator true is used if a regular conversion to bool is not possible.

public ResolveResult ResolveCondition(ResolveResult input)

Parameters

input ResolveResult

Returns

ResolveResult

ResolveConditionFalse(ResolveResult)

Converts the negated input to bool using the rules for boolean expressions. Computes !(bool)input if the implicit cast to bool is valid; otherwise computes input.operator false().

public ResolveResult ResolveConditionFalse(ResolveResult input)

Parameters

input ResolveResult

Returns

ResolveResult

ResolveConditional(ResolveResult, ResolveResult, ResolveResult)

public ResolveResult ResolveConditional(ResolveResult condition, ResolveResult trueExpression, ResolveResult falseExpression)

Parameters

condition ResolveResult
trueExpression ResolveResult
falseExpression ResolveResult

Returns

ResolveResult

ResolveDefaultValue(IType)

public ResolveResult ResolveDefaultValue(IType type)

Parameters

type IType

Returns

ResolveResult

ResolveForeach(ResolveResult)

public ForEachResolveResult ResolveForeach(ResolveResult expression)

Parameters

expression ResolveResult

Returns

ForEachResolveResult

ResolveIdentifierInObjectInitializer(string)

public ResolveResult ResolveIdentifierInObjectInitializer(string identifier)

Parameters

identifier string

Returns

ResolveResult

ResolveIndexer(ResolveResult, ResolveResult[], string[])

Resolves an indexer access.

public ResolveResult ResolveIndexer(ResolveResult target, ResolveResult[] arguments, string[] argumentNames = null)

Parameters

target ResolveResult

Target expression.

arguments ResolveResult[]

Arguments passed to the indexer. The resolver may mutate this array to wrap elements in ConversionResolveResults!

argumentNames string[]

The argument names. Pass the null string for positional arguments.

Returns

ResolveResult

ArrayAccessResolveResult, InvocationResolveResult, or ErrorResolveResult

ResolveInvocation(ResolveResult, ResolveResult[], string[])

Resolves an invocation.

public ResolveResult ResolveInvocation(ResolveResult target, ResolveResult[] arguments, string[] argumentNames = null)

Parameters

target ResolveResult

The target of the invocation. Usually a MethodGroupResolveResult.

arguments ResolveResult[]

Arguments passed to the method. The resolver may mutate this array to wrap elements in ConversionResolveResults!

argumentNames string[]

The argument names. Pass the null string for positional arguments.

Returns

ResolveResult

InvocationResolveResult or UnknownMethodResolveResult

ResolveMemberAccess(ResolveResult, string, IReadOnlyList<IType>, NameLookupMode)

public ResolveResult ResolveMemberAccess(ResolveResult target, string identifier, IReadOnlyList<IType> typeArguments, NameLookupMode lookupMode = NameLookupMode.Expression)

Parameters

target ResolveResult
identifier string
typeArguments IReadOnlyList<IType>
lookupMode NameLookupMode

Returns

ResolveResult

ResolveObjectCreation(IType, ResolveResult[], string[], bool, IList<ResolveResult>)

Resolves an object creation.

public ResolveResult ResolveObjectCreation(IType type, ResolveResult[] arguments, string[] argumentNames = null, bool allowProtectedAccess = false, IList<ResolveResult> initializerStatements = null)

Parameters

type IType

Type of the object to create.

arguments ResolveResult[]

Arguments passed to the constructor. The resolver may mutate this array to wrap elements in ConversionResolveResults!

argumentNames string[]

The argument names. Pass the null string for positional arguments.

allowProtectedAccess bool

Whether to allow calling protected constructors. This should be false except when resolving constructor initializers.

initializerStatements IList<ResolveResult>

Statements for Objects/Collections initializer. InitializerStatements

Returns

ResolveResult

InvocationResolveResult or ErrorResolveResult

ResolvePrimitive(object)

public ResolveResult ResolvePrimitive(object value)

Parameters

value object

Returns

ResolveResult

ResolveSimpleName(string, IReadOnlyList<IType>, bool)

public ResolveResult ResolveSimpleName(string identifier, IReadOnlyList<IType> typeArguments, bool isInvocationTarget = false)

Parameters

identifier string
typeArguments IReadOnlyList<IType>
isInvocationTarget bool

Returns

ResolveResult

ResolveSizeOf(IType)

Resolves 'sizeof(type)'.

public ResolveResult ResolveSizeOf(IType type)

Parameters

type IType

Returns

ResolveResult

ResolveThisReference()

Resolves 'this'.

public ResolveResult ResolveThisReference()

Returns

ResolveResult

ResolveTypeOf(IType)

public ResolveResult ResolveTypeOf(IType referencedType)

Parameters

referencedType IType

Returns

ResolveResult

ResolveUnaryOperator(UnaryOperatorType, ResolveResult)

public ResolveResult ResolveUnaryOperator(UnaryOperatorType op, ResolveResult expression)

Parameters

op UnaryOperatorType
expression ResolveResult

Returns

ResolveResult

WithCheckForOverflow(bool)

Sets whether the current context is checked.

public CSharpResolver WithCheckForOverflow(bool checkForOverflow)

Parameters

checkForOverflow bool

Returns

CSharpResolver

WithCurrentMember(IMember)

Sets the current member definition.

public CSharpResolver WithCurrentMember(IMember member)

Parameters

member IMember

Returns

CSharpResolver

Remarks

Don't forget to also set CurrentTypeDefinition when setting CurrentMember; setting one of the properties does not automatically set the other.

WithCurrentTypeDefinition(ITypeDefinition)

Sets the current type definition.

public CSharpResolver WithCurrentTypeDefinition(ITypeDefinition typeDefinition)

Parameters

typeDefinition ITypeDefinition

Returns

CSharpResolver

WithCurrentUsingScope(ResolvedUsingScope)

Sets the current using scope that is used to look up identifiers as class names.

public CSharpResolver WithCurrentUsingScope(ResolvedUsingScope usingScope)

Parameters

usingScope ResolvedUsingScope

Returns

CSharpResolver

WithIsWithinLambdaExpression(bool)

Sets whether the resolver is currently within a lambda expression.

public CSharpResolver WithIsWithinLambdaExpression(bool isWithinLambdaExpression)

Parameters

isWithinLambdaExpression bool

Returns

CSharpResolver