public override YamlNode TypeToNode(object obj, YamlObjectSerializer serializer) { var node = new YamlMappingNode(); var type = obj.GetType(); var fields = type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); foreach (var field in fields) { if (field.IsNotSerialized) { continue; } var fVal = field.GetValue(obj); if (fVal == null) { throw new ArgumentException("Cannot serialize null value inside struct field."); } // Potential recursive infinite loop? var fTypeNode = serializer.TypeToNode(fVal); node.Add(field.Name, fTypeNode); } return(node); }