本文整理汇总了C#中TextReader.TryReadExpected方法的典型用法代码示例。如果您正苦于以下问题:C# TextReader.TryReadExpected方法的具体用法?C# TextReader.TryReadExpected怎么用?C# TextReader.TryReadExpected使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TextReader
的用法示例。
在下文中一共展示了TextReader.TryReadExpected方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ParseEntry
private void ParseEntry(TextReader reader, int lineNumber)
{
if (!reader.TryReadExpected("STR_"))
{
_logger.LogError(lineNumber, "Expected line to start with 'STR_'");
return;
}
string identifier = reader.ReadString(4);
string[] validIdentifiers = null;
switch (_currentEntryType) {
case LanguageEntryType.ObjectOverride:
validIdentifiers = ObjectOverrideIdentifiers;
break;
case LanguageEntryType.ScenarioOverride:
validIdentifiers = ScenarioOverrideIdentifiers;
break;
}
if (validIdentifiers == null)
{
ushort index;
if (!UInt16.TryParse(identifier, out index))
{
_logger.LogError(lineNumber, $"String identifier must be between {UInt16.MinValue} and {UInt16.MaxValue}");
return;
}
}
else
{
if (!validIdentifiers.Contains(identifier))
{
_logger.LogError(lineNumber, $"Invalid identifier '{identifier}'");
}
if (!_groupItemIdentifiers.Add(identifier))
{
_logger.LogWarning(lineNumber, $"Entry '{identifier}' already set.");
}
}
ParseWhitespace(reader, lineNumber, 4);
if (!reader.TryReadExpected(":"))
{
_logger.LogError(lineNumber, "Expected ':' after identifier");
}
string text = reader.ReadToEnd();
}
示例2: ParseGroup
private string ParseGroup(TextReader reader, int lineNumber, char openCharacter, char closeCharacter)
{
if (!reader.TryReadExpected(openCharacter.ToString()))
{
_logger.LogError(lineNumber, $"Expected '{openCharacter}'");
return null;
}
var sb = new StringBuilder();
char c;
bool missingEndBracket = true;
while (reader.TryRead(out c))
{
if (c == closeCharacter)
{
missingEndBracket = false;
break;
}
else
{
sb.Append(c);
}
}
if (missingEndBracket)
{
_logger.LogError(lineNumber, $"Group name did not end with '{closeCharacter}'");
return null;
}
ParseWhitespace(reader, lineNumber, 0);
return sb.ToString();
}