StorytellerDocGen.Todos.TodoTask.ReadTasks C# (CSharp) Method

ReadTasks() public static method

public static ReadTasks ( Topic topic ) : IEnumerable
topic StorytellerDocGen.Topics.Topic
return IEnumerable
        public static IEnumerable<TodoTask> ReadTasks(Topic topic)
        {
            var i = 0;
            var regex = @"TODO\((.*?)\)";

            using (var stream = new FileStream(topic.File, FileMode.Open))
            {
                using (StreamReader streamReader = new StreamReader(stream))
                {
                    string text;
                    while ((text = streamReader.ReadLine()) != null)
                    {
                        i++;

                        if (text.Contains("TODO"))
                        {
                            var matches = Regex.Matches(text, regex);
                            foreach (Match match in matches)
                            {
                                var message = match.Groups[1].Value.Trim();
                                yield return new TodoTask
                                {
                                    File = topic.File,
                                    Key = topic.Key,
                                    Line = i,
                                    Message = message
                                };
                            }

                            if (matches.Count == 0)
                            {
                                var index = text.IndexOf("TODO");
                                var message = text.Substring(index + 4).Trim();

                                yield return new TodoTask
                                {
                                    File = topic.File,
                                    Key = topic.Key,
                                    Line = i,
                                    Message = message
                                };
                            }
                        }
                    }
                }
            }

        }