using System.Collections.Generic;
using YamlDotNet.Serialization;
using YamlDotNet.Core.Events;
namespace YamlDotNet.Samples
var deserializer = new Deserializer();
deserializer.RegisterTagMapping("tag:yaml.org,2002:set", typeof(YamlSet<object>));
var set = deserializer.Deserialize(new StringReader(@"
foreach(var value in (YamlSet<object>)set) {
Console.WriteLine(value);
public class YamlSet<T> : HashSet<T>, IDictionary<T, object>
void IDictionary<T, object>.Add(T key, object value)
bool IDictionary<T, object>.ContainsKey(T key)
throw new NotImplementedException();
ICollection<T> IDictionary<T, object>.Keys
get { throw new NotImplementedException(); }
bool IDictionary<T, object>.Remove(T key)
throw new NotImplementedException();
bool IDictionary<T, object>.TryGetValue(T key, out object value)
throw new NotImplementedException();
ICollection<object> IDictionary<T, object>.Values
get { throw new NotImplementedException(); }
object IDictionary<T, object>.this[T key]
throw new NotImplementedException();
void ICollection<KeyValuePair<T, object>>.Add(KeyValuePair<T, object> item)
throw new NotImplementedException();
void ICollection<KeyValuePair<T, object>>.Clear()
throw new NotImplementedException();
bool ICollection<KeyValuePair<T, object>>.Contains(KeyValuePair<T, object> item)
throw new NotImplementedException();
void ICollection<KeyValuePair<T, object>>.CopyTo(KeyValuePair<T, object>[] array, int arrayIndex)
throw new NotImplementedException();
int ICollection<KeyValuePair<T, object>>.Count
get { throw new NotImplementedException(); }
bool ICollection<KeyValuePair<T, object>>.IsReadOnly
get { throw new NotImplementedException(); }
bool ICollection<KeyValuePair<T, object>>.Remove(KeyValuePair<T, object> item)
throw new NotImplementedException();
IEnumerator<KeyValuePair<T, object>> IEnumerable<KeyValuePair<T, object>>.GetEnumerator()
throw new NotImplementedException();
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
throw new NotImplementedException();
public class FloatNodeDeserializer : INodeDeserializer
private static readonly Dictionary<Tuple<Type, string>, object> SpecialFloats = new Dictionary<Tuple<Type, string>, object>
{ Tuple.Create(typeof(float), ".nan"), float.NaN },
{ Tuple.Create(typeof(float), ".inf"), float.PositiveInfinity },
{ Tuple.Create(typeof(float), "-.inf"), float.NegativeInfinity },
{ Tuple.Create(typeof(double), ".nan"), double.NaN },
{ Tuple.Create(typeof(double), ".inf"), double.PositiveInfinity },
{ Tuple.Create(typeof(double), "-.inf"), double.NegativeInfinity },
bool INodeDeserializer.Deserialize(EventReader reader, Type expectedType, Func<EventReader, Type, object> nestedObjectDeserializer, out object value)
var scalar = reader.Peek<Scalar>();
var found = SpecialFloats.TryGetValue(Tuple.Create(expectedType, scalar.Value), out value);