Questions tagged [yamldotnet]

YamlDotNet is a .NET library for YAML

YamlDotNet provides low level parsing and emitting of YAML as well as a high level object model similar to XmlDocument. A serialization library is also included that allows to read and write objects from and to YAML streams.

The most up-to-date version can always be found right from Visual studio by installing following NuGet package - YamlDotNet.

PM> Install-Package YamlDotNet

Documentation can be found on the official page.

188 questions
3
votes
0 answers

How do I create recursive custom tags in YAMLDotNet

I'm working with YAML in C#, using YamlDotNet. I've created a custom tag that will deserialize to a simple object supporting string interpolation. Let's say the tag is "!StrInterp", and its structure is a template string and a sequence of args to…
russell
  • 31
  • 2
3
votes
2 answers

How do I parse only part of YAML using YamlDotNet?

Suppose I have the following YAML: config_one: name: foo stuff: value config_two: name: bar random: value I want to selectively parse config_one into an object and I want config_two to be ignored: class ConfigOne { public string Name…
void.pointer
  • 24,859
  • 31
  • 132
  • 243
3
votes
0 answers

How to force YamlDotNet to use Folded Block Scalar for all multi-line strings

With YamlDotNet I'm getting inconsistent serialization. I'm serializing with a basic serializer: new…
Wade Hatler
  • 1,785
  • 20
  • 18
3
votes
3 answers

How to Skip Empty Collections in Yamldotnet

I'm trying to figure out how to skip serializing empty collections using YamlDotNet. I have experimented with both a custom ChainedObjectGraphVisitor and IYamlTypeConverter. I'm new to using YamlDotNet and have some knowledge gaps here. Below is…
Paul Schroeder
  • 1,460
  • 1
  • 14
  • 21
3
votes
1 answer

How to deserialize a list of key/value pair in yaml file with YamlDotNet

Hi I'm using YamlDotNet to deserialize a yml file like this: name: element name description: something to describe parameters: - firstKey: value1 - secondKey: value2 this is the .net class for deserialize: class MyElement { public string name…
girtri
  • 767
  • 3
  • 8
  • 16
3
votes
0 answers

Is there a way to prevent setting the same property more than once when deserializing a object?

Deserializing the following yaml fragment using YamlDotNet: bill-to: &id001 street: |- 123 Tornado Alley Suite 16 city: East Westville city: West Westville …
damageboy
  • 2,097
  • 19
  • 34
3
votes
0 answers

In YamlDotNet, how can I deserialize a getter-only property?

I would like to serialize/deserialize objects that have readonly private fields with public getter-only properties, whose readonly fields are set in the objects' constructor. However, the following code fails in unit testing: using…
3
votes
2 answers

In YamlDotNet: Is there a way to output a null value as an empty string in a sequence?

When writing a sequence in an IYamlTypeConverter you might use some code like this: public class MyObjectConverter : IYamlTypeConverter { public MyObjectConverter() {} public bool Accepts(Type type) { return typeof(IMyObject) == type ||…
Steinbitglis
  • 2,482
  • 2
  • 27
  • 40
3
votes
0 answers

Polymorphic deserialization with object root

What's the best way do deserialize the following YAML file widgets: square: color: red circle: color: blue into this class hierarchy? public abstract class Widget { public string Color { get; set; } } public class Square : Widget {…
synapse
  • 5,588
  • 6
  • 35
  • 65
3
votes
1 answer

How to apply custom converter to properties in YamlDotNet

I'm porting my configuration file from .json to .yaml format. In Newtonsoft.Json I was able to apply attribute to a property which needed custom converter, for example [JsonConverter(typeof(CustomIdConverter))] public IList Users { get;…
stil
  • 5,306
  • 3
  • 38
  • 44
3
votes
1 answer

Converting Complex types of C# into YAML

I am a beginner with YAML and studying how to parse YAML into C#. Here I am trying to parse C# Object modules where I have data of complex objects types such as DataTable class or Type class in C#. I know how to convert basic types using YAMLDotNet…
starklord
  • 291
  • 2
  • 6
  • 16
3
votes
1 answer

How to use the DeserializerBuilder?

When trying to use YamlDotNet, I run into this warning: Deserializer.Deserializer(IObjectFactory, INamingConvention, bool, YamlAttributeOverrides) is obsolete: 'Please use DeserializerBuilder to customize the Deserializer. This constructor will…
3
votes
3 answers

How to deserialize an immutable data structure?

How would I deserialize YAML to a immutable data structure? e.g. I have this YAML: Value: SomeString Number: 99 And this data structure: public class MyData { public MyData(string value, int number) { Value = value; Number =…
YamlUser
  • 39
  • 2
3
votes
3 answers

Is it possible to disallow duplicates in YAML file?

I'm using YamlDotNet to parse simple configuration files (no deep nesting, etc.). The deserializer will parse strings containing duplicate fields, overwriting earlier values. For example, foo: bar foo: baz is considered equivalent to foo:…
MJD
  • 33
  • 5
3
votes
2 answers

C# parse and change strings in yaml

I am looking for a way to parse yaml file and change each string then save file without changing structure of original file. In my opinion I should not use Regex for this but some kind of yaml parser. Sample yaml input bellow: receipt: Oz-Ware…
wariacik
  • 335
  • 1
  • 7
  • 15
1 2
3
12 13