本文整理汇总了C#中IParser.Accept方法的典型用法代码示例。如果您正苦于以下问题:C# IParser.Accept方法的具体用法?C# IParser.Accept怎么用?C# IParser.Accept使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IParser
的用法示例。
在下文中一共展示了IParser.Accept方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: while
bool INodeDeserializer.Deserialize(IParser parser, Type expectedType, Func<IParser, Type, object> nestedObjectDeserializer, out object value)
{
var mapping = parser.Allow<MappingStart>();
if (mapping == null)
{
value = null;
return false;
}
value = _objectFactory.Create(expectedType);
while (!parser.Accept<MappingEnd>())
{
var propertyName = parser.Expect<Scalar>();
var property = _typeDescriptor.GetProperty(expectedType, null, propertyName.Value, _ignoreUnmatched);
if (property == null)
{
parser.SkipThisAndNestedEvents();
continue;
}
var propertyValue = nestedObjectDeserializer(parser, property.Type);
var propertyValuePromise = propertyValue as IValuePromise;
if (propertyValuePromise == null)
{
var convertedValue = TypeConverter.ChangeType(propertyValue, property.Type);
property.Write(value, convertedValue);
}
else
{
var valueRef = value;
propertyValuePromise.ValueAvailable += v =>
{
var convertedValue = TypeConverter.ChangeType(v, property.Type);
property.Write(valueRef, convertedValue);
};
}
}
parser.Expect<MappingEnd>();
return true;
}
示例2: YamlDocument
/// <summary>
/// Initializes a new instance of the <see cref="YamlDocument"/> class.
/// </summary>
internal YamlDocument(IParser parser)
{
var state = new DocumentLoadingState();
parser.Expect<DocumentStart>();
while (!parser.Accept<DocumentEnd>())
{
Debug.Assert(RootNode == null);
RootNode = YamlNode.ParseNode(parser, state);
if (RootNode is YamlAliasNode)
{
throw new YamlException();
}
}
state.ResolveAliases();
parser.Expect<DocumentEnd>();
}
示例3: ParseNode
/// <summary>
/// Parses the node represented by the next event in <paramref name="parser" />.
/// </summary>
/// <returns>Returns the node that has been parsed.</returns>
internal static YamlNode ParseNode(IParser parser, DocumentLoadingState state)
{
if (parser.Accept<Scalar>())
{
return new YamlScalarNode(parser, state);
}
if (parser.Accept<SequenceStart>())
{
return new YamlSequenceNode(parser, state);
}
if (parser.Accept<MappingStart>())
{
return new YamlMappingNode(parser, state);
}
if (parser.Accept<AnchorAlias>())
{
var alias = parser.Expect<AnchorAlias>();
return state.GetNode(alias.Value, false, alias.Start, alias.End) ?? new YamlAliasNode(alias.Value);
}
throw new ArgumentException("The current event is of an unsupported type.", "events");
}
示例4: DeserializeHelper
private static void DeserializeHelper(Type tKey, Type tValue, IParser parser, Func<IParser, Type, object> nestedObjectDeserializer, IDictionary result)
{
parser.Expect<MappingStart>();
while (!parser.Accept<MappingEnd>())
{
var key = nestedObjectDeserializer(parser, tKey);
var keyPromise = key as IValuePromise;
var value = nestedObjectDeserializer(parser, tValue);
var valuePromise = value as IValuePromise;
if (keyPromise == null)
{
if (valuePromise == null)
{
// Happy path: both key and value are known
result[key] = value;
}
else
{
// Key is known, value is pending
valuePromise.ValueAvailable += v => result[key] = v;
}
}
else
{
if (valuePromise == null)
{
// Key is pending, value is known
keyPromise.ValueAvailable += v => result[v] = value;
}
else
{
// Both key and value are pending. We need to wait until both of them becom available.
var hasFirstPart = false;
keyPromise.ValueAvailable += v =>
{
if (hasFirstPart)
{
result[v] = value;
}
else
{
key = v;
hasFirstPart = true;
}
};
valuePromise.ValueAvailable += v =>
{
if (hasFirstPart)
{
result[key] = v;
}
else
{
value = v;
hasFirstPart = true;
}
};
}
}
}
parser.Expect<MappingEnd>();
}
示例5: DeserializeHelper
internal static void DeserializeHelper(Type tItem, IParser parser, Func<IParser, Type, object> nestedObjectDeserializer, IList result, bool canUpdate)
{
parser.Expect<SequenceStart>();
while (!parser.Accept<SequenceEnd>())
{
var current = parser.Current;
var value = nestedObjectDeserializer(parser, tItem);
var promise = value as IValuePromise;
if (promise == null)
{
result.Add(TypeConverter.ChangeType(value, tItem));
}
else if (canUpdate)
{
var index = result.Add(tItem.IsValueType() ? Activator.CreateInstance(tItem) : null);
promise.ValueAvailable += v => result[index] = TypeConverter.ChangeType(v, tItem);
}
else
{
throw new ForwardAnchorNotSupportedException(
current.Start,
current.End,
"Forward alias references are not allowed because this type does not implement IList<>"
);
}
}
parser.Expect<SequenceEnd>();
}