2 // System.Xml.Serialization.SerializationCodeGeneratorConfiguration.cs:
5 // Lluis Sanchez Gual (lluis@ximian.com)
7 // (C) 2002, 2003 Ximian, Inc. http://www.ximian.com
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:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
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.
32 using System.Collections;
33 using System.Xml.Serialization;
35 namespace System.Xml.Serialization
37 [XmlType ("configuration")]
38 internal class SerializationCodeGeneratorConfiguration
40 [XmlElement ("serializer")]
41 public SerializerInfo[] Serializers;
44 [XmlType ("serializer")]
45 internal class SerializerInfo
47 [XmlAttribute ("class")]
48 public string ClassName;
50 [XmlAttribute ("assembly")]
51 public string Assembly;
53 [XmlElement ("reader")]
54 public string ReaderClassName;
56 [XmlElement ("writer")]
57 public string WriterClassName;
59 [XmlElement ("noreader")]
62 [XmlElement ("nowriter")]
65 [XmlElement ("generateAsInternal")]
66 public bool GenerateAsInternal;
68 [XmlElement ("namespace")]
69 public string Namespace;
71 [XmlArray ("namespaceImports")]
72 [XmlArrayItem ("namespaceImport")]
73 public string [] NamespaceImports;
75 [System.ComponentModel.DefaultValue (SerializationFormat.Literal)]
76 public SerializationFormat SerializationFormat = SerializationFormat.Literal;
78 [XmlElement ("outFileName")]
79 public string OutFileName;
81 [XmlArray ("readerHooks")]
82 public Hook[] ReaderHooks;
84 [XmlArray ("writerHooks")]
85 public Hook[] WriterHooks;
87 public ArrayList GetHooks (HookType hookType, HookDir dir, HookAction action, Type type, string member)
89 if (dir == HookDir.Read)
90 return FindHook (ReaderHooks, hookType, action, type, member);
92 return FindHook (WriterHooks, hookType, action, type, member);
95 ArrayList FindHook (Hook[] hooks, HookType hookType, HookAction action, Type type, string member)
97 ArrayList foundHooks = new ArrayList ();
98 if (hooks == null) return foundHooks;
100 foreach (Hook hook in hooks)
102 if (action == HookAction.InsertBefore && (hook.InsertBefore == null || hook.InsertBefore == ""))
104 else if (action == HookAction.InsertAfter && (hook.InsertAfter == null || hook.InsertAfter == ""))
106 else if (action == HookAction.Replace && (hook.Replace == null || hook.Replace == ""))
109 if (hook.HookType != hookType)
112 if (hook.Select != null)
114 if (hook.Select.TypeName != null && hook.Select.TypeName != "")
115 if (hook.Select.TypeName != type.FullName) continue;
117 if (hook.Select.TypeMember != null && hook.Select.TypeMember != "")
118 if (hook.Select.TypeMember != member) continue;
120 if (hook.Select.TypeAttributes != null && hook.Select.TypeAttributes.Length > 0)
122 object[] ats = type.GetCustomAttributes (true);
124 foreach (object at in ats)
125 if (Array.IndexOf (hook.Select.TypeAttributes, at.GetType().FullName) != -1) { found = true; break; }
126 if (!found) continue;
129 foundHooks.Add (hook);
138 [XmlAttribute ("type")]
139 public HookType HookType;
141 [XmlElement ("select")]
142 public Select Select;
144 [XmlElement ("insertBefore")]
145 public string InsertBefore;
147 [XmlElement ("insertAfter")]
148 public string InsertAfter;
150 [XmlElement ("replace")]
151 public string Replace;
153 public string GetCode (HookAction action)
155 if (action == HookAction.InsertBefore)
157 else if (action == HookAction.InsertAfter)
165 internal class Select
167 [XmlElement ("typeName")]
168 public string TypeName;
170 [XmlElement("typeAttribute")]
171 public string[] TypeAttributes;
173 [XmlElement ("typeMember")]
174 public string TypeMember;
177 internal enum HookDir
183 internal enum HookAction
190 [XmlType ("hookType")]
191 internal enum HookType