rikimaru0345 / Ceras

Universal binary serializer for a wide variety of scenarios https://discord.gg/FGaCX4c
MIT License
484 stars 53 forks source link

Serializing auto-generated properties but not calling regular properties getters. #98

Open laloutre87 opened 3 years ago

laloutre87 commented 3 years ago

Serializing object defined like that is long :

` public class MyObject { private object _SuperLongToCalculateField = null;

public object SuperLongToCalculateField {
    get {
        if (_SuperLongToCalculateField  == null) {
            Thread.Sleep(200000); // long calculation done here. 
                            _SuperLongToCalculateField   = "some value";
        }

        return _SuperLongToCalculateField;
    }
    set {
        _SuperLongToCalculateField = value;
    }
}

public int AnotherProperty { get; set; }

} `

Because it seems like the getter of SuperLongToCalculateField is called.

Putting the SerializerConfig "DefaultTargets" value to "TargetMember.AllFields", solve the speed problem, but then "AnotherProperty" isn't serialized.

Would it be possible to have a DefaultTargets settings to save all fields + auto-generated properties ( " get; set; " ) only ? Or is it already there and I am missing something ?

Thanks.