2
0

XmlMemberMapping.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. //
  2. // System.Xml.Serialization.XmlMemberMapping
  3. //
  4. // Author:
  5. // Tim Coleman ([email protected])
  6. // Lluis Sanchez Gual ([email protected])
  7. //
  8. // Copyright (C) Tim Coleman, 2002
  9. //
  10. //
  11. // Permission is hereby granted, free of charge, to any person obtaining
  12. // a copy of this software and associated documentation files (the
  13. // "Software"), to deal in the Software without restriction, including
  14. // without limitation the rights to use, copy, modify, merge, publish,
  15. // distribute, sublicense, and/or sell copies of the Software, and to
  16. // permit persons to whom the Software is furnished to do so, subject to
  17. // the following conditions:
  18. //
  19. // The above copyright notice and this permission notice shall be
  20. // included in all copies or substantial portions of the Software.
  21. //
  22. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  23. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  24. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  25. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  26. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  27. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  28. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  29. //
  30. using System.Xml.Schema;
  31. namespace System.Xml.Serialization
  32. {
  33. public class XmlMemberMapping {
  34. XmlTypeMapMember _mapMember;
  35. string _elementName;
  36. string _memberName;
  37. string _namespace;
  38. string _typeNamespace;
  39. XmlSchemaForm _form;
  40. internal XmlMemberMapping (string memberName, string defaultNamespace, XmlTypeMapMember mapMem, bool encodedFormat)
  41. {
  42. _mapMember = mapMem;
  43. _memberName = memberName;
  44. if (mapMem is XmlTypeMapMemberAnyElement)
  45. {
  46. XmlTypeMapMemberAnyElement anyelem = (XmlTypeMapMemberAnyElement) mapMem;
  47. XmlTypeMapElementInfo info = (XmlTypeMapElementInfo) anyelem.ElementInfo[anyelem.ElementInfo.Count-1];
  48. _elementName = info.ElementName;
  49. _namespace = info.Namespace;
  50. if (info.MappedType != null) _typeNamespace = info.MappedType.Namespace;
  51. else _typeNamespace = "";
  52. }
  53. else if (mapMem is XmlTypeMapMemberElement)
  54. {
  55. XmlTypeMapElementInfo info = (XmlTypeMapElementInfo) ((XmlTypeMapMemberElement)mapMem).ElementInfo[0];
  56. _elementName = info.ElementName;
  57. if (encodedFormat)
  58. {
  59. _namespace = defaultNamespace;
  60. if (info.MappedType != null) _typeNamespace = "";
  61. else _typeNamespace = info.DataTypeNamespace;
  62. }
  63. else
  64. {
  65. _namespace = info.Namespace;
  66. if (info.MappedType != null) _typeNamespace = info.MappedType.Namespace;
  67. else _typeNamespace = "";
  68. _form = info.Form;
  69. }
  70. }
  71. else
  72. {
  73. _elementName = _memberName;
  74. _namespace = "";
  75. }
  76. if (_form == XmlSchemaForm.None)
  77. _form = XmlSchemaForm.Qualified;
  78. }
  79. #region Properties
  80. public bool Any {
  81. get { return _mapMember is XmlTypeMapMemberAnyElement; }
  82. }
  83. public string ElementName {
  84. get { return _elementName; }
  85. }
  86. public string MemberName {
  87. get { return _memberName; }
  88. }
  89. public string Namespace {
  90. get { return _namespace; }
  91. }
  92. public string TypeFullName {
  93. get { return _mapMember.TypeData.FullTypeName; }
  94. }
  95. public string TypeName {
  96. get { return _mapMember.TypeData.XmlType; }
  97. }
  98. public string TypeNamespace {
  99. get { return _typeNamespace; }
  100. }
  101. internal XmlTypeMapMember TypeMapMember {
  102. get { return _mapMember; }
  103. }
  104. internal XmlSchemaForm Form {
  105. get { return _form; }
  106. }
  107. #if NET_2_0
  108. [MonoTODO]
  109. public string XsdElementName
  110. {
  111. get { throw new NotImplementedException (); }
  112. }
  113. [MonoTODO]
  114. public string GenerateTypeName (System.CodeDom.Compiler.CodeDomProvider codeProvider)
  115. {
  116. throw new NotImplementedException ();
  117. }
  118. #endif
  119. #if NET_1_1
  120. public bool CheckSpecified
  121. {
  122. get { return _mapMember.IsOptionalValueType; }
  123. }
  124. #endif
  125. #endregion // Properties
  126. }
  127. }