2 // System.Xml.Serialization.XmlSerializationReader.cs
5 // Tim Coleman (tim@timcoleman.com)
6 // Gonzalo Paniagua Javier (gonzalo@ximian.com)
7 // Lluis Sanchez Gual (lluis@ximian.com)
9 // Copyright (C) Tim Coleman, 2002
10 // (c) 2002 Ximian, Inc. (http://www.ximian.com)
14 // Permission is hereby granted, free of charge, to any person obtaining
15 // a copy of this software and associated documentation files (the
16 // "Software"), to deal in the Software without restriction, including
17 // without limitation the rights to use, copy, modify, merge, publish,
18 // distribute, sublicense, and/or sell copies of the Software, and to
19 // permit persons to whom the Software is furnished to do so, subject to
20 // the following conditions:
22 // The above copyright notice and this permission notice shall be
23 // included in all copies or substantial portions of the Software.
25 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
29 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
30 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
31 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35 using System
.Collections
;
36 using System
.Globalization
;
38 using System
.Xml
.Schema
;
39 using System
.Reflection
;
41 namespace System
.Xml
.Serialization
45 // FIXME: provide expected elements/attributes on unknown elements/attributs
47 public abstract class XmlSerializationReader
49 : XmlSerializationGeneratedCode
59 ArrayList collItemFixups
;
60 Hashtable typesCallbacks
;
61 ArrayList noIDTargets
;
63 Hashtable delayedListFixups
;
64 XmlSerializer eventSource
;
65 int delayedFixupId
= 0;
66 Hashtable referencedObjects
;
67 int readCount
, whileIterationCount
;
71 string w3InstanceNS2000
;
72 string w3InstanceNS1999
;
79 XmlQualifiedName arrayQName
;
82 internal void Initialize (XmlReader reader
, XmlSerializer eventSource
)
84 w3SchemaNS
= reader
.NameTable
.Add (XmlSchema
.Namespace
);
85 w3InstanceNS
= reader
.NameTable
.Add (XmlSchema
.InstanceNamespace
);
86 w3InstanceNS2000
= reader
.NameTable
.Add ("http://www.w3.org/2000/10/XMLSchema-instance");
87 w3InstanceNS1999
= reader
.NameTable
.Add ("http://www.w3.org/1999/XMLSchema-instance");
88 soapNS
= reader
.NameTable
.Add (XmlSerializer
.EncodingNamespace
);
89 wsdlNS
= reader
.NameTable
.Add (XmlSerializer
.WsdlNamespace
);
90 nullX
= reader
.NameTable
.Add ("null");
91 nil
= reader
.NameTable
.Add ("nil");
92 typeX
= reader
.NameTable
.Add ("type");
93 arrayType
= reader
.NameTable
.Add ("arrayType");
95 this.eventSource
= eventSource
;
96 arrayQName
= new XmlQualifiedName ("Array", soapNS
);
100 private ArrayList
EnsureArrayList (ArrayList list
)
103 list
= new ArrayList ();
107 private Hashtable
EnsureHashtable (Hashtable hash
)
110 hash
= new Hashtable ();
114 protected XmlSerializationReader ()
118 protected XmlDocument Document
121 if (document
== null)
122 document
= new XmlDocument (reader
.NameTable
);
128 protected XmlReader Reader
{
129 get { return reader; }
133 protected bool IsReturnValue
136 throw new NotImplementedException ();
139 throw new NotImplementedException ();
145 protected int ReaderCount
{
146 get { return readCount; }
152 protected void AddFixup (CollectionFixup fixup
)
154 collFixups
= EnsureHashtable (collFixups
);
155 collFixups
[fixup
.Id
] = fixup
;
157 if (delayedListFixups
!= null && delayedListFixups
.ContainsKey (fixup
.Id
)) {
158 fixup
.CollectionItems
= delayedListFixups
[fixup
.Id
];
159 delayedListFixups
.Remove (fixup
.Id
);
163 protected void AddFixup (Fixup fixup
)
165 fixups
= EnsureArrayList (fixups
);
169 void AddFixup (CollectionItemFixup fixup
)
171 collItemFixups
= EnsureArrayList (collItemFixups
);
172 collItemFixups
.Add(fixup
);
175 protected void AddReadCallback (string name
, string ns
, Type type
, XmlSerializationReadCallback read
)
177 WriteCallbackInfo info
= new WriteCallbackInfo ();
179 info
.TypeName
= name
;
181 info
.Callback
= read
;
182 typesCallbacks
= EnsureHashtable (typesCallbacks
);
183 typesCallbacks
.Add (new XmlQualifiedName (name
, ns
), info
);
186 protected void AddTarget (string id
, object o
)
189 targets
= EnsureHashtable (targets
);
190 if (targets
[id
] == null)
195 noIDTargets
= EnsureArrayList (noIDTargets
);
200 private string CurrentTag ()
202 switch (reader
.NodeType
) {
203 case XmlNodeType
.Element
:
204 return String
.Format ("<{0} xmlns='{1}'>", reader
.LocalName
,
205 reader
.NamespaceURI
);
206 case XmlNodeType
.Attribute
:
208 case XmlNodeType
.Text
:
210 case XmlNodeType
.ProcessingInstruction
:
212 case XmlNodeType
.Entity
:
214 case XmlNodeType
.EndElement
:
221 protected Exception
CreateCtorHasSecurityException (string typeName
)
223 string message
= string.Format ("The type '{0}' cannot"
224 + " be serialized because its parameterless"
225 + " constructor is decorated with declarative"
226 + " security permission attributes."
227 + " Consider using imperative asserts or demands"
228 + " in the constructor.", typeName
);
229 return new InvalidOperationException (message
);
232 protected Exception
CreateInaccessibleConstructorException (string typeName
)
234 string message
= string.Format ("{0} cannot be serialized"
235 + " because it does not have a default public"
236 + " constructor.", typeName
);
237 return new InvalidOperationException (message
);
240 protected Exception
CreateAbstractTypeException (string name
, string ns
)
242 string message
= "The specified type is abstrace: name='" + name
+ "' namespace='" + ns
+ "', at " + CurrentTag ();
243 return new InvalidOperationException (message
);
246 protected Exception
CreateInvalidCastException (Type type
, object value)
248 string message
= String
.Format (CultureInfo
.InvariantCulture
, "Cannot assign object of type {0} to an object of " +
249 "type {1}.", value.GetType (), type
);
250 return new InvalidCastException (message
);
253 protected Exception
CreateReadOnlyCollectionException (string name
)
255 string message
= String
.Format ("Could not serialize {0}. Default constructors are " +
256 "required for collections and enumerators.", name
);
257 return new InvalidOperationException (message
);
260 protected Exception
CreateUnknownConstantException (string value, Type enumType
)
262 string message
= String
.Format ("'{0}' is not a valid value for {1}.", value, enumType
);
263 return new InvalidOperationException (message
);
266 protected Exception
CreateUnknownNodeException ()
268 string message
= CurrentTag () + " was not expected";
269 return new InvalidOperationException (message
);
272 protected Exception
CreateUnknownTypeException (XmlQualifiedName type
)
274 string message
= "The specified type was not recognized: name='" + type
.Name
+ "' namespace='" + type
.Namespace
+ "', at " + CurrentTag ();
275 return new InvalidOperationException (message
);
279 protected void CheckReaderCount (ref int whileIterations
, ref int readerCount
)
281 whileIterations
= whileIterationCount
;
282 readerCount
= readCount
;
286 protected Array
EnsureArrayIndex (Array a
, int index
, Type elementType
)
288 if (a
!= null && index
< a
.Length
)
298 Array result
= Array
.CreateInstance (elementType
, size
);
300 Array
.Copy (a
, result
, index
);
306 protected void FixupArrayRefs (object fixup
)
308 throw new NotImplementedException ();
312 protected int GetArrayLength (string name
, string ns
)
314 throw new NotImplementedException ();
317 protected bool GetNullAttr ()
319 string na
= reader
.GetAttribute (nullX
, w3InstanceNS
);
321 na
= reader
.GetAttribute (nil
, w3InstanceNS
);
323 na
= reader
.GetAttribute (nullX
, w3InstanceNS2000
);
325 na
= reader
.GetAttribute (nullX
, w3InstanceNS1999
);
331 protected object GetTarget (string id
)
333 if (targets
== null) return null;
334 object ob
= targets
[id
];
336 if (referencedObjects
== null) referencedObjects
= new Hashtable ();
337 referencedObjects
[ob
] = ob
;
342 bool TargetReady (string id
)
344 if (targets
== null) return false;
345 return targets
.ContainsKey (id
);
348 protected XmlQualifiedName
GetXsiType ()
350 string typeName
= Reader
.GetAttribute (typeX
, XmlSchema
.InstanceNamespace
);
352 if (typeName
== string.Empty
|| typeName
== null) {
353 typeName
= Reader
.GetAttribute (typeX
, w3InstanceNS1999
);
354 if (typeName
== string.Empty
|| typeName
== null) {
355 typeName
= Reader
.GetAttribute (typeX
, w3InstanceNS2000
);
356 if (typeName
== string.Empty
|| typeName
== null)
361 int i
= typeName
.IndexOf (":");
362 if (i
== -1) return new XmlQualifiedName (typeName
, Reader
.NamespaceURI
);
365 string prefix
= typeName
.Substring(0,i
);
366 string name
= typeName
.Substring (i
+1);
367 return new XmlQualifiedName (name
, Reader
.LookupNamespace (prefix
));
371 protected abstract void InitCallbacks ();
372 protected abstract void InitIDs ();
374 protected bool IsXmlnsAttribute (string name
)
376 int length
= name
.Length
;
381 return (name
== "xmlns");
383 return name
.StartsWith ("xmlns:");
386 protected void ParseWsdlArrayType (XmlAttribute attr
)
388 if (attr
.NamespaceURI
== wsdlNS
&& attr
.LocalName
== arrayType
)
390 string ns
= "", type
, dimensions
;
391 TypeTranslator
.ParseArrayType (attr
.Value
, out type
, out ns
, out dimensions
);
392 if (ns
!= "") ns
= Reader
.LookupNamespace (ns
) + ":";
393 attr
.Value
= ns
+ type
+ dimensions
;
397 protected XmlQualifiedName
ReadElementQualifiedName ()
401 if (reader
.IsEmptyElement
) {
403 return ToXmlQualifiedName (String
.Empty
);
406 reader
.ReadStartElement ();
407 XmlQualifiedName xqn
= ToXmlQualifiedName(reader
.ReadString ());
408 reader
.ReadEndElement ();
412 protected void ReadEndElement ()
416 while (reader
.NodeType
== XmlNodeType
.Whitespace
)
419 if (reader
.NodeType
!= XmlNodeType
.None
) {
420 reader
.ReadEndElement ();
426 protected bool ReadNull ()
433 if (reader
.IsEmptyElement
) {
438 reader
.ReadStartElement();
439 while (reader
.NodeType
!= XmlNodeType
.EndElement
)
446 protected XmlQualifiedName
ReadNullableQualifiedName ()
451 return ReadElementQualifiedName ();
454 protected string ReadNullableString ()
460 return reader
.ReadElementString ();
463 protected bool ReadReference (out string fixupReference
)
465 string href
= reader
.GetAttribute ("href");
467 fixupReference
= null;
472 throw new InvalidOperationException("href not found: " + href
);
474 fixupReference
= href
.Substring (1);
476 if (!reader
.IsEmptyElement
) {
477 reader
.ReadStartElement ();
485 protected object ReadReferencedElement ()
487 return ReadReferencedElement (Reader
.LocalName
, Reader
.NamespaceURI
);
490 WriteCallbackInfo
GetCallbackInfo (XmlQualifiedName qname
)
492 if (typesCallbacks
== null)
494 typesCallbacks
= new Hashtable ();
497 return (WriteCallbackInfo
) typesCallbacks
[qname
];
500 protected object ReadReferencedElement (string name
, string ns
)
502 XmlQualifiedName qname
= GetXsiType ();
503 if (qname
== null) qname
= new XmlQualifiedName (name
, ns
);
505 string id
= Reader
.GetAttribute ("id");
508 // it takes precedence over xsi:type.
509 // Sometimes there are array types in WSDL,
510 // which are not reflected in client proxies.
511 // In SOAP messages, they are marked
512 // soap-env:arrayType, so use it (this could coexist
513 // with xsi:type, which indicates the type in WSDL).
515 string arrayTypeVal
= Reader
.GetAttribute (arrayType
, soapNS
);
517 if (qname
== arrayQName
|| arrayTypeVal
!= null && arrayTypeVal
.Length
> 0)
519 CollectionFixup fixup
= (collFixups
!= null) ? (CollectionFixup
) collFixups
[id
] : null;
520 if (ReadList (out ob
))
522 // List complete (does not contain references)
525 fixup
.Callback (fixup
.Collection
, ob
);
526 collFixups
.Remove (id
);
527 ob
= fixup
.Collection
;
530 else if (fixup
!= null)
532 fixup
.CollectionItems
= (object[])ob
;
533 ob
= fixup
.Collection
;
538 WriteCallbackInfo info
= GetCallbackInfo (qname
);
540 ob
= ReadTypedPrimitive (qname
, id
!= null);
542 ob
= info
.Callback();
548 bool ReadList (out object resultList
)
550 string arrayTypeAttr
= Reader
.GetAttribute (arrayType
, soapNS
);
551 if (arrayTypeAttr
== null) arrayTypeAttr
= Reader
.GetAttribute (arrayType
, wsdlNS
);
553 XmlQualifiedName qn
= ToXmlQualifiedName (arrayTypeAttr
);
554 int i
= qn
.Name
.LastIndexOf ('[');
555 string dim
= qn
.Name
.Substring (i
);
556 string itemType
= qn
.Name
.Substring (0,i
);
557 int count
= Int32
.Parse (dim
.Substring (1, dim
.Length
- 2), CultureInfo
.InvariantCulture
);
561 i
= itemType
.IndexOf ('['); if (i
== -1) i
= itemType
.Length
;
562 string baseType
= itemType
.Substring (0,i
);
563 string arrayTypeName
;
565 if (qn
.Namespace
== w3SchemaNS
)
566 arrayTypeName
= TypeTranslator
.GetPrimitiveTypeData (baseType
).Type
.FullName
+ itemType
.Substring (i
);
569 WriteCallbackInfo info
= GetCallbackInfo (new XmlQualifiedName (baseType
,qn
.Namespace
));
570 arrayTypeName
= info
.Type
.FullName
+ itemType
.Substring (i
) + ", " + info
.Type
.Assembly
.FullName
;
573 list
= Array
.CreateInstance (Type
.GetType (arrayTypeName
), count
);
575 bool listComplete
= true;
577 if (Reader
.IsEmptyElement
) {
581 Reader
.ReadStartElement ();
582 for (int n
=0; n
<count
; n
++)
584 whileIterationCount
++;
586 Reader
.MoveToContent ();
588 object item
= ReadReferencingElement (itemType
, qn
.Namespace
, out id
);
590 list
.SetValue (item
,n
);
593 AddFixup (new CollectionItemFixup (list
, n
, id
));
594 listComplete
= false;
597 whileIterationCount
= 0;
598 Reader
.ReadEndElement ();
605 protected void ReadReferencedElements ()
607 reader
.MoveToContent();
608 XmlNodeType nt
= reader
.NodeType
;
609 while (nt
!= XmlNodeType
.EndElement
&& nt
!= XmlNodeType
.None
) {
610 whileIterationCount
++;
612 ReadReferencedElement ();
613 reader
.MoveToContent ();
614 nt
= reader
.NodeType
;
616 whileIterationCount
= 0;
618 // Registers delayed list
620 if (delayedListFixups
!= null)
622 foreach (DictionaryEntry entry
in delayedListFixups
)
623 AddTarget ((string)entry
.Key
, entry
.Value
);
627 if (collItemFixups
!= null)
629 foreach (CollectionItemFixup itemFixup
in collItemFixups
)
630 itemFixup
.Collection
.SetValue (GetTarget (itemFixup
.Id
), itemFixup
.Index
);
635 if (collFixups
!= null)
637 ICollection cfixups
= collFixups
.Values
;
638 foreach (CollectionFixup fixup
in cfixups
)
639 fixup
.Callback (fixup
.Collection
, fixup
.CollectionItems
);
642 // Fills class instances
646 foreach (Fixup fixup
in fixups
)
647 fixup
.Callback (fixup
);
650 if (targets
!= null) {
651 foreach (DictionaryEntry e
in targets
) {
652 if (e
.Value
!= null && (referencedObjects
== null || !referencedObjects
.Contains (e
.Value
)))
653 UnreferencedObject ((string)e
.Key
, e
.Value
);
658 protected object ReadReferencingElement (out string fixupReference
)
660 return ReadReferencingElement (Reader
.LocalName
, Reader
.NamespaceURI
, false, out fixupReference
);
663 protected object ReadReferencingElement (string name
, string ns
, out string fixupReference
)
665 return ReadReferencingElement (name
, ns
, false, out fixupReference
);
668 protected object ReadReferencingElement (string name
,
670 bool elementCanBeType
,
671 out string fixupReference
)
675 fixupReference
= null;
679 string refid
= Reader
.GetAttribute ("href");
681 if (refid
== string.Empty
|| refid
== null)
683 fixupReference
= null;
685 XmlQualifiedName qname
= GetXsiType ();
686 if (qname
== null) qname
= new XmlQualifiedName (name
, ns
);
687 string arrayTypeAttr
= Reader
.GetAttribute (arrayType
, soapNS
);
689 if (qname
== arrayQName
|| arrayTypeAttr
!= null)
691 delayedListFixups
= EnsureHashtable (delayedListFixups
);
692 fixupReference
= "__<" + (delayedFixupId
++) + ">";
694 ReadList (out items
);
695 delayedListFixups
[fixupReference
] = items
;
700 WriteCallbackInfo info
= GetCallbackInfo (qname
);
702 return ReadTypedPrimitive (qname
, true);
704 return info
.Callback();
709 if (refid
.StartsWith ("#")) refid
= refid
.Substring (1);
713 if (TargetReady (refid
))
715 fixupReference
= null;
716 return GetTarget (refid
);
720 fixupReference
= refid
;
726 protected IXmlSerializable
ReadSerializable (IXmlSerializable serializable
)
728 if (ReadNull ()) return null;
729 int depth
= reader
.Depth
;
731 serializable
.ReadXml (reader
);
732 Reader
.MoveToContent ();
733 while (reader
.Depth
> depth
)
735 if (reader
.Depth
== depth
&& reader
.NodeType
== XmlNodeType
.EndElement
)
736 reader
.ReadEndElement ();
740 protected string ReadString (string value)
743 if (value == null || value == String
.Empty
)
744 return reader
.ReadString ();
746 return (value + reader
.ReadString ());
749 protected object ReadTypedPrimitive (XmlQualifiedName qname
)
751 return ReadTypedPrimitive (qname
, false);
754 object ReadTypedPrimitive (XmlQualifiedName qname
, bool reportUnknown
)
756 if (qname
== null) qname
= GetXsiType ();
758 TypeData typeData
= TypeTranslator
.FindPrimitiveTypeData (qname
.Name
);
759 if (typeData
== null || typeData
.SchemaType
!= SchemaTypes
.Primitive
)
761 // Put everything into a node array
763 XmlNode node
= Document
.ReadNode (reader
);
766 OnUnknownNode (node
, null, null);
768 if (node
.ChildNodes
.Count
== 0 && node
.Attributes
.Count
== 0)
769 return new Object ();
771 XmlElement elem
= node
as XmlElement
;
774 return new XmlNode
[] {node}
;
776 XmlNode
[] nodes
= new XmlNode
[elem
.Attributes
.Count
+ elem
.ChildNodes
.Count
];
778 foreach (XmlNode no
in elem
.Attributes
)
780 foreach (XmlNode no
in elem
.ChildNodes
)
786 if (typeData
.Type
== typeof (XmlQualifiedName
)) return ReadNullableQualifiedName ();
788 return XmlCustomFormatter
.FromXmlString (typeData
, Reader
.ReadElementString ());
791 protected XmlNode
ReadXmlNode (bool wrapped
)
794 XmlNode node
= Document
.ReadNode (reader
);
796 return node
.FirstChild
;
801 protected XmlDocument
ReadXmlDocument (bool wrapped
)
806 reader
.ReadStartElement ();
807 reader
.MoveToContent ();
808 XmlDocument doc
= new XmlDocument ();
809 XmlNode node
= doc
.ReadNode (reader
);
810 doc
.AppendChild (node
);
813 reader
.ReadEndElement ();
818 protected void Referenced (object o
)
821 if (referencedObjects
== null) referencedObjects
= new Hashtable ();
822 referencedObjects
[o
] = o
;
826 protected Array
ShrinkArray (Array a
, int length
, Type elementType
, bool isNullable
)
828 if (length
== 0 && isNullable
) return null;
829 if (a
== null) return Array
.CreateInstance (elementType
, length
);
830 if (a
.Length
== length
) return a
;
832 Array result
= Array
.CreateInstance (elementType
, length
);
833 Array
.Copy (a
, result
, length
);
837 protected byte[] ToByteArrayBase64 (bool isNull
)
841 Reader
.ReadString ();
845 return ToByteArrayBase64 (Reader
.ReadString ());
848 protected static byte[] ToByteArrayBase64 (string value)
850 return Convert
.FromBase64String (value);
853 protected byte[] ToByteArrayHex (bool isNull
)
857 Reader
.ReadString ();
861 return ToByteArrayHex (Reader
.ReadString ());
864 protected static byte[] ToByteArrayHex (string value)
866 return XmlConvert
.FromBinHexString (value);
869 protected static char ToChar (string value)
871 return XmlCustomFormatter
.ToChar (value);
874 protected static DateTime
ToDate (string value)
876 return XmlCustomFormatter
.ToDate (value);
879 protected static DateTime
ToDateTime (string value)
881 return XmlCustomFormatter
.ToDateTime (value);
884 protected static long ToEnum (string value, Hashtable h
, string typeName
)
886 return XmlCustomFormatter
.ToEnum (value, h
, typeName
, true);
889 protected static DateTime
ToTime (string value)
891 return XmlCustomFormatter
.ToTime (value);
894 protected static string ToXmlName (string value)
896 return XmlCustomFormatter
.ToXmlName (value);
899 protected static string ToXmlNCName (string value)
901 return XmlCustomFormatter
.ToXmlNCName (value);
904 protected static string ToXmlNmToken (string value)
906 return XmlCustomFormatter
.ToXmlNmToken (value);
909 protected static string ToXmlNmTokens (string value)
911 return XmlCustomFormatter
.ToXmlNmTokens (value);
914 protected XmlQualifiedName
ToXmlQualifiedName (string value)
918 int lastColon
= value.LastIndexOf (':');
919 string decodedValue
= XmlConvert
.DecodeName (value);
921 name
= reader
.NameTable
.Add (decodedValue
);
922 ns
= reader
.LookupNamespace (String
.Empty
);
924 string prefix
= value.Substring (0, lastColon
);
925 ns
= reader
.LookupNamespace (prefix
);
927 throw new InvalidOperationException ("namespace " + prefix
+ " not defined");
929 name
= reader
.NameTable
.Add (value.Substring (lastColon
+ 1));
932 return new XmlQualifiedName (name
, ns
);
935 protected void UnknownAttribute (object o
, XmlAttribute attr
)
937 UnknownAttribute (o
, attr
, null);
943 void UnknownAttribute (object o
, XmlAttribute attr
, string qnames
)
945 int line_number
, line_position
;
947 if (Reader
is XmlTextReader
){
948 line_number
= ((XmlTextReader
)Reader
).LineNumber
;
949 line_position
= ((XmlTextReader
)Reader
).LinePosition
;
955 XmlAttributeEventArgs args
= new XmlAttributeEventArgs (attr
, line_number
, line_position
, o
);
957 args
.ExpectedAttributes
= qnames
;
960 if (eventSource
!= null)
961 eventSource
.OnUnknownAttribute (args
);
964 protected void UnknownElement (object o
, XmlElement elem
)
966 UnknownElement (o
, elem
, null);
972 void UnknownElement (object o
, XmlElement elem
, string qnames
)
974 int line_number
, line_position
;
976 if (Reader
is XmlTextReader
){
977 line_number
= ((XmlTextReader
)Reader
).LineNumber
;
978 line_position
= ((XmlTextReader
)Reader
).LinePosition
;
984 XmlElementEventArgs args
= new XmlElementEventArgs (elem
, line_number
, line_position
, o
);
986 args
.ExpectedElements
= qnames
;
989 if (eventSource
!= null)
990 eventSource
.OnUnknownElement (args
);
993 protected void UnknownNode (object o
)
995 UnknownNode (o
, null);
1001 void UnknownNode (object o
, string qnames
)
1003 OnUnknownNode (ReadXmlNode (false), o
, qnames
);
1006 void OnUnknownNode (XmlNode node
, object o
, string qnames
)
1008 int line_number
, line_position
;
1010 if (Reader
is XmlTextReader
){
1011 line_number
= ((XmlTextReader
)Reader
).LineNumber
;
1012 line_position
= ((XmlTextReader
)Reader
).LinePosition
;
1018 if (node
is XmlAttribute
)
1020 UnknownAttribute (o
, (XmlAttribute
)node
, qnames
);
1023 else if (node
is XmlElement
)
1025 UnknownElement (o
, (XmlElement
) node
, qnames
);
1030 if (eventSource
!= null)
1031 eventSource
.OnUnknownNode (new XmlNodeEventArgs(line_number
, line_position
, node
.LocalName
, node
.Name
, node
.NamespaceURI
, node
.NodeType
, o
, node
.Value
));
1033 if (Reader
.ReadState
== ReadState
.EndOfFile
)
1034 throw new InvalidOperationException ("End of document found");
1038 protected void UnreferencedObject (string id
, object o
)
1040 if (eventSource
!= null)
1041 eventSource
.OnUnreferencedObject (new UnreferencedObjectEventArgs (o
,id
));
1044 #endregion // Methods
1046 class WriteCallbackInfo
1049 public string TypeName
;
1050 public string TypeNs
;
1051 public XmlSerializationReadCallback Callback
;
1054 protected class CollectionFixup
{
1056 XmlSerializationCollectionFixupCallback callback
;
1058 object collectionItems
;
1061 public CollectionFixup (object collection
, XmlSerializationCollectionFixupCallback callback
, string id
)
1063 this.callback
= callback
;
1064 this.collection
= collection
;
1068 public XmlSerializationCollectionFixupCallback Callback
{
1069 get { return callback; }
1072 public object Collection
{
1073 get { return collection; }
1080 internal object CollectionItems
1082 get { return collectionItems; }
1083 set { collectionItems = value; }
1087 protected class Fixup
{
1091 XmlSerializationFixupCallback callback
;
1093 public Fixup (object o
, XmlSerializationFixupCallback callback
, int count
)
1096 this.callback
= callback
;
1097 this.ids
= new string[count
];
1100 public Fixup (object o
, XmlSerializationFixupCallback callback
, string[] ids
)
1104 this.callback
= callback
;
1107 public XmlSerializationFixupCallback Callback
{
1108 get { return callback; }
1111 public string[] Ids
{
1115 public object Source
{
1116 get { return source; }
1117 set { source = value; }
1121 protected class CollectionItemFixup
1127 public CollectionItemFixup (Array list
, int index
, string id
)
1134 public Array Collection
1136 get { return list; }
1141 get { return index; }
1152 protected bool DecodeName
1154 get { throw new NotImplementedException(); }
1155 set { throw new NotImplementedException(); }
1159 protected string CollapseWhitespace (string value)
1161 throw new NotImplementedException ();
1165 protected Exception
CreateBadDerivationException (
1173 throw new NotImplementedException ();
1177 protected Exception
CreateInvalidCastException (Type type
, object value, string id
)
1179 throw new NotImplementedException ();
1183 protected Exception
CreateMissingIXmlSerializableType (string name
, string ns
, string clrType
)
1185 throw new NotImplementedException ();
1189 protected string ReadString (string value, bool trim
)
1191 throw new NotImplementedException ();
1195 protected object ReadTypedNull (XmlQualifiedName type
)
1197 throw new NotImplementedException ();
1201 protected static Assembly
ResolveDynamicAssembly (string assemblyFullName
)
1203 throw new NotImplementedException ();