private BoundExpression GenerateDisposeCall(SyntaxNode syntax, BoundExpression disposedExpression, MethodSymbol methodOpt, AwaitableInfo awaitOpt, SyntaxToken awaitKeyword) { Debug.Assert(awaitOpt is null || awaitKeyword != default); // If we don't have an explicit dispose method, try and get the special member for IDiposable/IAsyncDisposable if (methodOpt is null) { if (awaitOpt is null) { // IDisposable.Dispose() Binder.TryGetSpecialTypeMember(_compilation, SpecialMember.System_IDisposable__Dispose, syntax, _diagnostics, out methodOpt); } else { // IAsyncDisposable.DisposeAsync() TryGetWellKnownTypeMember(syntax: null, WellKnownMember.System_IAsyncDisposable__DisposeAsync, out methodOpt, location: awaitKeyword.GetLocation()); } } BoundExpression disposeCall; if (methodOpt is null) { disposeCall = new BoundBadExpression(syntax, LookupResultKind.NotInvocable, ImmutableArray <Symbol> .Empty, ImmutableArray.Create(disposedExpression), ErrorTypeSymbol.UnknownResultType); } else { var receiver = methodOpt.IsExtensionMethod ? null : disposedExpression; var args = methodOpt.IsExtensionMethod ? ImmutableArray.Create(disposedExpression) : ImmutableArray <BoundExpression> .Empty; var refs = methodOpt.IsExtensionMethod && !methodOpt.ParameterRefKinds.IsDefaultOrEmpty ? ImmutableArray.Create(methodOpt.ParameterRefKinds[0]) : default; disposeCall = MakeCall(syntax: syntax, rewrittenReceiver: receiver, method: methodOpt, rewrittenArguments: args, argumentRefKindsOpt: refs, expanded: methodOpt.HasParamsParameter(), invokedAsExtensionMethod: methodOpt.IsExtensionMethod, argsToParamsOpt: default,
/// <summary> /// Synthesize a call `expression.Method()`, but with some extra smarts to handle extension methods, and to fill-in optional and params parameters. /// </summary> private BoundExpression MakeCallWithNoExplicitArgument(SyntaxNode syntax, BoundExpression expression, MethodSymbol method) { var receiver = method.IsExtensionMethod ? null : expression; var args = method.IsExtensionMethod ? ImmutableArray.Create(expression) : ImmutableArray <BoundExpression> .Empty; var refKinds = method.IsExtensionMethod && !method.ParameterRefKinds.IsDefaultOrEmpty ? ImmutableArray.Create(method.ParameterRefKinds[0]) : default; BoundExpression disposeCall = MakeCall(syntax: syntax, rewrittenReceiver: receiver, method: method, rewrittenArguments: args, argumentRefKindsOpt: refKinds, expanded: method.HasParamsParameter(), invokedAsExtensionMethod: method.IsExtensionMethod, argsToParamsOpt: default,