FW: [Mono-dev] Enum serealization proble in System.Xml.Serialization.XmlMapping

Lluis Sanchez lluis at ximian.com
Tue Nov 22 08:48:56 EST 2005


El dom, 20-11-2005 a las 01:23 -0800, Vladimir Krasnov escribió:
> Hello Lluis,
> 
> Please approve the attached patch to 
> System.Xml.Serialization/XmlTypeMapping.cs

The change looks ok, but please:
* Use == to compare strings.
* you have to apply the fix to the serializer generator, or it will be
useless.
* a nunit test is needed for this.

Thanks!
Lluis.

> 
> Vladimir Krasnov
> 
> -----Original Message-----
> From: Atsushi Eno [mailto:atsushi at ximian.com] 
> Sent: Thursday, November 17, 2005 8:28 PM
> To: Vladimir Krasnov
> Cc: mono-devel mailing list
> Subject: Re: [Mono-dev] Enum serealization proble in
> System.Xml.Serialization.XmlMapping
> 
> Ah, now I understand what you wanted to do (serializing flag enums).
> 
> BTW I'm not maintaining XmlSerializer stuff; you should ping Lluis
> to get your patches approved ;-)
> 
> Atsushi Eno
> 
> Vladimir Krasnov wrote:
> > You are right, but this occurs only on not flaggable enums. I suppose
> > the reason for this behavior is indeed an illegal state for such enum.
> > The reason it's supported for flaggable enum is that the zero value
> > means "all flags are off".
> > 
> > Anyway the correct patch would be in file
> > System.Xml.Serialization\XmlTypeMapping.cs line 670 :
> > 
> > if (enumName.Equals("0") && IsFlags)
> > 
> > 
> > Would you like to commit it or you prefer I'll do?
> > 
> > Vladimir Krasnov
> > 
> > -----Original Message-----
> > From: Atsushi Eno [mailto:atsushi at ximian.com] 
> > Sent: Thursday, November 17, 2005 6:54 PM
> > To: Vladimir Krasnov
> > Cc: mono-devel mailing list
> > Subject: Re: [Mono-dev] Enum serealization proble in
> > System.Xml.Serialization.XmlMapping
> > 
> > Oh, I didn't know that enum fields are always initialized as 0.
> > 
> > So your patch is basically to omit the value string instead of
> > omitting the entire element (or attribute) and it isn't
> > deserializable anyways (as well as MS.NET), right?
> > 
> > --------
> > using System;
> > using System.IO;
> > using System.Xml.Serialization;
> > 
> > public class Foo
> > {
> >          public EnumFoo efoo;
> > 
> >          public static void Main ()
> >          {
> >                  Foo f = new Foo ();
> >                  XmlSerializer s = new XmlSerializer (typeof (Foo));
> >                  StringWriter sw = new StringWriter ();
> >                  s.Serialize (sw, f);
> >                  StringReader sr = new StringReader (sw.ToString ());
> >                  f = (Foo) s.Deserialize (sr);
> >                  Console.WriteLine (f.efoo);
> >          }
> > }
> > 
> > public enum EnumFoo {
> >          A = 1,
> >          B = 2
> > }
> > --------
> > 
> > Cheers,
> > Atsushi Eno
> > 
> > 
> > Vladimir Krasnov wrote:
> >> Hello Atsushi,
> >>
> >> What do mean always "0"? Is it may be other value if you don't
> >> initialize enum variable?
> >> I'll create test case soon.
> >>
> >> Vladimir Krasnov
> >>
> >> -----Original Message-----
> >> From: Atsushi Eno [mailto:atsushi at ximian.com] 
> >> Sent: Thursday, November 17, 2005 5:34 PM
> >> To: Vladimir Krasnov
> >> Cc: mono-devel-list at lists.ximian.com
> >> Subject: Re: [Mono-dev] Enum serealization proble in
> >> System.Xml.Serialization.XmlMapping
> >>
> >> It would be much better if you avoid application/octet-stream for
> >> your text attachments (it is even unlikely to be read by others).
> >>
> >> Are you sure that enum default value is always "0" ?
> >>
> >> Also, it looks like you forgot to create NUnit test for your
> >> example case.
> >>
> >> Cheers,
> >> Atsushi Eno
> >>
> >> Vladimir Krasnov wrote:
> >>> Hello All,
> >>>  
> >>> There is a problem in serialization of Enum default value, the value
> >>> shouldn't be written to the xml.
> >>> See attached sample that reproduces the problem.
> >>> Also please approve the patch that fixes the problem.
> >>> If no one objects I'll commit.
> >>>  
> >>> Vladimir Krasnov
> >>>
> >>>
> >>>
> >>>
> >
> ------------------------------------------------------------------------
> >>> _______________________________________________
> >>> Mono-devel-list mailing list
> >>> Mono-devel-list at lists.ximian.com
> >>> http://lists.ximian.com/mailman/listinfo/mono-devel-list
> >>
> > 
> > 
> 
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list




More information about the Mono-devel-list mailing list