2
0

XmlAttributeOverrides.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 void AddKeyHash (System.Text.StringBuilder sb)
  49. {
  50. sb.Append ("XAO ");
  51. foreach (DictionaryEntry entry in overrides)
  52. {
  53. XmlAttributes val = (XmlAttributes) entry.Value;
  54. sb.Append (entry.Key.ToString()).Append(' ');
  55. val.AddKeyHash (sb);
  56. }
  57. sb.Append ("|");
  58. }
  59. }
  60. }