Skip to content

Commit

Permalink
Fix for issue 2907. I took Roman Zavalov's patch at https://bugzilla.…
Browse files Browse the repository at this point in the history
…xamarin.com/show_bug.cgi?id=2907#c10 and reverted the numerous formatting changes that were obscuring the real changes, hopefully making the diff clearer
  • Loading branch information
nicolas-raoul committed Nov 2, 2012
1 parent 47dd377 commit f72fc52
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
Expand Up @@ -329,12 +329,12 @@ void ReadMembers (ClassMap map, object ob, bool isValueList, bool readBySoapOrde
object[] flatLists = null;
object[] flatListsChoices = null;
Fixup fixup = null;
int ind = 0;
int ind = -1;
int maxInd;

if (readBySoapOrder) {
if (map.ElementMembers != null) maxInd = map.ElementMembers.Count;
else maxInd = 0;
else maxInd = -1;
}
else
maxInd = int.MaxValue;
Expand Down Expand Up @@ -373,31 +373,40 @@ void ReadMembers (ClassMap map, object ob, bool isValueList, bool readBySoapOrde
AddFixup (fixup);
}

while (Reader.NodeType != System.Xml.XmlNodeType.EndElement && (ind < maxInd))
XmlTypeMapMember previousMember = null;
while (Reader.NodeType != System.Xml.XmlNodeType.EndElement && (ind < maxInd - 1))
{
if (Reader.NodeType == System.Xml.XmlNodeType.Element)
{
XmlTypeMapElementInfo info;

if (readBySoapOrder) {
info = map.GetElement (ind++);
info = map.GetElement (Reader.LocalName, Reader.NamespaceURI);
}
else if (hasAnyReturnMember) {
info = (XmlTypeMapElementInfo) ((XmlTypeMapMemberElement)map.ReturnMember).ElementInfo[0];
hasAnyReturnMember = false;
}
else {
if (map.IsOrderDependentMap) {
while ((info = map.GetElement (ind++)) != null)
if (info.ElementName == Reader.LocalName && info.Namespace == Reader.NamespaceURI)
break;
info = map.GetElement (Reader.LocalName, Reader.NamespaceURI);
}
else
info = map.GetElement (Reader.LocalName, Reader.NamespaceURI, -1);
}

if (info != null && !readFlag[info.Member.Index] )
{
if (info.Member != previousMember)
{
ind++;
previousMember = info.Member;
}

if (info.ExplicitOrder != ind)
throw new InvalidOperationException(string.Format("Element '{0}' has wrong order in sequence (expected - {1}, actual - {2}", Reader.LocalName, info.ExplicitOrder, ind));


if (info.Member.GetType() == typeof (XmlTypeMapMemberList))
{
if (_format == SerializationFormat.Encoded && info.MultiReferenceType)
Expand Down
11 changes: 11 additions & 0 deletions mcs/class/System.XML/System.Xml.Serialization/XmlTypeMapping.cs
Expand Up @@ -400,6 +400,17 @@ public XmlTypeMapElementInfo GetElement (string name, string ns, int order)
if (_elements == null) return null;
return (XmlTypeMapElementInfo)_elements [BuildKey (name,ns, order)];
}

public XmlTypeMapElementInfo GetElement(string name, string ns)
{
if (_elements == null) return null;

foreach (XmlTypeMapElementInfo info in _elements.Values)
if (info.ElementName == name && info.Namespace == ns)
return info;

return null;
}

public XmlTypeMapElementInfo GetElement (int index)
{
Expand Down

0 comments on commit f72fc52

Please sign in to comment.