Explorar o código

* XmlReflectionImporter.cs: Get the class members using the right order.
* XmlSerializationWriterInterpreter.cs: Removed unneeded code.
A member with the Any attribute can also contain text. Support this.
* XmlTypeMapMemberElement.cs: Added CanBeText property.

svn path=/trunk/mcs/; revision=22750

Lluis Sanchez %!s(int64=22) %!d(string=hai) anos
pai
achega
24ebffbe3a

+ 7 - 0
mcs/class/System.XML/System.Xml.Serialization/ChangeLog

@@ -1,3 +1,10 @@
+2004-02-04  Lluis Sanchez Gual  <[email protected]>
+
+	* XmlReflectionImporter.cs: Get the class members using the right order.
+	* XmlSerializationWriterInterpreter.cs: Removed unneeded code.
+	  A member with the Any attribute can also contain text. Support this.
+	* XmlTypeMapMemberElement.cs: Added CanBeText property.
+
 2004-01-27  Lluis Sanchez Gual  <[email protected]>
 
 	* XmlSchemaImporter.cs: Redefinition of types are not supported. Added a

+ 36 - 22
mcs/class/System.XML/System.Xml.Serialization/XmlReflectionImporter.cs

@@ -491,29 +491,43 @@ namespace System.Xml.Serialization {
 		public ICollection GetReflectionMembers (Type type)
 		{
 			ArrayList members = new ArrayList();
-			PropertyInfo[] properties = type.GetProperties (BindingFlags.Instance | BindingFlags.Public);
-			foreach (PropertyInfo prop in properties)
-			{
-				if (!prop.CanRead) continue;
-				if (!prop.CanWrite && TypeTranslator.GetTypeData (prop.PropertyType).SchemaType != SchemaTypes.Array)
-					continue;
-				if (prop.GetIndexParameters().Length > 0) continue;
-					
-				XmlAttributes atts = attributeOverrides[type, prop.Name];
-				if (atts == null) atts = new XmlAttributes (prop);
-				if (atts.XmlIgnore) continue;
-				XmlReflectionMember member = new XmlReflectionMember(prop.Name, prop.PropertyType, atts);
-				members.Add (member);
-			}
-
-			FieldInfo[] fields = type.GetFields (BindingFlags.Instance | BindingFlags.Public);
-			foreach (FieldInfo field in fields)
+			MemberInfo[] tmembers = type.GetMembers (BindingFlags.Instance | BindingFlags.Public);
+			int currentTypePos = 0;
+			Type currentType = null;
+			
+			foreach (MemberInfo tmember in tmembers)
 			{
-				XmlAttributes atts = attributeOverrides[type, field.Name];
-				if (atts == null) atts = new XmlAttributes (field);
-				if (atts.XmlIgnore) continue;
-				XmlReflectionMember member = new XmlReflectionMember(field.Name, field.FieldType, atts);
-				members.Add (member);
+				if (currentType != tmember.DeclaringType)
+				{
+					currentType = tmember.DeclaringType;
+					currentTypePos = 0;
+				}
+				
+				if (tmember is FieldInfo)
+				{
+					FieldInfo field = tmember as FieldInfo;
+					XmlAttributes atts = attributeOverrides[type, field.Name];
+					if (atts == null) atts = new XmlAttributes (field);
+					if (atts.XmlIgnore) continue;
+					XmlReflectionMember member = new XmlReflectionMember(field.Name, field.FieldType, atts);
+					members.Insert (currentTypePos, member);
+					currentTypePos++;
+				}
+				else if (tmember is PropertyInfo)
+				{
+					PropertyInfo prop  = tmember as PropertyInfo;
+					if (!prop.CanRead) continue;
+					if (!prop.CanWrite && TypeTranslator.GetTypeData (prop.PropertyType).SchemaType != SchemaTypes.Array)
+						continue;
+					if (prop.GetIndexParameters().Length > 0) continue;
+						
+					XmlAttributes atts = attributeOverrides[type, prop.Name];
+					if (atts == null) atts = new XmlAttributes (prop);
+					if (atts.XmlIgnore) continue;
+					XmlReflectionMember member = new XmlReflectionMember(prop.Name, prop.PropertyType, atts);
+					members.Insert (currentTypePos, member);
+					currentTypePos++;
+				}
 			}
 			return members;
 		}

+ 4 - 6
mcs/class/System.XML/System.Xml.Serialization/XmlSerializationWriterInterpreter.cs

@@ -224,11 +224,6 @@ namespace System.Xml.Serialization
 						if (memberValue != null)
 							WriteAnyElementContent ((XmlTypeMapMemberAnyElement)member, memberValue);
 					}
-					else if (memType == typeof(XmlTypeMapMemberAnyElement))
-					{
-						if (memberValue != null)
-							WriteAnyElementContent ((XmlTypeMapMemberAnyElement)member, memberValue);
-					}
 					else if (memType == typeof(XmlTypeMapMemberAnyAttribute))
 					{
 						// Ignore
@@ -425,6 +420,7 @@ namespace System.Xml.Serialization
 				memberValue = new object[] { memberValue };
 			}
 
+			bool canBeText = member.CanBeText;
 			Array elems = (Array) memberValue;
 			foreach (XmlNode elem in elems)
 			{
@@ -438,8 +434,10 @@ namespace System.Xml.Serialization
 					else
 						throw CreateUnknownAnyElementException (elem.Name, elem.NamespaceURI);
 				}
+				else if (elem is XmlCharacterData)
+					elem.WriteTo (Writer);
 				else
-					CreateUnknownTypeException (elem);
+					throw CreateUnknownTypeException (elem);
 			}
 		}
 

+ 8 - 0
mcs/class/System.XML/System.Xml.Serialization/XmlTypeMapMemberElement.cs

@@ -142,6 +142,14 @@ namespace System.Xml.Serialization
 				return false;
 			}
 		}
+		
+		public bool CanBeText
+		{
+			get
+			{
+				return (ElementInfo.Count > 0) && ((XmlTypeMapElementInfo)ElementInfo[0]).IsTextElement;
+			}
+		}
 	}
 
 	internal class XmlTypeMapMemberAnyAttribute: XmlTypeMapMember