private void EmitDebugLog(ILGenerator ilGenerator, string message)
 {
     if (LoggerKey != null)
     {
         FluentActionLoggers.PushDebugLogOntoStack(ilGenerator, LoggerKey, $"[MoveNext] {message}");
     }
 }
        public static AsyncStateMachineTypeBuilder Create(
            TypeBuilder parentTypeBuilder,
            FluentActionDefinition fluentActionDefinition,
            ILogger logger = null)
        {
            var builder = new AsyncStateMachineTypeBuilder
            {
                ParentType = parentTypeBuilder,
                ReturnType = fluentActionDefinition.Handlers.Last().ReturnType,
                Logger     = logger
            };

            if (logger != null)
            {
                builder.LoggerKey = FluentActionLoggers.Add(logger);
            }

            builder.DefineTypeAndDefaultConstructor(parentTypeBuilder);
            builder.DefineFields(fluentActionDefinition);
            builder.DefineMoveNextMethod(fluentActionDefinition);
            builder.DefineSetStateMachineMethod();

            return(builder);
        }