本文整理汇总了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;
}
示例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();
}
}
示例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");
}
}
示例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);
}
示例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;
}
示例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;
}