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
Compilation
Gets the compilation used by the resolver.
public ICompilation Compilation { get; }
Property Value
CurrentMember
Gets the current member definition that is used to look up identifiers as parameters or type parameters.
public IMember CurrentMember { get; }
Property Value
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
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
CurrentTypeDefinition
Gets the current type definition.
public ITypeDefinition CurrentTypeDefinition { get; }
Property Value
CurrentTypeResolveContext
Gets the current type resolve context.
public CSharpTypeResolveContext CurrentTypeResolveContext { get; }
Property Value
CurrentUsingScope
Gets the current using scope that is used to look up identifiers as class names.
public ResolvedUsingScope CurrentUsingScope { get; }
Property Value
IsInObjectInitializer
Gets whether this context is within an object initializer.
public bool IsInObjectInitializer { get; }
Property Value
IsWithinLambdaExpression
Gets whether the resolver is currently within a lambda expression or anonymous method.
public bool IsWithinLambdaExpression { get; }
Property Value
LocalVariables
Gets all currently visible local variables and lambda parameters. Does not include method parameters.
public IEnumerable<IVariable> LocalVariables { get; }
Property Value
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
CreateMemberLookup()
Creates a MemberLookup instance using this resolver's settings.
public MemberLookup CreateMemberLookup()
Returns
CreateMemberLookup(NameLookupMode)
Creates a MemberLookup instance using this resolver's settings.
public MemberLookup CreateMemberLookup(NameLookupMode lookupMode)
Parameters
lookupMode
NameLookupMode
Returns
GetDefaultValue(IType)
public static object GetDefaultValue(IType type)
Parameters
type
IType
Returns
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
ITypeType of the 'this' argument
name
stringName 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
boolSpecifies 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 iftypeArguments
is non-empty.
Returns
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
stringName 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
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
Returns
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
ITypeTarget type that is passed as first argument to the extension method.
method
IMethodThe extension method.
useTypeInference
boolWhether to perform type inference for the method. Use
false
ifmethod
is already parameterized (e.g. when type arguments were given explicitly). Otherwise, usetrue
.outInferredTypes
IType[]If the method is generic and
useTypeInference
istrue
, 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
IsVariableReferenceWithSameType(ResolveResult, string, out TypeResolveResult)
public bool IsVariableReferenceWithSameType(ResolveResult rr, string identifier, out TypeResolveResult trr)
Parameters
rr
ResolveResultidentifier
stringtrr
TypeResolveResult
Returns
LookupSimpleNameOrTypeName(string, IReadOnlyList<IType>, NameLookupMode)
public ResolveResult LookupSimpleNameOrTypeName(string identifier, IReadOnlyList<IType> typeArguments, NameLookupMode lookupMode)
Parameters
identifier
stringtypeArguments
IReadOnlyList<IType>lookupMode
NameLookupMode
Returns
PopObjectInitializer()
public CSharpResolver PopObjectInitializer()
Returns
PushObjectInitializer(ResolveResult)
Pushes the type of the object that is currently being initialized.
public CSharpResolver PushObjectInitializer(ResolveResult initializedObject)
Parameters
initializedObject
ResolveResult
Returns
ResolveAlias(string)
Looks up an alias (identifier in front of :: operator)
public ResolveResult ResolveAlias(string identifier)
Parameters
identifier
string
Returns
ResolveArrayCreation(IType, ResolveResult[], ResolveResult[])
Resolves an array creation.
public ArrayCreateResolveResult ResolveArrayCreation(IType elementType, ResolveResult[] sizeArguments, ResolveResult[] initializerElements = null)
Parameters
elementType
ITypeThe 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
ResolveArrayCreation(IType, int[], ResolveResult[])
Resolves an array creation.
public ArrayCreateResolveResult ResolveArrayCreation(IType elementType, int[] sizeArguments, ResolveResult[] initializerElements = null)
Parameters
elementType
ITypeThe 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
ResolveAssignment(AssignmentOperatorType, ResolveResult, ResolveResult)
public ResolveResult ResolveAssignment(AssignmentOperatorType op, ResolveResult lhs, ResolveResult rhs)
Parameters
op
AssignmentOperatorTypelhs
ResolveResultrhs
ResolveResult
Returns
ResolveBaseReference()
Resolves 'base'.
public ResolveResult ResolveBaseReference()
Returns
ResolveBinaryOperator(BinaryOperatorType, ResolveResult, ResolveResult)
public ResolveResult ResolveBinaryOperator(BinaryOperatorType op, ResolveResult lhs, ResolveResult rhs)
Parameters
op
BinaryOperatorTypelhs
ResolveResultrhs
ResolveResult
Returns
ResolveCast(IType, ResolveResult)
public ResolveResult ResolveCast(IType targetType, ResolveResult expression)
Parameters
targetType
ITypeexpression
ResolveResult
Returns
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
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
ResolveConditional(ResolveResult, ResolveResult, ResolveResult)
public ResolveResult ResolveConditional(ResolveResult condition, ResolveResult trueExpression, ResolveResult falseExpression)
Parameters
condition
ResolveResulttrueExpression
ResolveResultfalseExpression
ResolveResult
Returns
ResolveDefaultValue(IType)
public ResolveResult ResolveDefaultValue(IType type)
Parameters
type
IType
Returns
ResolveForeach(ResolveResult)
public ForEachResolveResult ResolveForeach(ResolveResult expression)
Parameters
expression
ResolveResult
Returns
ResolveIdentifierInObjectInitializer(string)
public ResolveResult ResolveIdentifierInObjectInitializer(string identifier)
Parameters
identifier
string
Returns
ResolveIndexer(ResolveResult, ResolveResult[], string[])
Resolves an indexer access.
public ResolveResult ResolveIndexer(ResolveResult target, ResolveResult[] arguments, string[] argumentNames = null)
Parameters
target
ResolveResultTarget 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
ResolveResultThe 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
ResolveResultidentifier
stringtypeArguments
IReadOnlyList<IType>lookupMode
NameLookupMode
Returns
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
ITypeType 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
boolWhether 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
ResolveSimpleName(string, IReadOnlyList<IType>, bool)
public ResolveResult ResolveSimpleName(string identifier, IReadOnlyList<IType> typeArguments, bool isInvocationTarget = false)
Parameters
identifier
stringtypeArguments
IReadOnlyList<IType>isInvocationTarget
bool
Returns
ResolveSizeOf(IType)
Resolves 'sizeof(type)'.
public ResolveResult ResolveSizeOf(IType type)
Parameters
type
IType
Returns
ResolveThisReference()
Resolves 'this'.
public ResolveResult ResolveThisReference()
Returns
ResolveTypeOf(IType)
public ResolveResult ResolveTypeOf(IType referencedType)
Parameters
referencedType
IType
Returns
ResolveUnaryOperator(UnaryOperatorType, ResolveResult)
public ResolveResult ResolveUnaryOperator(UnaryOperatorType op, ResolveResult expression)
Parameters
op
UnaryOperatorTypeexpression
ResolveResult
Returns
WithCheckForOverflow(bool)
Sets whether the current context is checked
.
public CSharpResolver WithCheckForOverflow(bool checkForOverflow)
Parameters
checkForOverflow
bool
Returns
WithCurrentMember(IMember)
Sets the current member definition.
public CSharpResolver WithCurrentMember(IMember member)
Parameters
member
IMember
Returns
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
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
WithIsWithinLambdaExpression(bool)
Sets whether the resolver is currently within a lambda expression.
public CSharpResolver WithIsWithinLambdaExpression(bool isWithinLambdaExpression)
Parameters
isWithinLambdaExpression
bool