SerializationSource.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. //
  2. // System.Xml.Serialization.SerializationSource.cs
  3. //
  4. // Author:
  5. // Lluis Sanchez Gual ([email protected])
  6. //
  7. // Copyright (C) 2004 Novell, Inc.
  8. //
  9. using System.Collections;
  10. namespace System.Xml.Serialization
  11. {
  12. internal class SerializationSource
  13. {
  14. ArrayList includedTypes;
  15. string namspace;
  16. bool canBeGenerated = true;
  17. public SerializationSource (string namspace, ArrayList includedTypes)
  18. {
  19. this.namspace = namspace;
  20. this.includedTypes = includedTypes;
  21. }
  22. public override bool Equals (object o)
  23. {
  24. SerializationSource other = o as SerializationSource;
  25. if (other == null) return false;
  26. if (namspace != other.namspace) return false;
  27. if (canBeGenerated != other.canBeGenerated) return false;
  28. if (includedTypes == null)
  29. return other.includedTypes == null;
  30. if (includedTypes.Count != other.includedTypes.Count) return false;
  31. for (int n=0; n<includedTypes.Count; n++)
  32. if (!includedTypes[n].Equals (other.includedTypes[n])) return false;
  33. return true;
  34. }
  35. public virtual bool CanBeGenerated
  36. {
  37. get { return canBeGenerated; }
  38. set { canBeGenerated = value; }
  39. }
  40. }
  41. internal class XmlTypeSerializationSource: SerializationSource
  42. {
  43. XmlAttributeOverrides attributeOverrides;
  44. Type type;
  45. XmlRootAttribute root;
  46. public XmlTypeSerializationSource (Type type, XmlRootAttribute root, XmlAttributeOverrides attributeOverrides, string namspace, ArrayList includedTypes)
  47. : base (namspace, includedTypes)
  48. {
  49. this.attributeOverrides = attributeOverrides;
  50. this.type = type;
  51. this.root = root;
  52. }
  53. public override bool Equals (object o)
  54. {
  55. XmlTypeSerializationSource other = o as XmlTypeSerializationSource;
  56. if (other == null) return false;
  57. if (!type.Equals(other.type)) return false;
  58. if (root == null) {
  59. if (other.root != null)
  60. return false;
  61. }
  62. else if (!root.InternalEquals (other.root))
  63. return false;
  64. if (!base.Equals (o))
  65. return false;
  66. if (attributeOverrides == null)
  67. return other.attributeOverrides == null;
  68. return attributeOverrides.InternalEquals (other.attributeOverrides);
  69. }
  70. public override int GetHashCode ()
  71. {
  72. return type.GetHashCode ();
  73. }
  74. }
  75. internal class SoapTypeSerializationSource: SerializationSource
  76. {
  77. SoapAttributeOverrides attributeOverrides;
  78. Type type;
  79. public SoapTypeSerializationSource (Type type, SoapAttributeOverrides attributeOverrides, string namspace, ArrayList includedTypes)
  80. : base (namspace, includedTypes)
  81. {
  82. this.attributeOverrides = attributeOverrides;
  83. this.type = type;
  84. }
  85. public override bool Equals (object o)
  86. {
  87. SoapTypeSerializationSource other = o as SoapTypeSerializationSource;
  88. if (other == null) return false;
  89. if (!type.Equals(other.type)) return false;
  90. if (!base.Equals (o))
  91. return false;
  92. if (attributeOverrides == null)
  93. return other.attributeOverrides == null;
  94. return attributeOverrides.InternalEquals (other.attributeOverrides);
  95. }
  96. public override int GetHashCode ()
  97. {
  98. return type.GetHashCode ();
  99. }
  100. }
  101. internal class MembersSerializationSource: SerializationSource
  102. {
  103. string elementName;
  104. bool hasWrapperElement;
  105. XmlReflectionMember [] members;
  106. bool writeAccessors;
  107. bool literalFormat;
  108. int hcode = -1;
  109. public MembersSerializationSource (string elementName, bool hasWrapperElement, XmlReflectionMember [] members, bool writeAccessors,
  110. bool literalFormat, string namspace, ArrayList includedTypes)
  111. : base (namspace, includedTypes)
  112. {
  113. this.elementName = elementName;
  114. this.hasWrapperElement = hasWrapperElement;
  115. this.members = members;
  116. this.writeAccessors = writeAccessors;
  117. this.literalFormat = literalFormat;
  118. }
  119. public override bool Equals (object o)
  120. {
  121. MembersSerializationSource other = o as MembersSerializationSource;
  122. if (other == null) return false;
  123. if (literalFormat = other.literalFormat) return false;
  124. if (elementName != other.elementName) return false;
  125. if (hasWrapperElement != other.hasWrapperElement) return false;
  126. if (members.Length != other.members.Length) return false;
  127. if (!base.Equals (o))
  128. return false;
  129. for (int n=0; n<members.Length; n++)
  130. if (!members[n].InternalEquals (other.members[n])) return false;
  131. return true;
  132. }
  133. public override int GetHashCode ()
  134. {
  135. if (hcode != -1) return hcode;
  136. System.Text.StringBuilder sb = new System.Text.StringBuilder ();
  137. foreach (XmlReflectionMember mem in members)
  138. sb.Append (mem.MemberName);
  139. hcode = sb.ToString().GetHashCode ();
  140. return hcode;
  141. }
  142. }
  143. }