SoapAttributeOverrides.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. //
  2. // SoapAttributeOverrides.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. ///
  15. /// </summary>
  16. public class SoapAttributeOverrides
  17. {
  18. /// <summary>
  19. /// This class requires to store SoapAttrributes indexed by a key containg
  20. /// both Type and Member Name. There are 3 approaches to this IMO.
  21. /// 1. Make the key as "FullTypeName..MemberName", with ".." seperating Type and Member.
  22. /// 2. Use a jagged 2D hashtable. The main hashtable is indexed by Type and each value
  23. /// contains another hashtable which is indexed by member names. (Too many hashtables)
  24. /// 3. Use a new class which emcompasses the Type and MemberName. An implementation is there
  25. /// in TypeMember class in this namespace. (Too many instantiations of the class needed)
  26. ///
  27. /// Method 1 is the most elegent, but I am not sure if the seperator is language insensitive.
  28. /// What if someone writes a language which allows . in the member names.
  29. /// </summary>
  30. ///
  31. private Hashtable overrides;
  32. public SoapAttributeOverrides ()
  33. {
  34. overrides = new Hashtable();
  35. }
  36. public SoapAttributes this [Type type]
  37. {
  38. get { return this [type, string.Empty]; }
  39. }
  40. public SoapAttributes this [Type type, string member]
  41. {
  42. get
  43. {
  44. return (SoapAttributes) overrides[GetKey(type,member)];
  45. }
  46. }
  47. public void Add (Type type, SoapAttributes attributes)
  48. {
  49. Add(type, string.Empty, attributes);
  50. }
  51. public void Add (Type type, string member, SoapAttributes attributes)
  52. {
  53. if(overrides[GetKey(type, member)] != null)
  54. throw new Exception("The attributes for the given type and Member already exist in the collection");
  55. overrides.Add(GetKey(type,member), attributes);
  56. }
  57. private TypeMember GetKey(Type type, string member)
  58. {
  59. return new TypeMember(type, member);
  60. }
  61. internal void AddKeyHash (System.Text.StringBuilder sb)
  62. {
  63. sb.Append ("SAO ");
  64. foreach (DictionaryEntry entry in overrides)
  65. {
  66. SoapAttributes val = (SoapAttributes) overrides [entry.Key];
  67. sb.Append (entry.Key.ToString()).Append(' ');
  68. val.AddKeyHash (sb);
  69. }
  70. sb.Append ("|");
  71. }
  72. }
  73. }