SoapAttributes.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. //
  2. // SoapAttributes.cs:
  3. //
  4. // Author:
  5. // John Donagher ([email protected])
  6. //
  7. // (C) 2002 John Donagher
  8. //
  9. //
  10. // Permission is hereby granted, free of charge, to any person obtaining
  11. // a copy of this software and associated documentation files (the
  12. // "Software"), to deal in the Software without restriction, including
  13. // without limitation the rights to use, copy, modify, merge, publish,
  14. // distribute, sublicense, and/or sell copies of the Software, and to
  15. // permit persons to whom the Software is furnished to do so, subject to
  16. // the following conditions:
  17. //
  18. // The above copyright notice and this permission notice shall be
  19. // included in all copies or substantial portions of the Software.
  20. //
  21. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  22. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  23. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  24. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  25. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  26. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  27. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  28. //
  29. using System.Reflection;
  30. using System;
  31. using System.ComponentModel;
  32. namespace System.Xml.Serialization
  33. {
  34. /// <summary>
  35. /// Summary description for SoapAttributes.
  36. /// </summary>
  37. public class SoapAttributes
  38. {
  39. private SoapAttributeAttribute soapAttribute;
  40. private object soapDefaultValue = System.DBNull.Value;
  41. private SoapElementAttribute soapElement;
  42. private SoapEnumAttribute soapEnum;
  43. private bool soapIgnore;
  44. private SoapTypeAttribute soapType;
  45. public SoapAttributes ()
  46. {
  47. }
  48. public SoapAttributes (ICustomAttributeProvider provider)
  49. {
  50. object[] attributes = provider.GetCustomAttributes(false);
  51. foreach(object obj in attributes)
  52. {
  53. if(obj is SoapAttributeAttribute)
  54. soapAttribute = (SoapAttributeAttribute) obj;
  55. else if(obj is DefaultValueAttribute)
  56. soapDefaultValue = ((DefaultValueAttribute) obj).Value;
  57. else if(obj is SoapElementAttribute)
  58. soapElement = (SoapElementAttribute) obj;
  59. else if(obj is SoapEnumAttribute)
  60. soapEnum = (SoapEnumAttribute) obj;
  61. else if(obj is SoapIgnoreAttribute)
  62. soapIgnore = true;
  63. else if(obj is SoapTypeAttribute)
  64. soapType = (SoapTypeAttribute) obj;
  65. }
  66. }
  67. public SoapAttributeAttribute SoapAttribute
  68. {
  69. get { return soapAttribute; }
  70. set { soapAttribute = value; }
  71. }
  72. public object SoapDefaultValue
  73. {
  74. get { return soapDefaultValue; }
  75. set { soapDefaultValue = value; }
  76. }
  77. public SoapElementAttribute SoapElement
  78. {
  79. get { return soapElement; }
  80. set { soapElement = value; }
  81. }
  82. public SoapEnumAttribute SoapEnum
  83. {
  84. get { return soapEnum; }
  85. set { soapEnum = value; }
  86. }
  87. public bool SoapIgnore
  88. {
  89. get { return soapIgnore; }
  90. set { soapIgnore = value; }
  91. }
  92. public SoapTypeAttribute SoapType
  93. {
  94. get { return soapType; }
  95. set { soapType = value; }
  96. }
  97. internal void AddKeyHash (System.Text.StringBuilder sb)
  98. {
  99. sb.Append ("SA ");
  100. if (soapIgnore)
  101. sb.Append ('i');
  102. if (soapAttribute != null)
  103. soapAttribute.AddKeyHash (sb);
  104. if (soapElement != null)
  105. soapElement.AddKeyHash (sb);
  106. if (soapEnum != null)
  107. soapEnum.AddKeyHash (sb);
  108. if (soapType != null)
  109. soapType.AddKeyHash (sb);
  110. if (soapDefaultValue == null) {
  111. sb.Append ("n");
  112. }
  113. else if (!(soapDefaultValue is System.DBNull)) {
  114. string v = XmlCustomFormatter.ToXmlString (TypeTranslator.GetTypeData (soapDefaultValue.GetType()), soapDefaultValue);
  115. sb.Append ("v" + v);
  116. }
  117. sb.Append ("|");
  118. }
  119. }
  120. }