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

Vladimir Krasnov vladimirk at mainsoft.com
Sun Nov 20 04:23:03 EST 2005


Hello Lluis,

Please approve the attached patch to 
System.Xml.Serialization/XmlTypeMapping.cs

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
>>
> 
> 

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: XmlTypeMapping.patch.txt
Url: http://lists.ximian.com/pipermail/mono-devel-list/attachments/20051120/3707f1a7/attachment.txt 


More information about the Mono-devel-list mailing list