Please enable YAX-Attributes inheritance...

Jun 7, 2012 at 6:56 PM

If you derive a class, only some YAXAttributes are taken into account of into the serialization:

 

[YAXSerializeAs("root")]
    class TestBase
    {
        [YAXAttributeForClass]
        public string Name { get; set; }
    }

    class TestInherited : TestBase
    {
        public string Another { get; set; }
    }

    class Program
    {
        static void Main(string[] args)
        {
            var serializer = new YAXSerializer(typeof (TestInherited));
            var test = new TestInherited
                           {
                               Name = "myName",
                               Another = "one bites the dust"
                           };
            var result = serializer.Serialize(test);

            Console.Write(result);

            Console.ReadKey();
        }
    }

 

produces:

<TestInherited Name="myName">
  <Another>one bites the dust</Another>
</TestInherited>

and not:

<root Name="myName">
  <Another>one bites the dust</Another>
</root>

It works, if you change this code part from UDTWrapper.cs:  

 

            foreach (var attr in m_udtType.GetCustomAttributes(true))
            {
                if (attr is YAXBaseAttribute)
                    ProcessYAXAttribute(attr);
            }

But i didn´t test the deserialization part, yet....

 

Coordinator
Jun 9, 2012 at 7:53 AM

Currently none of the attributes have been implemented, having inheritance in mind. This feature has been requested several times.

Thanks, and I will look for the most secure and flexible workaround.