hadashiA / VYaml

The extra fast, low memory footprint YAML library for C#, focued on .NET and Unity.
MIT License
305 stars 18 forks source link

Default values in constructor doesn't work #53

Closed nicloay closed 10 months ago

nicloay commented 10 months ago

with following configuration Test is not passed

    public partial class DefaultValue
    {
        public readonly int Value;
        public readonly int ValueSet;

        [YamlConstructor]
        public DefaultValue(int valueSet, int value = 12)
        {
            ValueSet = valueSet;
            Value = value;
        }
    }

and this test is failing

        public void TestDefaultValue()
        {
            string testYaml = @"---
valueSet: 22";
            var deserialized = YamlSerializer.Deserialize<DefaultValue>(Encoding.UTF8.GetBytes(testYaml));
            Assert.That(deserialized.ValueSet, Is.EqualTo(22));
            Assert.That(deserialized.Value, Is.EqualTo(12));
        }

TestDefaultValue (0,046s)

Expected: 12 But was: 0

hadashiA commented 10 months ago

Thanks for the report. I've fixed in #58 , #59.