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
292 stars 62 forks source link

Suggestion: Rename FieldLength(string) to FieldLength(string) #165

Closed hjkl950217 closed 3 years ago

hjkl950217 commented 3 years ago

in Doc “For bound length fields, the source will be updated with the serialized length. ”

I think it's very easy to understand mistakes,After reading this document, I did not understand the role of FieldLengthAttribute(string path), and then I tested the correct behavior.

  1. FieldLengthAttribute(ulong length) -> Limit length
  2. FieldLengthAttribute(string path) -> Update to other property

The two APIs have completely different functions. It is recommended to use two names

Suggestion FieldLengthAttribute(string path) -> FieldLengthToAttribute(string path) It looks like this:


    public class TestPerson
    {
        [FieldOrder(0)]
        [FieldLength(1)]
        public byte NameLength { get; set; }

        [FieldOrder(1)]
        [FieldLengthTo(nameof(NameLength))]
        public string Name { get; set; }

    }

//for old Api
[Obsolete("Use FieldLengthTo")]
public FieldLengthAttribute(string path){....}
hjkl950217 commented 3 years ago

in Serialize: update property in Deserialize: fix Length by property

so changing api name is not a good idea