Beispiel #1
0
        public Value For()
        {
            using var assistant = new ParameterAssistant(Arguments);
            var block = assistant.Block();

            if (block != null)
            {
                assistant.LoopParameters();
                Func <string, bool> func = _ => true;
                if (filter.IsNotEmpty())
                {
                    func = l => l.IndexOf(filter, StringComparison.Ordinal) > -1;
                }
                else if (lambda != null)
                {
                    func = l => lambda.Evaluate(new Arguments(l)).IsTrue;
                }

                using var stream = new FileStream(fileName, FileMode.Open, FileAccess.Read);
                using var reader = new StreamReader(stream);
                string line;
                var    index = 0;
                while ((line = reader.ReadLine()) != null)
                {
                    if (func(line))
                    {
                        assistant.SetLoopParameters(line, index++);
                        block.Evaluate();
                        var signal = ParameterAssistant.Signal();
                        if (signal == ParameterAssistant.SignalType.Breaking)
                        {
                            break;
                        }

                        switch (signal)
                        {
                        case ParameterAssistant.SignalType.Continuing:
                            continue;

                        case ParameterAssistant.SignalType.ReturningNull:
                            return(null);
                        }
                    }
                }

                return(null);
            }

            return(null);
        }
Beispiel #2
0
        public Value For()
        {
            using var assistant = new ParameterAssistant(Arguments);
            var block = assistant.Block();

            if (block != null)
            {
                assistant.LoopParameters();
                if (filter.IsEmpty())
                {
                    using var reader = new StringReader(text);
                    string line;
                    var    index = 0;
                    while ((line = reader.ReadLine()) != null)
                    {
                        assistant.SetLoopParameters(line, index++);
                        block.Evaluate();
                        var signal = ParameterAssistant.Signal();
                        if (signal == ParameterAssistant.SignalType.Breaking)
                        {
                            break;
                        }

                        switch (signal)
                        {
                        case ParameterAssistant.SignalType.ReturningNull:
                            return(null);

                        case ParameterAssistant.SignalType.Continuing:
                            continue;
                        }
                    }
                }
                else
                {
                    using var reader = new StringReader(text);
                    string line;
                    var    index = 0;
                    while ((line = reader.ReadLine()) != null)
                    {
                        if (line.IndexOf(filter, StringComparison.Ordinal) > -1)
                        {
                            assistant.SetLoopParameters(line, index++);
                            block.Evaluate();
                            var signal = ParameterAssistant.Signal();
                            if (signal == ParameterAssistant.SignalType.Breaking)
                            {
                                break;
                            }

                            switch (signal)
                            {
                            case ParameterAssistant.SignalType.ReturningNull:
                                return(null);

                            case ParameterAssistant.SignalType.Continuing:
                                continue;
                            }
                        }
                    }
                }

                return(null);
            }

            return(null);
        }