本文整理汇总了C#中YamlStream.Accept方法的典型用法代码示例。如果您正苦于以下问题:C# YamlStream.Accept方法的具体用法?C# YamlStream.Accept怎么用?C# YamlStream.Accept使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类YamlStream
的用法示例。
在下文中一共展示了YamlStream.Accept方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ParseModel
private static NamedModel ParseModel(string input)
{
if (input == null) throw new ArgumentNullException("input");
using (var yamlSource = File.OpenText(input))
{
var stream = new YamlStream();
stream.Load(yamlSource);
var visitor = new ComposeNamedModelVisitor();
stream.Accept(visitor);
return visitor.Model;
}
}
示例2: AllAliasesMustBeResolved
public void AllAliasesMustBeResolved()
{
YamlStream original = new YamlStream();
original.Load(YamlFile("invalid-reference.yaml"));
var visitor = new AliasFindingVisitor();
try
{
original.Accept(visitor);
}
catch (NotSupportedException)
{
foreach (var node in visitor.CurrentPath)
{
TestContext.WriteLine(node.ToString());
}
Assert.Fail();
}
}
示例3: Parse
public IDictionary<string, string> Parse(Stream input)
{
IDictionary<string, string> data = new SortedDictionary<string, string>(StringComparer.OrdinalIgnoreCase);
var visitor = new ContextAwareVisitor();
var yamlStream = new YamlStream();
using (var reader = new StreamReader(input))
{
yamlStream.Load(reader);
}
if (!yamlStream.Documents.Any())
{
return data;
}
yamlStream.Accept(visitor);
foreach (var item in visitor.Items)
{
var key = item.Key;
if (!string.IsNullOrEmpty(this.root))
{
key = ConfigurationPath.Combine(this.root, key);
}
if (data.ContainsKey(key))
{
throw new FormatException(string.Format("The key '{0}' is duplicated.", key));
}
data[key] = item.Value;
}
return data;
}
示例4: RoundtripSample
public void RoundtripSample()
{
var original = new YamlStream();
original.Load(YamlFile("sample.yaml"));
original.Accept(new TracingVisitor());
}
示例5: RoundtripTest
private void RoundtripTest(string yamlFileName)
{
var original = new YamlStream();
original.Load(YamlFile(yamlFileName));
var buffer = new StringBuilder();
original.Save(new StringWriter(buffer));
Dump.WriteLine(buffer);
var final = new YamlStream();
final.Load(new StringReader(buffer.ToString()));
var originalBuilder = new YamlDocumentStructureBuilder();
original.Accept(originalBuilder);
var finalBuilder = new YamlDocumentStructureBuilder();
final.Accept(finalBuilder);
Dump.WriteLine("The original document produced {0} events.", originalBuilder.Events.Count);
Dump.WriteLine("The final document produced {0} events.", finalBuilder.Events.Count);
Assert.AreEqual(originalBuilder.Events.Count, finalBuilder.Events.Count);
for (var i = 0; i < originalBuilder.Events.Count; ++i)
{
var originalEvent = originalBuilder.Events[i];
var finalEvent = finalBuilder.Events[i];
Assert.AreEqual(originalEvent.Type, finalEvent.Type);
Assert.AreEqual(originalEvent.Value, finalEvent.Value);
}
}
示例6: Run
public void Run(string[] args)
{
var original = new YamlStream();
original.Load(new StringReader(Sample));
original.Accept(new TracingVisitor());
}
示例7: RoundtripTest
private void RoundtripTest(string yamlFileName)
{
YamlStream original = new YamlStream();
original.Load(YamlFile(yamlFileName));
StringBuilder buffer = new StringBuilder();
original.Save(new StringWriter(buffer));
Console.WriteLine(buffer.ToString());
YamlStream final = new YamlStream();
final.Load(new StringReader(buffer.ToString()));
YamlDocumentStructureBuilder originalBuilder = new YamlDocumentStructureBuilder();
original.Accept(originalBuilder);
YamlDocumentStructureBuilder finalBuilder = new YamlDocumentStructureBuilder();
final.Accept(finalBuilder);
Console.WriteLine("The original document produced {0} events.", originalBuilder.Events.Count);
Console.WriteLine("The final document produced {0} events.", finalBuilder.Events.Count);
Assert.Equal(originalBuilder.Events.Count, finalBuilder.Events.Count);
for (int i = 0; i < originalBuilder.Events.Count; ++i)
{
YamlNodeEvent originalEvent = originalBuilder.Events[i];
YamlNodeEvent finalEvent = finalBuilder.Events[i];
Assert.Equal(originalEvent.Type, finalEvent.Type);
//Assert.Equal(originalEvent.Tag, finalEvent.Tag);
//Assert.Equal(originalEvent.Anchor, finalEvent.Anchor);
Assert.Equal(originalEvent.Value, finalEvent.Value);
}
}