[Mono-dev] Enum serealization proble in System.Xml.Serialization.XmlMapping
Atsushi Eno
atsushi at ximian.com
Thu Nov 17 11:53:59 EST 2005
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
>
>
More information about the Mono-devel-list
mailing list