XmlAttributeOverrides.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. //
  2. // XmlAttributeOverrides.cs:
  3. //
  4. // Author:
  5. // John Donagher ([email protected])
  6. //
  7. // (C) 2002 John Donagher
  8. //
  9. using System;
  10. using System.Collections;
  11. namespace System.Xml.Serialization
  12. {
  13. /// <summary>
  14. /// Summary description for XmlAttributeOverrides.
  15. /// </summary>
  16. public class XmlAttributeOverrides
  17. {
  18. private Hashtable overrides;
  19. public XmlAttributeOverrides ()
  20. {
  21. overrides = new Hashtable();
  22. }
  23. public XmlAttributes this [Type type]
  24. {
  25. get { return this [type, string.Empty]; }
  26. }
  27. public XmlAttributes this [Type type, string member]
  28. {
  29. get
  30. {
  31. return (XmlAttributes) overrides[GetKey(type,member)];
  32. }
  33. }
  34. public void Add (Type type, XmlAttributes attributes)
  35. {
  36. Add(type, string.Empty, attributes);
  37. }
  38. public void Add (Type type, string member, XmlAttributes attributes)
  39. {
  40. if(overrides[GetKey(type, member)] != null)
  41. throw new Exception("The attributes for the given type and Member already exist in the collection");
  42. overrides.Add(GetKey(type,member), attributes);
  43. }
  44. private TypeMember GetKey(Type type, string member)
  45. {
  46. return new TypeMember(type, member);
  47. }
  48. internal bool InternalEquals (XmlAttributeOverrides other)
  49. {
  50. if (other == null) return false;
  51. if (overrides.Count != other.overrides.Count) return false;
  52. foreach (DictionaryEntry entry in overrides)
  53. {
  54. XmlAttributes val = (XmlAttributes) other.overrides [entry.Key];
  55. if (val == null || !val.Equals ((XmlAttributes) entry.Value)) return false;
  56. }
  57. return true;
  58. }
  59. }
  60. }