public override object NodeToType(Type type, YamlNode node, YamlObjectSerializer serializer) { var mapNode = (YamlMappingNode)node; var fields = type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); var instance = Activator.CreateInstance(type) !; var scalarNode = new YamlScalarNode(); foreach (var field in fields) { if (field.IsNotSerialized) { continue; } var fName = field.Name; var fType = field.FieldType; scalarNode.Value = fName; if (mapNode.Children.TryGetValue(scalarNode, out var fNode)) { var fVal = serializer.NodeToType(fType, fNode); field.SetValue(instance, fVal); } } return(instance); }
/// <summary> /// Turn a YAML node into an integer value with the correct flags set. /// </summary> public override object NodeToType(Type type, YamlNode node, YamlObjectSerializer objectSerializer) { // Fallback to just a number, if it's not in flag format yet // This is a hack, but it's only for legacy representations, so it's not so bad if (node is YamlScalarNode) { return((int)objectSerializer.NodeToType(typeof(int), node)); } return(base.NodeToType(type, node, objectSerializer)); }
public override object NodeToType(Type _type, YamlNode node, YamlObjectSerializer serializer) { return(_formatter.FromCustomFormat(serializer.NodeToType(_formatter.Format, node))); }