Ejemplo n.º 1
0
            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);
            }
Ejemplo n.º 2
0
        /// <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));
        }
Ejemplo n.º 3
0
 public override object NodeToType(Type _type, YamlNode node, YamlObjectSerializer serializer)
 {
     return(_formatter.FromCustomFormat(serializer.NodeToType(_formatter.Format, node)));
 }