2323using System . Linq ;
2424
2525using ICSharpCode . Decompiler . CSharp . Resolver ;
26- using ICSharpCode . Decompiler . CSharp . TypeSystem ;
2726using ICSharpCode . Decompiler . Semantics ;
2827using ICSharpCode . Decompiler . TypeSystem ;
2928using ICSharpCode . Decompiler . Util ;
@@ -211,8 +210,7 @@ bool IsPartOfInitializer(InstructionCollection<ILInstruction> instructions, int
211210 possibleIndexVariables . Add ( stloc . Variable , ( stloc . ChildIndex , stloc . Value ) ) ;
212211 return true ;
213212 }
214- var resolveContext = new CSharpTypeResolveContext ( context . TypeSystem . MainModule , context . UsingScope ) ;
215- ( var kind , var newPath , var values , var targetVariable ) = AccessPathElement . GetAccessPath ( instructions [ pos ] , rootType , context . Settings , resolveContext , possibleIndexVariables ) ;
213+ ( var kind , var newPath , var values , var targetVariable ) = AccessPathElement . GetAccessPath ( instructions [ pos ] , rootType , context . Settings , context . CSharpResolver , possibleIndexVariables ) ;
216214 if ( kind == AccessPathKind . Invalid || target != targetVariable )
217215 return false ;
218216 // Treat last element separately:
@@ -302,7 +300,7 @@ public AccessPathElement(OpCode opCode, IMember member, ILInstruction[]? indices
302300
303301 public static ( AccessPathKind Kind , List < AccessPathElement > Path , List < ILInstruction > ? Values , ILVariable ? Target ) GetAccessPath (
304302 ILInstruction instruction , IType rootType , DecompilerSettings ? settings = null ,
305- CSharpTypeResolveContext ? resolveContext = null ,
303+ CSharpResolver ? resolver = null ,
306304 Dictionary < ILVariable , ( int Index , ILInstruction Value ) > ? possibleIndexVariables = null )
307305 {
308306 List < AccessPathElement > path = new List < AccessPathElement > ( ) ;
@@ -319,7 +317,7 @@ public static (AccessPathKind Kind, List<AccessPathElement> Path, List<ILInstruc
319317 if ( ! ( call is CallVirt || call is Call ) )
320318 goto default ;
321319 method = call . Method ;
322- if ( resolveContext != null && ! IsMethodApplicable ( method , call . Arguments , rootType , resolveContext , settings ) )
320+ if ( resolver != null && ! IsMethodApplicable ( method , call . Arguments , rootType , resolver , settings ) )
323321 goto default ;
324322 inst = call . Arguments [ 0 ] ;
325323 if ( inst is LdObjIfRef ldObjIfRef )
@@ -329,7 +327,7 @@ public static (AccessPathKind Kind, List<AccessPathElement> Path, List<ILInstruc
329327 if ( method . IsAccessor )
330328 {
331329 if ( method . AccessorOwner is IProperty property &&
332- ! CanBeUsedInInitializer ( property , resolveContext , kind ) )
330+ ! CanBeUsedInInitializer ( property , resolver , kind ) )
333331 {
334332 goto default ;
335333 }
@@ -433,22 +431,22 @@ public static (AccessPathKind Kind, List<AccessPathElement> Path, List<ILInstruc
433431 return ( kind , path , values , target ) ;
434432 }
435433
436- private static bool CanBeUsedInInitializer ( IProperty property , CSharpTypeResolveContext ? resolveContext , AccessPathKind kind )
434+ private static bool CanBeUsedInInitializer ( IProperty property , ITypeResolveContext ? resolveContext , AccessPathKind kind )
437435 {
438436 if ( property . CanSet && ( property . Accessibility == property . Setter . Accessibility || IsAccessorAccessible ( property . Setter , resolveContext ) ) )
439437 return true ;
440438 return kind != AccessPathKind . Setter ;
441439 }
442440
443- private static bool IsAccessorAccessible ( IMethod setter , CSharpTypeResolveContext ? resolveContext )
441+ private static bool IsAccessorAccessible ( IMethod setter , ITypeResolveContext ? resolveContext )
444442 {
445443 if ( resolveContext == null )
446444 return true ;
447445 var lookup = new MemberLookup ( resolveContext . CurrentTypeDefinition , resolveContext . CurrentModule ) ;
448446 return lookup . IsAccessible ( setter , allowProtectedAccess : setter . DeclaringTypeDefinition == resolveContext . CurrentTypeDefinition ) ;
449447 }
450448
451- static bool IsMethodApplicable ( IMethod method , IReadOnlyList < ILInstruction > arguments , IType rootType , CSharpTypeResolveContext resolveContext , DecompilerSettings ? settings )
449+ static bool IsMethodApplicable ( IMethod method , IReadOnlyList < ILInstruction > arguments , IType rootType , CSharpResolver resolver , DecompilerSettings ? settings )
452450 {
453451 if ( method . IsStatic && ! method . IsExtensionMethod )
454452 return false ;
@@ -460,7 +458,7 @@ static bool IsMethodApplicable(IMethod method, IReadOnlyList<ILInstruction> argu
460458 {
461459 if ( settings ? . ExtensionMethodsInCollectionInitializers == false )
462460 return false ;
463- if ( ! CSharp . Transforms . IntroduceExtensionMethods . CanTransformToExtensionMethodCall ( method , resolveContext , ignoreTypeArguments : true ) )
461+ if ( ! resolver . CanTransformToExtensionMethodCall ( method , ignoreTypeArguments : true ) )
464462 return false ;
465463 }
466464 var targetType = GetReturnTypeFromInstruction ( arguments [ 0 ] ) ?? rootType ;
@@ -476,7 +474,7 @@ bool CanInferTypeArgumentsFromParameters(IMethod method)
476474 return true ;
477475 // always use unspecialized member, otherwise type inference fails
478476 method = ( IMethod ) method . MemberDefinition ;
479- new TypeInference ( resolveContext . Compilation )
477+ new TypeInference ( resolver . Compilation )
480478 . InferTypeArguments (
481479 method . TypeParameters ,
482480 // TODO : this is not entirely correct... we need argument type information to resolve Add methods properly
0 commit comments