Beispiel #1
0
            internal AsyncForwardEntryPoint(
                CSharpCompilation compilation,
                NamedTypeSymbol containingType,
                MethodSymbol userMain
                ) : base(containingType)
            {
                // There should be no way for a userMain to be passed in unless it already passed the
                // parameter checks for determining entrypoint validity.
                Debug.Assert(userMain.ParameterCount == 0 || userMain.ParameterCount == 1);

                UserMain = userMain;
                _userMainReturnTypeSyntax = userMain.ExtractReturnTypeSyntax();
                var binder = compilation.GetBinder(_userMainReturnTypeSyntax);

                _parameters = SynthesizedParameterSymbol.DeriveParameters(userMain, this);

                var arguments = Parameters.SelectAsArray(
                    (p, s) => (BoundExpression) new BoundParameter(s, p, p.Type),
                    _userMainReturnTypeSyntax
                    );

                // Main(args) or Main()
                BoundCall userMainInvocation = new BoundCall(
                    syntax: _userMainReturnTypeSyntax,
                    receiverOpt: null,
                    method: userMain,
                    arguments: arguments,
                    argumentNamesOpt: default(ImmutableArray <string>),
                    argumentRefKindsOpt: default(ImmutableArray <RefKind>),
                    isDelegateCall: false,
                    expanded: false,
                    invokedAsExtensionMethod: false,
                    argsToParamsOpt: default(ImmutableArray <int>),
                    defaultArguments: default(BitVector),
                    resultKind: LookupResultKind.Viable,
                    type: userMain.ReturnType
                    )
                {
                    WasCompilerGenerated = true
                };

                // The diagnostics that would be produced here will already have been captured and returned.
                var success = binder.GetAwaitableExpressionInfo(
                    userMainInvocation,
                    out _getAwaiterGetResultCall !,
                    _userMainReturnTypeSyntax,
                    BindingDiagnosticBag.Discarded
                    );

                Debug.Assert(
                    ReturnType.IsVoidType() || ReturnType.SpecialType == SpecialType.System_Int32
                    );
            }