| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- //
- // System.Xml.Serialization.SerializationCodeGeneratorConfiguration.cs:
- //
- // Author:
- // Lluis Sanchez Gual ([email protected])
- //
- // (C) 2002, 2003 Ximian, Inc. http://www.ximian.com
- //
- using System;
- using System.Collections;
- using System.Xml.Serialization;
- namespace System.Xml.Serialization
- {
- [XmlType ("configuration")]
- internal class SerializationCodeGeneratorConfiguration
- {
- [XmlElement ("serializer")]
- public SerializerInfo[] Serializers;
- }
-
- [XmlType ("serializer")]
- internal class SerializerInfo
- {
- [XmlAttribute ("class")]
- public string ClassName;
-
- [XmlAttribute ("assembly")]
- public string Assembly;
-
- [XmlElement ("reader")]
- public string ReaderClassName;
-
- [XmlElement ("writer")]
- public string WriterClassName;
-
- [XmlElement ("namespace")]
- public string Namespace;
-
- [XmlArray ("namespaceImports")]
- [XmlArrayItem ("namespaceImport")]
- public string [] NamespaceImports;
-
- [System.ComponentModel.DefaultValue (SerializationFormat.Literal)]
- public SerializationFormat SerializationFormat = SerializationFormat.Literal;
-
- [XmlElement ("outFileName")]
- public string OutFileName;
-
- [XmlArray ("readerHooks")]
- public Hook[] ReaderHooks;
-
- [XmlArray ("writerHooks")]
- public Hook[] WriterHooks;
-
- public ArrayList GetHooks (HookType hookType, HookDir dir, HookAction action, Type type, string member)
- {
- if (dir == HookDir.Read)
- return FindHook (ReaderHooks, hookType, action, type, member);
- else
- return FindHook (WriterHooks, hookType, action, type, member);
- }
-
- ArrayList FindHook (Hook[] hooks, HookType hookType, HookAction action, Type type, string member)
- {
- ArrayList foundHooks = new ArrayList ();
- if (hooks == null) return foundHooks;
-
- foreach (Hook hook in hooks)
- {
- if (action == HookAction.InsertBefore && (hook.InsertBefore == null || hook.InsertBefore == ""))
- continue;
- else if (action == HookAction.InsertAfter && (hook.InsertAfter == null || hook.InsertAfter == ""))
- continue;
- else if (action == HookAction.Replace && (hook.Replace == null || hook.Replace == ""))
- continue;
-
- if (hook.HookType != hookType)
- continue;
-
- if (hook.Select != null)
- {
- if (hook.Select.TypeName != null && hook.Select.TypeName != "")
- if (hook.Select.TypeName != type.FullName) continue;
-
- if (hook.Select.TypeMember != null && hook.Select.TypeMember != "")
- if (hook.Select.TypeMember != member) continue;
-
- if (hook.Select.TypeAttributes != null && hook.Select.TypeAttributes.Length > 0)
- {
- object[] ats = type.GetCustomAttributes (true);
- bool found = false;
- foreach (object at in ats)
- if (Array.IndexOf (hook.Select.TypeAttributes, at.GetType().FullName) != -1) { found = true; break; }
- if (!found) continue;
- }
- }
- foundHooks.Add (hook);
- }
- return foundHooks;
- }
- }
-
- [XmlType ("hook")]
- internal class Hook
- {
- [XmlAttribute ("type")]
- public HookType HookType;
-
- [XmlElement ("select")]
- public Select Select;
-
- [XmlElement ("insertBefore")]
- public string InsertBefore;
- [XmlElement ("insertAfter")]
- public string InsertAfter;
- [XmlElement ("replace")]
- public string Replace;
-
- public string GetCode (HookAction action)
- {
- if (action == HookAction.InsertBefore)
- return InsertBefore;
- else if (action == HookAction.InsertAfter)
- return InsertAfter;
- else
- return Replace;
- }
- }
-
- [XmlType ("select")]
- internal class Select
- {
- [XmlElement ("typeName")]
- public string TypeName;
-
- [XmlElement("typeAttribute")]
- public string[] TypeAttributes;
-
- [XmlElement ("typeMember")]
- public string TypeMember;
- }
-
- internal enum HookDir
- {
- Read,
- Write
- }
-
- internal enum HookAction
- {
- InsertBefore,
- InsertAfter,
- Replace
- }
-
- [XmlType ("hookType")]
- internal enum HookType
- {
- attributes,
- elements,
- unknownAttribute,
- unknownElement,
- member,
- type
- }
- }
|