public IEnumerable Create()

in TeamCity.CSharpInteractive/CodeSourceCommandFactory.cs [25:88]


    public IEnumerable<ICommand> Create(ICodeSource codeSource)
    {
        var sb = new StringBuilder();
        using var codeEnumerator = codeSource.GetEnumerator();
        while (codeEnumerator.MoveNext())
        {
            var code = codeEnumerator.Current;
            if (code == null)
            {
                foreach (var command in CreateCommands(codeSource, sb))
                {
                    yield return command;
                }

                continue;
            }

            foreach (var line in code.Split(System.Environment.NewLine))
            {
                var trimmedLine = line.Trim();
                _log.Trace(() => new[] {new Text($"Line: \"{trimmedLine}\".")});
                if (trimmedLine.StartsWith("#"))
                {
                    var hasReplCommand = false;
                    foreach (var replCommandFactory in _replCommandFactories)
                    {
                        var commands = replCommandFactory.Create(trimmedLine).ToArray();
                        _log.Trace(() => new[] {new Text($"REPL commands count: {commands.Length}.")});
                        if (!commands.Any())
                        {
                            continue;
                        }

                        foreach (var command in CreateCommands(codeSource, sb))
                        {
                            yield return command;
                        }

                        hasReplCommand = true;
                        foreach (var command in commands)
                        {
                            yield return command;
                        }

                        break;
                    }

                    if (!hasReplCommand)
                    {
                        sb.AppendLine(line);
                    }
                }
                else
                {
                    sb.AppendLine(line);
                }
            }
        }

        foreach (var command in CreateCommands(codeSource, sb))
        {
            yield return command;
        }
    }