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

Bug: Interface-based Abstractions Throws Missing FieldOrder Attribute #140

Closed Texnomic closed 4 years ago

Texnomic commented 5 years ago

When using Interface-based Abstractions, The following case works only if Interface IDomain members are marked with FieldOrder Attributes. Otherwise ThrowIfUnordered() throws InvalidOperationException because it checked Interface IDomain members not type Domain members.

public interface IDomain
{
        List<ILabel> Labels { get; }
        string Name { get; }
}

public class Domain : IBinarySerializable, IDomain
{
        [Ignore]
        public List<ILabel> Labels { get; }

        [Ignore]
        public string Name => ToString();

        public void Serialize(Stream Stream, Endianness Endianness, BinarySerializationContext Context)
        {
           //Code
        }

        public void Deserialize(Stream Stream, Endianness Endianness, BinarySerializationContext Context)
        {
            //Code
        }

}

public class Question : IQuestion
{
        [FieldOrder(0)]
        [SubtypeDefault(typeof(Domain))] //Check Issue #139 
        public IDomain Domain { get; set; }
}
A016699 commented 4 years ago

Hi, I'm just run in the same problem. Do you think there will be fix soon ?

jefffhaynes commented 4 years ago

I'll work on this but it is a tricky problem. The possibility is there to create an entire inheritance hierarchy of serializer attributes, which isn't really something that is currently supported. Ignoring attributes in a derived (or implemented) class is actually just a special case of that hierarchy. That being said, I certainly see the value.

A016699 commented 4 years ago

I understand the problem, Just a little hint. It seems to work if I I use the SubtypeAttribute to - could be there a workaround for it ?

jefffhaynes commented 4 years ago

Fair point. Maybe I'm thinking about it wrong. Let me try a different approach.

jefffhaynes commented 4 years ago

Fixed in 8.5

A016699 commented 4 years ago

Thank you, for your fast response, it is create lib and I love working with it.

jefffhaynes commented 4 years ago

Thanks! Glad you like it!

jefffhaynes commented 4 years ago

Sorry, I have no idea what happened but apparently this exact issue isn't quite fixed yet. Give me a few...

jefffhaynes commented 4 years ago

Ok, deserialization wasn't working. Fixed in 8.5.1