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 #if !NET_2_1 || MONOTOUCH
38 internal abstract class SerializationSource
42 bool canBeGenerated
= true;
44 public SerializationSource (string namspace
, Type
[] includedTypes
)
46 this.namspace
= namspace
;
47 this.includedTypes
= includedTypes
;
50 protected bool BaseEquals (SerializationSource other
)
52 if (namspace
!= other
.namspace
) return false;
53 if (canBeGenerated
!= other
.canBeGenerated
) return false;
55 if (includedTypes
== null)
56 return other
.includedTypes
== null;
58 if (other
.includedTypes
== null || includedTypes
.Length
!= other
.includedTypes
.Length
) return false;
59 for (int n
=0; n
<includedTypes
.Length
; n
++)
60 if (!includedTypes
[n
].Equals (other
.includedTypes
[n
])) return false;
65 public virtual bool CanBeGenerated
67 get { return canBeGenerated; }
68 set { canBeGenerated = value; }
72 internal class XmlTypeSerializationSource
: SerializationSource
74 string attributeOverridesHash
;
78 public XmlTypeSerializationSource (Type type
, XmlRootAttribute root
, XmlAttributeOverrides attributeOverrides
, string namspace
, Type
[] includedTypes
)
79 : base (namspace
, includedTypes
)
81 if (attributeOverrides
!= null) {
82 StringBuilder sb
= new StringBuilder ();
83 attributeOverrides
.AddKeyHash (sb
);
84 attributeOverridesHash
= sb
.ToString ();
88 StringBuilder sb
= new StringBuilder ();
90 rootHash
= sb
.ToString ();
96 public override bool Equals (object o
)
98 XmlTypeSerializationSource other
= o
as XmlTypeSerializationSource
;
99 if (other
== null) return false;
101 if (!type
.Equals(other
.type
)) return false;
102 if (rootHash
!= other
.rootHash
) return false;
103 if (attributeOverridesHash
!= other
.attributeOverridesHash
) return false;
105 return base.BaseEquals (other
);
108 public override int GetHashCode ()
110 return type
.GetHashCode ();
114 internal class SoapTypeSerializationSource
: SerializationSource
116 string attributeOverridesHash
;
119 public SoapTypeSerializationSource (Type type
, SoapAttributeOverrides attributeOverrides
, string namspace
, Type
[] includedTypes
)
120 : base (namspace
, includedTypes
)
122 if (attributeOverrides
!= null) {
123 StringBuilder sb
= new StringBuilder ();
124 attributeOverrides
.AddKeyHash (sb
);
125 attributeOverridesHash
= sb
.ToString ();
131 public override bool Equals (object o
)
133 SoapTypeSerializationSource other
= o
as SoapTypeSerializationSource
;
134 if (other
== null) return false;
135 if (!type
.Equals(other
.type
)) return false;
136 if (attributeOverridesHash
!= other
.attributeOverridesHash
) return false;
138 return base.BaseEquals (other
);
141 public override int GetHashCode ()
143 return type
.GetHashCode ();
147 internal class MembersSerializationSource
: SerializationSource
150 bool hasWrapperElement
;
155 public MembersSerializationSource (string elementName
, bool hasWrapperElement
, XmlReflectionMember
[] members
, bool writeAccessors
,
156 bool literalFormat
, string namspace
, Type
[] includedTypes
)
157 : base (namspace
, includedTypes
)
159 this.elementName
= elementName
;
160 this.hasWrapperElement
= hasWrapperElement
;
161 this.writeAccessors
= writeAccessors
;
162 this.literalFormat
= literalFormat
;
164 StringBuilder sb
= new StringBuilder ();
165 sb
.Append (members
.Length
.ToString(CultureInfo
.InvariantCulture
));
166 foreach (XmlReflectionMember mem
in members
)
169 membersHash
= sb
.ToString();
173 public override bool Equals (object o
)
175 MembersSerializationSource other
= o
as MembersSerializationSource
;
176 if (other
== null) return false;
177 if (literalFormat
= other
.literalFormat
) return false;
178 if (elementName
!= other
.elementName
) return false;
179 if (hasWrapperElement
!= other
.hasWrapperElement
) return false;
180 if (membersHash
!= other
.membersHash
) return false;
182 return base.BaseEquals (other
);
185 public override int GetHashCode ()
187 return membersHash
.GetHashCode ();