[Mono-dev] [PATCH] Enum XML (de)serialization fixes

Gert Driesen gert.driesen at telenet.be
Mon Feb 6 13:14:27 EST 2006


Hi,

The attached patch fixes a few issues in Mono's XML (de)serialization of
enums, and adds support for serialization of numeric values to matching enum
fields:

	* XmlTypeMapping.cs: EnumMapMemer now also stores value for enum
	fields. Modified EnumMapping.GetXmlName to use XmlCustomerFormatter
	to support serializing value to enum field and made sure the 
	exceptions we throw match those of MSFT. To match MSFT, throw 
	InvalidOperationException in EnumMapping.GetEnumName if matching 
	constant does not exist in enum.
	* XmlSerializationReaderInterpreter.cs: Pass full typename to
	EnumMapping.GetEnumName for construction of exception message.
	* XmlSerializer.cs: In Deserialize, wrap InvalidOperationException
	and InvalidCastException in another InvalidOperationException to
match
	MSFT. In Serialize, wrap InvalidOperationException,
InvalidCastException
	and the inner exception for a TargetInvocationException in a
	InvalidOperationException to match MSFT.
	* SerializationCodeGenerator.cs: In GenerateGetXmlEnumValue, use 
	XmlCustomerFormatter.FromEnum in order to also support serialization
	from the underlying value of a constant. In 2.0 profile, throw
	InvalidOperationException if numeric value cannot be serialized into
	enum constant(s). In GenerateSingleEnumValue, no longer attempt
	to parse unknown constant value but instead report it as
	InvalidOperationException.
	* XmlSerializationWriter.cs: Implemented 2.0 version of FromEnum,
and
	CreateInvalidEnumValueException.
	* XmlCustomerFormatter.cs: Added FromEnum overload that takes name
of
	enum for which string value must be created. Modified FromEnum
	to behave more like MSFT's implementation:
	- treat value as bit field.
	- no longer return empty string if the value matches an id for which
there's no corresponding
	name.
	- if one of the ids has value 0 and there's a match for the enum
value
	(with a zero length XML name) or the enum value is 0, then return
the 
	corresponding XML for the id with value 0.
	- in 2.0 profile, throw InvalidOperationException is no match is
found
	for (part of) the enum value.
	* XmlSerializationWriterInterpreter.cs: Do not treat numeric enum
value
	as typed primitive type. Pass full typename of enum to 
	EnumMap.GetXmlName.
	* XmlSchemaImporter.cs: Pass full typename to EnumMap.GetEnumName
	to allow it to be used in exception messages.
	* XmlReflectionImporter.cs: Use FieldInfo instead of MemberInfo for
	enum fields. Use IsDefined instead of GetCustomAttributes for
checking
	if a certain attribute is defined. Use value of enum field in
	EnumMapMember ctor.
	* SoapReflectionImporter.cs: Use FieldInfo instead of MemberInfo for
	enum fields. Use IsDefined instead of GetCustomAttribute for
checking
	if a certain attribute is defined. Use value of enum field in
	EnumMapMember ctor.

Note:

A large part of the patch consist of new/fixed unit tests, which explains
the size of the patch. 

All tests pass on Mono 1.0/2.0, and MS.NET 1.1 and 2.0.

Let me know if it's ok to commit these changes ?

Gert
-------------- next part --------------
A non-text attachment was scrubbed...
Name: xmlsernew.diff
Type: application/octet-stream
Size: 80735 bytes
Desc: not available
Url : http://lists.ximian.com/pipermail/mono-devel-list/attachments/20060206/851753ef/attachment.obj 


More information about the Mono-devel-list mailing list