Пример #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);
            }