jefffhaynes / BinarySerializer

A declarative serialization framework for controlling formatting of data at the byte and bit level using field bindings, converters, and code.
MIT License
290 stars 62 forks source link

FieldScale and Nullable does not return NULL if value should be NULL #234

Open A016699 opened 3 months ago

A016699 commented 3 months ago

I'm just want use the FieldScale ans SerializeWhen Atribuest together with Nullable type.

If the FieldScale is not use the Deserializion works correctly as it returns null if the SerializeWhen is not valid. If i add the Fieldscale it returns 0 instead of NULL.

As a second problem was that if you using float? it throws an Exception - as ist could not be converted.

    public class ScaledValueClass
    {
        [Ignore]
        public bool Serialize { get; set; } = false;

        [FieldScale(2)]
        [SerializeAs(SerializedType.Int4)]
        [SerializeWhen(nameof(Serialize), true)]
        public double? Value { get; set; } = default;
    }