当前位置: 首页>>代码示例>>C#>>正文


C# StringReader.ReadLines方法代码示例

本文整理汇总了C#中System.IO.StringReader.ReadLines方法的典型用法代码示例。如果您正苦于以下问题:C# StringReader.ReadLines方法的具体用法?C# StringReader.ReadLines怎么用?C# StringReader.ReadLines使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.IO.StringReader的用法示例。


在下文中一共展示了StringReader.ReadLines方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Interpret

 public IEnumerable<Project> Interpret(string dslText)
 {
     var reader = new StringReader(dslText);
     Project project = null;
     foreach (var line in reader.ReadLines().Select( s => s.Replace("\n", "")))
     {
         if(line.EndsWith(":"))
         {
             if(project != null)
             {
                 yield return project;
             }
             project = new Project(line);
         }
         else if(project != null && Regex.Match(line, @"^-\s*").Success)
         {
             project.AddTask(new TaskItem(line));
         }
         else if(project != null)
         {
             if (project.Tasks.Count == 0)
                 project.AddNote(line);
             else
                 project.Tasks.Last().AddNote(line);
         }
     }
     yield return project;
 }
开发者ID:Ball,项目名称:DslExamples,代码行数:28,代码来源:DelimiterParser.cs

示例2: GetExpected

        static string[][] GetExpected(string testCase)
        {
            using (var ss = new StringReader(testCase ?? ""))
            {
                var lines = ss.ReadLines().ToArray();

                return lines.Select(l => l.Split('\t')).ToArray();
            }
        }
开发者ID:mrange,项目名称:T4Include,代码行数:9,代码来源:TestsFor_LineToObjectExtensions.cs

示例3: Test_ReadLines

        public void Test_ReadLines()
        {
            const string testCase = "A\r\nB\rC\nD\n\rE\n\nF\r\rG\r\r\nH\n\r\nI\r\n\rJ\n\n\rK\r\n";

            using (var stringReader = new StringReader(testCase))
            {
                var expected = stringReader.ReadLines().ToArray();
                var found = testCase.ReadLines().Select(ss => ss.ToString()).ToArray();

                TestFor.Equality(expected.Length + 1, found.Length, "ReadLines in the presence of ending linebreak should read one line extra compared to StringReader");
                TestFor.SequenceEquality(expected, found.Take(expected.Length), "ReadLines should otherwise match StringReader behavior");
            }
        }
开发者ID:mrange,项目名称:T4Include,代码行数:13,代码来源:TestsFor_SubString.cs

示例4: TestReadLines

        public void TestReadLines()
        {
            var text = @"line1
            line2
            line3
            ";
              var expectedLines = new[] {
            "line1",
            "line2",
            "line3",
              };

              var reader = new StringReader(text);
              var index = 0;

              foreach (var line in reader.ReadLines()) {
            Assert.AreEqual(expectedLines[index++], line);
              }

              Assert.AreEqual(expectedLines.Length, index);
        }
开发者ID:pengyancai,项目名称:cs-util,代码行数:21,代码来源:TextReaderExtensions.cs

示例5: GetBlame

        public BlameModel GetBlame(string path)
        {
            string referenceName;
            var commit = GetCommitByPath(ref path, out referenceName);
            if (commit == null)
                return null;

            var entry = commit[path];
            if (entry == null || entry.TargetType != TreeEntryTargetType.Blob)
                return null;

            var blob = (Blob)entry.Target;
            var bytes = blob.GetContentStream().ToBytes();
            var encoding = FileHelper.DetectEncoding(bytes, CpToEncoding(commit.Encoding), _i18n.Value);
            if (encoding == null)
                return null;

            var code = FileHelper.ReadToEnd(bytes, encoding);
            var reader = new StringReader(code);

            var hunks = GitCache.Get<BlameHunkModel[]>(blob.Sha, "blame");
            if (hunks == null)
            {
                var blame = _repository.Blame(path, new BlameOptions { StartingAt = commit });
                hunks = blame.Select(s => new BlameHunkModel
                {
                    Code = reader.ReadLines(s.LineCount),
                    StartLine = s.FinalStartLineNumber,
                    EndLine = s.LineCount,
                    MessageShort = s.FinalCommit.MessageShort.RepetitionIfEmpty(NoCommitMessage),
                    Sha = s.FinalCommit.Sha,
                    Author = s.FinalCommit.Author.Name,
                    AuthorEmail = s.FinalCommit.Author.Email,
                    AuthorDate = s.FinalCommit.Author.When,
                })
                .ToArray();
                GitCache.Set(blob.Sha, "blame", hunks);
            }

            var model = new BlameModel
            {
                ReferenceName = referenceName,
                Sha = commit.Sha,
                Path = string.IsNullOrEmpty(path) ? "" : path,
                SizeString = FileHelper.GetSizeString(blob.Size),
                Brush = FileHelper.GetBrush(path),
                Hunks = hunks,
                BranchSelector = GetBranchSelectorModel(referenceName, commit.Sha, path),
                PathBar = new PathBarModel
                {
                    Name = Name,
                    Action = "Tree",
                    Path = path,
                    ReferenceName = referenceName,
                    ReferenceSha = commit.Sha,
                    HideLastSlash = true,
                },
            };

            return model;
        }
开发者ID:supuy-ruby,项目名称:GitCandy,代码行数:61,代码来源:GitService.cs

示例6: ReadLines

 public static IEnumerable<string> ReadLines(this string s)
 {
     using (var r = new StringReader(s))
         foreach (var line in r.ReadLines())
             yield return line;
 }
开发者ID:ronnieoverby,项目名称:UniqueNamespace.SqlBuilder,代码行数:6,代码来源:Extensions.cs


注:本文中的System.IO.StringReader.ReadLines方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。