2 // System.Xml.Serialization.SerializationSource.cs
5 // Lluis Sanchez Gual (lluis@ximian.com)
7 // Copyright (C) 2004 Novell, Inc.
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 using System.Collections;
32 using System.Globalization;
35 namespace System.Xml.Serialization
37 internal class SerializationSource
39 ArrayList includedTypes;
41 bool canBeGenerated = true;
43 public SerializationSource (string namspace, ArrayList includedTypes)
45 this.namspace = namspace;
46 this.includedTypes = includedTypes;
49 public override bool Equals (object o)
51 SerializationSource other = o as SerializationSource;
52 if (other == null) return false;
53 if (namspace != other.namspace) return false;
54 if (canBeGenerated != other.canBeGenerated) return false;
56 if (includedTypes == null)
57 return other.includedTypes == null;
59 if (includedTypes.Count != other.includedTypes.Count) return false;
60 for (int n=0; n<includedTypes.Count; n++)
61 if (!includedTypes[n].Equals (other.includedTypes[n])) return false;
66 public virtual bool CanBeGenerated
68 get { return canBeGenerated; }
69 set { canBeGenerated = value; }
73 internal class XmlTypeSerializationSource: SerializationSource
75 string attributeOverridesHash;
79 public XmlTypeSerializationSource (Type type, XmlRootAttribute root, XmlAttributeOverrides attributeOverrides, string namspace, ArrayList includedTypes)
80 : base (namspace, includedTypes)
82 if (attributeOverrides != null) {
83 StringBuilder sb = new StringBuilder ();
84 attributeOverrides.AddKeyHash (sb);
85 attributeOverridesHash = sb.ToString ();
89 StringBuilder sb = new StringBuilder ();
91 rootHash = sb.ToString ();
97 public override bool Equals (object o)
99 XmlTypeSerializationSource other = o as XmlTypeSerializationSource;
100 if (other == null) return false;
102 if (!type.Equals(other.type)) return false;
103 if (rootHash != other.rootHash) return false;
104 if (attributeOverridesHash != other.attributeOverridesHash) return false;
106 return base.Equals (o);
109 public override int GetHashCode ()
111 return type.GetHashCode ();
115 internal class SoapTypeSerializationSource: SerializationSource
117 string attributeOverridesHash;
120 public SoapTypeSerializationSource (Type type, SoapAttributeOverrides attributeOverrides, string namspace, ArrayList includedTypes)
121 : base (namspace, includedTypes)
123 if (attributeOverrides != null) {
124 StringBuilder sb = new StringBuilder ();
125 attributeOverrides.AddKeyHash (sb);
126 attributeOverridesHash = sb.ToString ();
132 public override bool Equals (object o)
134 SoapTypeSerializationSource other = o as SoapTypeSerializationSource;
135 if (other == null) return false;
136 if (!type.Equals(other.type)) return false;
137 if (attributeOverridesHash != other.attributeOverridesHash) return false;
139 return base.Equals (o);
142 public override int GetHashCode ()
144 return type.GetHashCode ();
148 internal class MembersSerializationSource: SerializationSource
151 bool hasWrapperElement;
156 public MembersSerializationSource (string elementName, bool hasWrapperElement, XmlReflectionMember [] members, bool writeAccessors,
157 bool literalFormat, string namspace, ArrayList includedTypes)
158 : base (namspace, includedTypes)
160 this.elementName = elementName;
161 this.hasWrapperElement = hasWrapperElement;
162 this.writeAccessors = writeAccessors;
163 this.literalFormat = literalFormat;
165 StringBuilder sb = new StringBuilder ();
166 sb.Append (members.Length.ToString(CultureInfo.InvariantCulture));
167 foreach (XmlReflectionMember mem in members)
170 membersHash = sb.ToString();
174 public override bool Equals (object o)
176 MembersSerializationSource other = o as MembersSerializationSource;
177 if (other == null) return false;
178 if (literalFormat = other.literalFormat) return false;
179 if (elementName != other.elementName) return false;
180 if (hasWrapperElement != other.hasWrapperElement) return false;
181 if (membersHash != other.membersHash) return false;
183 return base.Equals (o);
186 public override int GetHashCode ()
188 return membersHash.GetHashCode ();
192 internal class KeyHelper
194 public static void AddField (StringBuilder sb, int n, string val)
196 AddField (sb, n, val, null);
199 public static void AddField (StringBuilder sb, int n, string val, string def)
202 sb.Append (n.ToString());
203 sb.Append (val.Length.ToString(CultureInfo.InvariantCulture));
208 public static void AddField (StringBuilder sb, int n, bool val)
210 AddField (sb, n, val, false);
213 public static void AddField (StringBuilder sb, int n, bool val, bool def)
216 sb.Append (n.ToString());
219 public static void AddField (StringBuilder sb, int n, int val, int def)
222 sb.Append (n.ToString());
223 sb.Append (val.ToString(CultureInfo.InvariantCulture));
227 public static void AddField (StringBuilder sb, int n, Type val)
230 sb.Append (n.ToString(CultureInfo.InvariantCulture));
231 sb.Append (val.ToString());