SerializationCodeGeneratorConfiguration.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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. [XmlArray ("namespaceImports")]
  34. [XmlArrayItem ("namespaceImport")]
  35. public string [] NamespaceImports;
  36. [System.ComponentModel.DefaultValue (SerializationFormat.Literal)]
  37. public SerializationFormat SerializationFormat = SerializationFormat.Literal;
  38. [XmlElement ("outFileName")]
  39. public string OutFileName;
  40. [XmlArray ("readerHooks")]
  41. public Hook[] ReaderHooks;
  42. [XmlArray ("writerHooks")]
  43. public Hook[] WriterHooks;
  44. public ArrayList GetHooks (HookType hookType, HookDir dir, HookAction action, Type type, string member)
  45. {
  46. if (dir == HookDir.Read)
  47. return FindHook (ReaderHooks, hookType, action, type, member);
  48. else
  49. return FindHook (WriterHooks, hookType, action, type, member);
  50. }
  51. ArrayList FindHook (Hook[] hooks, HookType hookType, HookAction action, Type type, string member)
  52. {
  53. ArrayList foundHooks = new ArrayList ();
  54. if (hooks == null) return foundHooks;
  55. foreach (Hook hook in hooks)
  56. {
  57. if (action == HookAction.InsertBefore && (hook.InsertBefore == null || hook.InsertBefore == ""))
  58. continue;
  59. else if (action == HookAction.InsertAfter && (hook.InsertAfter == null || hook.InsertAfter == ""))
  60. continue;
  61. else if (action == HookAction.Replace && (hook.Replace == null || hook.Replace == ""))
  62. continue;
  63. if (hook.HookType != hookType)
  64. continue;
  65. if (hook.Select != null)
  66. {
  67. if (hook.Select.TypeName != null && hook.Select.TypeName != "")
  68. if (hook.Select.TypeName != type.FullName) continue;
  69. if (hook.Select.TypeMember != null && hook.Select.TypeMember != "")
  70. if (hook.Select.TypeMember != member) continue;
  71. if (hook.Select.TypeAttributes != null && hook.Select.TypeAttributes.Length > 0)
  72. {
  73. object[] ats = type.GetCustomAttributes (true);
  74. bool found = false;
  75. foreach (object at in ats)
  76. if (Array.IndexOf (hook.Select.TypeAttributes, at.GetType().FullName) != -1) { found = true; break; }
  77. if (!found) continue;
  78. }
  79. }
  80. foundHooks.Add (hook);
  81. }
  82. return foundHooks;
  83. }
  84. }
  85. [XmlType ("hook")]
  86. internal class Hook
  87. {
  88. [XmlAttribute ("type")]
  89. public HookType HookType;
  90. [XmlElement ("select")]
  91. public Select Select;
  92. [XmlElement ("insertBefore")]
  93. public string InsertBefore;
  94. [XmlElement ("insertAfter")]
  95. public string InsertAfter;
  96. [XmlElement ("replace")]
  97. public string Replace;
  98. public string GetCode (HookAction action)
  99. {
  100. if (action == HookAction.InsertBefore)
  101. return InsertBefore;
  102. else if (action == HookAction.InsertAfter)
  103. return InsertAfter;
  104. else
  105. return Replace;
  106. }
  107. }
  108. [XmlType ("select")]
  109. internal class Select
  110. {
  111. [XmlElement ("typeName")]
  112. public string TypeName;
  113. [XmlElement("typeAttribute")]
  114. public string[] TypeAttributes;
  115. [XmlElement ("typeMember")]
  116. public string TypeMember;
  117. }
  118. internal enum HookDir
  119. {
  120. Read,
  121. Write
  122. }
  123. internal enum HookAction
  124. {
  125. InsertBefore,
  126. InsertAfter,
  127. Replace
  128. }
  129. [XmlType ("hookType")]
  130. internal enum HookType
  131. {
  132. attributes,
  133. elements,
  134. unknownAttribute,
  135. unknownElement,
  136. member,
  137. type
  138. }
  139. }