2
0

SerializationCodeGeneratorConfiguration.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. //
  2. // System.Xml.Serialization.SerializationCodeGeneratorConfiguration.cs:
  3. //
  4. // Author:
  5. // Lluis Sanchez Gual ([email protected])
  6. //
  7. // (C) 2002, 2003 Ximian, Inc. http://www.ximian.com
  8. //
  9. using System;
  10. using System.Collections;
  11. using System.Xml.Serialization;
  12. namespace System.Xml.Serialization
  13. {
  14. [XmlType ("configuration")]
  15. internal class SerializationCodeGeneratorConfiguration
  16. {
  17. [XmlElement ("serializer")]
  18. public SerializerInfo[] Serializers;
  19. }
  20. [XmlType ("serializer")]
  21. internal class SerializerInfo
  22. {
  23. [XmlAttribute ("class")]
  24. public string ClassName;
  25. [XmlAttribute ("assembly")]
  26. public string Assembly;
  27. [XmlElement ("reader")]
  28. public string ReaderClassName;
  29. [XmlElement ("writer")]
  30. public string WriterClassName;
  31. [XmlElement ("namespace")]
  32. public string Namespace;
  33. [System.ComponentModel.DefaultValue (SerializationFormat.Literal)]
  34. public SerializationFormat SerializationFormat = SerializationFormat.Literal;
  35. [XmlElement ("outFileName")]
  36. public string OutFileName;
  37. [XmlArray ("readerHooks")]
  38. public Hook[] ReaderHooks;
  39. [XmlArray ("writerHooks")]
  40. public Hook[] WriterHooks;
  41. public ArrayList GetHooks (HookType hookType, HookDir dir, HookAction action, Type type, string member)
  42. {
  43. if (dir == HookDir.Read)
  44. return FindHook (ReaderHooks, hookType, action, type, member);
  45. else
  46. return FindHook (WriterHooks, hookType, action, type, member);
  47. }
  48. ArrayList FindHook (Hook[] hooks, HookType hookType, HookAction action, Type type, string member)
  49. {
  50. ArrayList foundHooks = new ArrayList ();
  51. if (hooks == null) return foundHooks;
  52. foreach (Hook hook in hooks)
  53. {
  54. if (action == HookAction.InsertBefore && (hook.InsertBefore == null || hook.InsertBefore == ""))
  55. continue;
  56. else if (action == HookAction.InsertAfter && (hook.InsertAfter == null || hook.InsertAfter == ""))
  57. continue;
  58. else if (action == HookAction.Replace && (hook.Replace == null || hook.Replace == ""))
  59. continue;
  60. if (hook.HookType != hookType)
  61. continue;
  62. if (hook.Select != null)
  63. {
  64. if (hook.Select.TypeName != null && hook.Select.TypeName != "")
  65. if (hook.Select.TypeName != type.FullName) continue;
  66. if (hook.Select.TypeMember != null && hook.Select.TypeMember != "")
  67. if (hook.Select.TypeMember != member) continue;
  68. if (hook.Select.TypeAttributes != null && hook.Select.TypeAttributes.Length > 0)
  69. {
  70. object[] ats = type.GetCustomAttributes (true);
  71. bool found = false;
  72. foreach (object at in ats)
  73. if (Array.IndexOf (hook.Select.TypeAttributes, at.GetType().FullName) != -1) { found = true; break; }
  74. if (!found) continue;
  75. }
  76. }
  77. foundHooks.Add (hook);
  78. }
  79. return foundHooks;
  80. }
  81. }
  82. [XmlType ("hook")]
  83. internal class Hook
  84. {
  85. [XmlAttribute ("type")]
  86. public HookType HookType;
  87. [XmlElement ("select")]
  88. public Select Select;
  89. [XmlElement ("insertBefore")]
  90. public string InsertBefore;
  91. [XmlElement ("insertAfter")]
  92. public string InsertAfter;
  93. [XmlElement ("replace")]
  94. public string Replace;
  95. public string GetCode (HookAction action)
  96. {
  97. if (action == HookAction.InsertBefore)
  98. return InsertBefore;
  99. else if (action == HookAction.InsertAfter)
  100. return InsertAfter;
  101. else
  102. return Replace;
  103. }
  104. }
  105. [XmlType ("select")]
  106. internal class Select
  107. {
  108. [XmlElement ("typeName")]
  109. public string TypeName;
  110. [XmlElement("typeAttribute")]
  111. public string[] TypeAttributes;
  112. [XmlElement ("typeMember")]
  113. public string TypeMember;
  114. }
  115. internal enum HookDir
  116. {
  117. Read,
  118. Write
  119. }
  120. internal enum HookAction
  121. {
  122. InsertBefore,
  123. InsertAfter,
  124. Replace
  125. }
  126. [XmlType ("hookType")]
  127. internal enum HookType
  128. {
  129. attributes,
  130. elements,
  131. unknownAttribute,
  132. unknownElement,
  133. member,
  134. type
  135. }
  136. }