public IEnumerable <StatementSyntax> GenerateNotifyForSuccessfulInvokeStatements(TypePositionInfo info, StubCodeContext context) => _innerMarshaller.GenerateNotifyForSuccessfulInvokeStatements(info, context);
        public IEnumerable <StatementSyntax> Generate(TypePositionInfo info, StubCodeContext context)
        {
            // Although custom native type marshalling doesn't support [In] or [Out] by value marshalling,
            // other marshallers that wrap this one might, so we handle the correct cases here.
            switch (context.CurrentStage)
            {
            case StubCodeContext.Stage.Setup:
                return(_nativeTypeMarshaller.GenerateSetupStatements(info, context));

            case StubCodeContext.Stage.Marshal:
                if (!info.IsManagedReturnPosition && info.RefKind != RefKind.Out)
                {
                    return(_nativeTypeMarshaller.GenerateMarshalStatements(info, context));
                }
                break;

            case StubCodeContext.Stage.Pin:
                if (!info.IsByRef || info.RefKind == RefKind.In)
                {
                    return(_nativeTypeMarshaller.GeneratePinStatements(info, context));
                }
                break;

            case StubCodeContext.Stage.PinnedMarshal:
                if (!info.IsManagedReturnPosition && info.RefKind != RefKind.Out)
                {
                    return(_nativeTypeMarshaller.GeneratePinnedMarshalStatements(info, context));
                }
                break;

            case StubCodeContext.Stage.NotifyForSuccessfulInvoke:
                if (!info.IsManagedReturnPosition && info.RefKind != RefKind.Out)
                {
                    return(_nativeTypeMarshaller.GenerateNotifyForSuccessfulInvokeStatements(info, context));
                }
                break;

            case StubCodeContext.Stage.UnmarshalCapture:
                if (info.IsManagedReturnPosition || (info.IsByRef && info.RefKind != RefKind.In))
                {
                    return(_nativeTypeMarshaller.GenerateUnmarshalCaptureStatements(info, context));
                }
                break;

            case StubCodeContext.Stage.Unmarshal:
                if (info.IsManagedReturnPosition || (info.IsByRef && info.RefKind != RefKind.In) ||
                    (_enableByValueContentsMarshalling && !info.IsByRef && info.ByValueContentsMarshalKind.HasFlag(ByValueContentsMarshalKind.Out)))
                {
                    return(_nativeTypeMarshaller.GenerateUnmarshalStatements(info, context));
                }
                break;

            case StubCodeContext.Stage.GuaranteedUnmarshal:
                if (info.IsManagedReturnPosition ||
                    (info.IsByRef && info.RefKind != RefKind.In) ||
                    (_enableByValueContentsMarshalling && !info.IsByRef && info.ByValueContentsMarshalKind.HasFlag(ByValueContentsMarshalKind.Out)))
                {
                    return(_nativeTypeMarshaller.GenerateGuaranteedUnmarshalStatements(info, context));
                }
                break;

            case StubCodeContext.Stage.Cleanup:
                return(_nativeTypeMarshaller.GenerateCleanupStatements(info, context));

            default:
                break;
            }

            return(Array.Empty <StatementSyntax>());
        }