XmlSerializer.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736
  1. //
  2. // XmlSerializer.cs:
  3. //
  4. // Author:
  5. // Lluis Sanchez Gual ([email protected])
  6. //
  7. // (C) 2002, 2003 Ximian, Inc. http://www.ximian.com
  8. //
  9. //
  10. // Permission is hereby granted, free of charge, to any person obtaining
  11. // a copy of this software and associated documentation files (the
  12. // "Software"), to deal in the Software without restriction, including
  13. // without limitation the rights to use, copy, modify, merge, publish,
  14. // distribute, sublicense, and/or sell copies of the Software, and to
  15. // permit persons to whom the Software is furnished to do so, subject to
  16. // the following conditions:
  17. //
  18. // The above copyright notice and this permission notice shall be
  19. // included in all copies or substantial portions of the Software.
  20. //
  21. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  22. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  23. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  24. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  25. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  26. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  27. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  28. //
  29. using System;
  30. using System.Threading;
  31. using System.Collections;
  32. using System.Globalization;
  33. using System.IO;
  34. using System.Reflection;
  35. using System.Xml;
  36. using System.Xml.Schema;
  37. using System.Text;
  38. using System.CodeDom;
  39. using System.CodeDom.Compiler;
  40. using Microsoft.CSharp;
  41. using System.Configuration;
  42. using System.Security.Policy;
  43. namespace System.Xml.Serialization
  44. {
  45. public class XmlSerializer
  46. {
  47. internal const string WsdlNamespace = "http://schemas.xmlsoap.org/wsdl/";
  48. internal const string EncodingNamespace = "http://schemas.xmlsoap.org/soap/encoding/";
  49. static int generationThreshold;
  50. static bool backgroundGeneration = true;
  51. static bool deleteTempFiles = true;
  52. bool customSerializer;
  53. XmlMapping typeMapping;
  54. SerializerData serializerData;
  55. Type writerType;
  56. Type readerType;
  57. static Hashtable serializerTypes = new Hashtable ();
  58. internal class SerializerData
  59. {
  60. public int UsageCount;
  61. public Type ReaderType;
  62. public MethodInfo ReaderMethod;
  63. public Type WriterType;
  64. public MethodInfo WriterMethod;
  65. public GenerationBatch Batch;
  66. public IXmlSerializerImplementation Implementation;
  67. public XmlSerializationReader CreateReader () {
  68. if (ReaderType != null)
  69. return (XmlSerializationReader) Activator.CreateInstance (ReaderType);
  70. else if (Implementation != null)
  71. return Implementation.Reader;
  72. else
  73. return null;
  74. }
  75. public XmlSerializationWriter CreateWriter () {
  76. if (WriterType != null)
  77. return (XmlSerializationWriter) Activator.CreateInstance (WriterType);
  78. else if (Implementation != null)
  79. return Implementation.Writer;
  80. else
  81. return null;
  82. }
  83. }
  84. internal class GenerationBatch
  85. {
  86. public bool Done;
  87. public XmlMapping[] Maps;
  88. public SerializerData[] Datas;
  89. }
  90. static XmlSerializer ()
  91. {
  92. string db = Environment.GetEnvironmentVariable ("MONO_XMLSERIALIZER_DEBUG");
  93. deleteTempFiles = (db == null || db == "no");
  94. IDictionary table = (IDictionary) ConfigurationSettings.GetConfig("system.diagnostics");
  95. if (table != null) {
  96. table = (IDictionary) table["switches"];
  97. if (table != null) {
  98. string val = (string) table ["XmlSerialization.Compilation"];
  99. if (val == "1") deleteTempFiles = false;
  100. }
  101. }
  102. string th = Environment.GetEnvironmentVariable ("MONO_XMLSERIALIZER_THS");
  103. if (th == null) {
  104. generationThreshold = 50;
  105. backgroundGeneration = true;
  106. }
  107. else if (th.ToLower(CultureInfo.InvariantCulture) == "no")
  108. generationThreshold = -1;
  109. else {
  110. generationThreshold = int.Parse (th, CultureInfo.InvariantCulture);
  111. backgroundGeneration = (generationThreshold != 0);
  112. if (generationThreshold < 1) generationThreshold = 1;
  113. }
  114. }
  115. #region Constructors
  116. protected XmlSerializer ()
  117. {
  118. customSerializer = true;
  119. }
  120. public XmlSerializer (Type type)
  121. : this (type, null, null, null, null)
  122. {
  123. }
  124. public XmlSerializer (XmlTypeMapping xmlTypeMapping)
  125. {
  126. typeMapping = xmlTypeMapping;
  127. }
  128. internal XmlSerializer (XmlMapping mapping, SerializerData data)
  129. {
  130. typeMapping = mapping;
  131. serializerData = data;
  132. }
  133. public XmlSerializer (Type type, string defaultNamespace)
  134. : this (type, null, null, null, defaultNamespace)
  135. {
  136. }
  137. public XmlSerializer (Type type, Type[] extraTypes)
  138. : this (type, null, extraTypes, null, null)
  139. {
  140. }
  141. public XmlSerializer (Type type, XmlAttributeOverrides overrides)
  142. : this (type, overrides, null, null, null)
  143. {
  144. }
  145. public XmlSerializer (Type type, XmlRootAttribute root)
  146. : this (type, null, null, root, null)
  147. {
  148. }
  149. public XmlSerializer (Type type,
  150. XmlAttributeOverrides overrides,
  151. Type [] extraTypes,
  152. XmlRootAttribute root,
  153. string defaultNamespace)
  154. {
  155. if (type == null)
  156. throw new ArgumentNullException ("type");
  157. XmlReflectionImporter importer = new XmlReflectionImporter (overrides, defaultNamespace);
  158. if (extraTypes != null)
  159. {
  160. foreach (Type intype in extraTypes)
  161. importer.IncludeType (intype);
  162. }
  163. typeMapping = importer.ImportTypeMapping (type, root, defaultNamespace);
  164. }
  165. internal XmlMapping Mapping
  166. {
  167. get { return typeMapping; }
  168. }
  169. #if NET_2_0
  170. [MonoTODO]
  171. public XmlSerializer (Type type,
  172. XmlAttributeOverrides overrides,
  173. Type [] extraTypes,
  174. XmlRootAttribute root,
  175. string defaultNamespace,
  176. string location,
  177. Evidence evidence)
  178. {
  179. }
  180. #endif
  181. #endregion // Constructors
  182. #region Events
  183. private XmlAttributeEventHandler onUnknownAttribute;
  184. private XmlElementEventHandler onUnknownElement;
  185. private XmlNodeEventHandler onUnknownNode;
  186. private UnreferencedObjectEventHandler onUnreferencedObject;
  187. public event XmlAttributeEventHandler UnknownAttribute
  188. {
  189. add { onUnknownAttribute += value; } remove { onUnknownAttribute -= value; }
  190. }
  191. public event XmlElementEventHandler UnknownElement
  192. {
  193. add { onUnknownElement += value; } remove { onUnknownElement -= value; }
  194. }
  195. public event XmlNodeEventHandler UnknownNode
  196. {
  197. add { onUnknownNode += value; } remove { onUnknownNode -= value; }
  198. }
  199. public event UnreferencedObjectEventHandler UnreferencedObject
  200. {
  201. add { onUnreferencedObject += value; } remove { onUnreferencedObject -= value; }
  202. }
  203. internal virtual void OnUnknownAttribute (XmlAttributeEventArgs e)
  204. {
  205. if (onUnknownAttribute != null) onUnknownAttribute(this, e);
  206. }
  207. internal virtual void OnUnknownElement (XmlElementEventArgs e)
  208. {
  209. if (onUnknownElement != null) onUnknownElement(this, e);
  210. }
  211. internal virtual void OnUnknownNode (XmlNodeEventArgs e)
  212. {
  213. if (onUnknownNode != null) onUnknownNode(this, e);
  214. }
  215. internal virtual void OnUnreferencedObject (UnreferencedObjectEventArgs e)
  216. {
  217. if (onUnreferencedObject != null) onUnreferencedObject(this, e);
  218. }
  219. #endregion // Events
  220. #region Methods
  221. public virtual bool CanDeserialize (XmlReader xmlReader)
  222. {
  223. xmlReader.MoveToContent ();
  224. if (typeMapping is XmlMembersMapping)
  225. return true;
  226. else
  227. return ((XmlTypeMapping)typeMapping).ElementName == xmlReader.LocalName;
  228. }
  229. protected virtual XmlSerializationReader CreateReader ()
  230. {
  231. // Must be implemented in derived class
  232. throw new NotImplementedException ();
  233. }
  234. protected virtual XmlSerializationWriter CreateWriter ()
  235. {
  236. // Must be implemented in derived class
  237. throw new NotImplementedException ();
  238. }
  239. public object Deserialize (Stream stream)
  240. {
  241. XmlTextReader xmlReader = new XmlTextReader(stream);
  242. xmlReader.Normalization = true;
  243. return Deserialize(xmlReader);
  244. }
  245. public object Deserialize (TextReader textReader)
  246. {
  247. XmlTextReader xmlReader = new XmlTextReader(textReader);
  248. xmlReader.Normalization = true;
  249. return Deserialize(xmlReader);
  250. }
  251. public object Deserialize (XmlReader xmlReader)
  252. {
  253. XmlSerializationReader xsReader;
  254. if (customSerializer)
  255. xsReader = CreateReader ();
  256. else
  257. xsReader = CreateReader (typeMapping);
  258. xsReader.Initialize (xmlReader, this);
  259. return Deserialize (xsReader);
  260. }
  261. protected virtual object Deserialize (XmlSerializationReader reader)
  262. {
  263. if (customSerializer)
  264. // Must be implemented in derived class
  265. throw new NotImplementedException ();
  266. if (reader is XmlSerializationReaderInterpreter)
  267. return ((XmlSerializationReaderInterpreter)reader).ReadRoot ();
  268. else
  269. return serializerData.ReaderMethod.Invoke (reader, null);
  270. }
  271. public static XmlSerializer [] FromMappings (XmlMapping [] mappings)
  272. {
  273. XmlSerializer[] sers = new XmlSerializer [mappings.Length];
  274. SerializerData[] datas = new SerializerData [mappings.Length];
  275. GenerationBatch batch = new GenerationBatch ();
  276. batch.Maps = mappings;
  277. batch.Datas = datas;
  278. for (int n=0; n<mappings.Length; n++)
  279. {
  280. if (mappings[n] != null)
  281. {
  282. SerializerData data = new SerializerData ();
  283. data.Batch = batch;
  284. sers[n] = new XmlSerializer (mappings[n], data);
  285. datas[n] = data;
  286. }
  287. }
  288. return sers;
  289. }
  290. public static XmlSerializer [] FromTypes (Type [] mappings)
  291. {
  292. XmlSerializer [] sers = new XmlSerializer [mappings.Length];
  293. for (int n=0; n<mappings.Length; n++)
  294. sers[n] = new XmlSerializer (mappings[n]);
  295. return sers;
  296. }
  297. protected virtual void Serialize (object o, XmlSerializationWriter writer)
  298. {
  299. if (customSerializer)
  300. // Must be implemented in derived class
  301. throw new NotImplementedException ();
  302. if (writer is XmlSerializationWriterInterpreter)
  303. ((XmlSerializationWriterInterpreter)writer).WriteRoot (o);
  304. else
  305. serializerData.WriterMethod.Invoke (writer, new object[] {o});
  306. }
  307. public void Serialize (Stream stream, object o)
  308. {
  309. XmlTextWriter xmlWriter = new XmlTextWriter (stream, System.Text.Encoding.Default);
  310. xmlWriter.Formatting = Formatting.Indented;
  311. Serialize (xmlWriter, o, null);
  312. }
  313. public void Serialize (TextWriter textWriter, object o)
  314. {
  315. XmlTextWriter xmlWriter = new XmlTextWriter (textWriter);
  316. xmlWriter.Formatting = Formatting.Indented;
  317. Serialize (xmlWriter, o, null);
  318. }
  319. public void Serialize (XmlWriter xmlWriter, object o)
  320. {
  321. Serialize (xmlWriter, o, null);
  322. }
  323. public void Serialize (Stream stream, object o, XmlSerializerNamespaces namespaces)
  324. {
  325. XmlTextWriter xmlWriter = new XmlTextWriter (stream, System.Text.Encoding.Default);
  326. xmlWriter.Formatting = Formatting.Indented;
  327. Serialize (xmlWriter, o, namespaces);
  328. }
  329. public void Serialize (TextWriter textWriter, object o, XmlSerializerNamespaces namespaces)
  330. {
  331. XmlTextWriter xmlWriter = new XmlTextWriter (textWriter);
  332. xmlWriter.Formatting = Formatting.Indented;
  333. Serialize (xmlWriter, o, namespaces);
  334. xmlWriter.Flush();
  335. }
  336. public void Serialize (XmlWriter writer, object o, XmlSerializerNamespaces namespaces)
  337. {
  338. XmlSerializationWriter xsWriter;
  339. if (customSerializer)
  340. xsWriter = CreateWriter ();
  341. else
  342. xsWriter = CreateWriter (typeMapping);
  343. if (namespaces == null || namespaces.Count == 0)
  344. {
  345. namespaces = new XmlSerializerNamespaces ();
  346. namespaces.Add ("xsd", XmlSchema.Namespace);
  347. namespaces.Add ("xsi", XmlSchema.InstanceNamespace);
  348. }
  349. xsWriter.Initialize (writer, namespaces);
  350. Serialize (o, xsWriter);
  351. writer.Flush ();
  352. }
  353. #if NET_2_0
  354. [MonoTODO]
  355. public object Deserialize (XmlReader xmlReader, string encodingStyle, XmlDeserializationEvents events)
  356. {
  357. throw new NotImplementedException ();
  358. }
  359. [MonoTODO]
  360. public object Deserialize (XmlReader xmlReader, string encodingStyle)
  361. {
  362. throw new NotImplementedException ();
  363. }
  364. [MonoTODO]
  365. public object Deserialize (XmlReader xmlReader, XmlDeserializationEvents events)
  366. {
  367. throw new NotImplementedException ();
  368. }
  369. [MonoTODO]
  370. public static XmlSerializer[] FromMappings (XmlMapping[] mappings, Evidence evidence)
  371. {
  372. throw new NotImplementedException ();
  373. }
  374. [MonoTODO]
  375. public static XmlSerializer[] FromMappings (XmlMapping[] mappings, Type type)
  376. {
  377. throw new NotImplementedException ();
  378. }
  379. public static Assembly GenerateSerializer (Type[] types, XmlMapping[] mappings)
  380. {
  381. return GenerateSerializer (types, mappings, null);
  382. }
  383. [MonoTODO]
  384. public static Assembly GenerateSerializer (Type[] types, XmlMapping[] mappings, CompilerParameters parameters)
  385. {
  386. GenerationBatch batch = new GenerationBatch ();
  387. batch.Maps = mappings;
  388. batch.Datas = new SerializerData [mappings.Length];
  389. for (int n=0; n<mappings.Length; n++) {
  390. SerializerData data = new SerializerData ();
  391. data.Batch = batch;
  392. batch.Datas [n] = data;
  393. }
  394. return GenerateSerializers (batch, parameters);
  395. }
  396. [MonoTODO]
  397. [Obsolete]
  398. public static Assembly GenerateSerializer (Type[] types,
  399. XmlMapping[] mappings,
  400. string codePath,
  401. bool debug,
  402. bool keepFiles)
  403. {
  404. throw new NotImplementedException ();
  405. }
  406. [MonoTODO]
  407. [Obsolete]
  408. public static Assembly GenerateSerializer (Type[] types,
  409. XmlMapping[] mappings,
  410. string codePath,
  411. bool debug,
  412. bool keepFiles,
  413. string compilerOptions)
  414. {
  415. throw new NotImplementedException ();
  416. }
  417. public static string GetXmlSerializerAssemblyName (Type type)
  418. {
  419. return type.Assembly.GetName().Name + ".XmlSerializers";
  420. }
  421. public static string GetXmlSerializerAssemblyName (Type type, string defaultNamespace)
  422. {
  423. return GetXmlSerializerAssemblyName (type) + "." + defaultNamespace.GetHashCode ();
  424. }
  425. [MonoTODO]
  426. public void Serialize (XmlWriter xmlWriter, object o, XmlSerializerNamespaces namespaces, string encodingStyle)
  427. {
  428. throw new NotImplementedException ();
  429. }
  430. #endif
  431. XmlSerializationWriter CreateWriter (XmlMapping typeMapping)
  432. {
  433. XmlSerializationWriter writer;
  434. lock (this) {
  435. if (serializerData != null) {
  436. writer = serializerData.CreateWriter ();
  437. if (writer != null) return writer;
  438. }
  439. }
  440. if (!typeMapping.Source.CanBeGenerated || generationThreshold == -1)
  441. return new XmlSerializationWriterInterpreter (typeMapping);
  442. CheckGeneratedTypes (typeMapping);
  443. lock (this) {
  444. writer = serializerData.CreateWriter ();
  445. if (writer != null) return writer;
  446. }
  447. return new XmlSerializationWriterInterpreter (typeMapping);
  448. }
  449. XmlSerializationReader CreateReader (XmlMapping typeMapping)
  450. {
  451. XmlSerializationReader reader;
  452. lock (this) {
  453. if (serializerData != null) {
  454. reader = serializerData.CreateReader ();
  455. if (reader != null) return reader;
  456. }
  457. }
  458. if (!typeMapping.Source.CanBeGenerated || generationThreshold == -1)
  459. return new XmlSerializationReaderInterpreter (typeMapping);
  460. CheckGeneratedTypes (typeMapping);
  461. lock (this) {
  462. reader = serializerData.CreateReader ();
  463. if (reader != null) return reader;
  464. }
  465. return new XmlSerializationReaderInterpreter (typeMapping);
  466. }
  467. void CheckGeneratedTypes (XmlMapping typeMapping)
  468. {
  469. lock (this)
  470. {
  471. if (serializerData == null)
  472. {
  473. lock (serializerTypes)
  474. {
  475. serializerData = (SerializerData) serializerTypes [typeMapping.Source];
  476. if (serializerData == null) {
  477. serializerData = new SerializerData();
  478. serializerTypes [typeMapping.Source] = serializerData;
  479. }
  480. }
  481. }
  482. }
  483. bool generate = false;
  484. lock (serializerData)
  485. {
  486. generate = (++serializerData.UsageCount == generationThreshold);
  487. }
  488. if (generate)
  489. {
  490. if (serializerData.Batch != null)
  491. GenerateSerializersAsync (serializerData.Batch);
  492. else
  493. {
  494. GenerationBatch batch = new GenerationBatch ();
  495. batch.Maps = new XmlMapping[] {typeMapping};
  496. batch.Datas = new SerializerData[] {serializerData};
  497. GenerateSerializersAsync (batch);
  498. }
  499. }
  500. }
  501. void GenerateSerializersAsync (GenerationBatch batch)
  502. {
  503. if (batch.Maps.Length != batch.Datas.Length)
  504. throw new ArgumentException ("batch");
  505. lock (batch)
  506. {
  507. if (batch.Done) return;
  508. batch.Done = true;
  509. }
  510. if (backgroundGeneration)
  511. ThreadPool.QueueUserWorkItem (new WaitCallback (RunSerializerGeneration), batch);
  512. else
  513. RunSerializerGeneration (batch);
  514. }
  515. void RunSerializerGeneration (object obj)
  516. {
  517. try
  518. {
  519. GenerationBatch batch = (GenerationBatch) obj;
  520. batch = LoadFromSatelliteAssembly (batch);
  521. if (batch != null)
  522. GenerateSerializers (batch, null);
  523. }
  524. catch (Exception ex)
  525. {
  526. Console.WriteLine (ex);
  527. }
  528. }
  529. static Assembly GenerateSerializers (GenerationBatch batch, CompilerParameters cp)
  530. {
  531. DateTime tim = DateTime.Now;
  532. XmlMapping[] maps = batch.Maps;
  533. if (cp == null) {
  534. cp = new CompilerParameters();
  535. cp.IncludeDebugInformation = false;
  536. cp.GenerateInMemory = true;
  537. cp.TempFiles.KeepFiles = !deleteTempFiles;
  538. }
  539. string file = cp.TempFiles.AddExtension ("cs");
  540. StreamWriter sw = new StreamWriter (file);
  541. if (!deleteTempFiles)
  542. Console.WriteLine ("Generating " + file);
  543. SerializationCodeGenerator gen = new SerializationCodeGenerator (maps);
  544. try
  545. {
  546. gen.GenerateSerializers (sw);
  547. }
  548. catch (Exception ex)
  549. {
  550. Console.WriteLine ("Serializer could not be generated");
  551. Console.WriteLine (ex);
  552. cp.TempFiles.Delete ();
  553. return null;
  554. }
  555. sw.Close ();
  556. CSharpCodeProvider provider = new CSharpCodeProvider();
  557. ICodeCompiler comp = provider.CreateCompiler ();
  558. cp.GenerateExecutable = false;
  559. foreach (Type rtype in gen.ReferencedTypes)
  560. {
  561. if (!cp.ReferencedAssemblies.Contains (rtype.Assembly.Location))
  562. cp.ReferencedAssemblies.Add (rtype.Assembly.Location);
  563. }
  564. if (!cp.ReferencedAssemblies.Contains ("System.dll"))
  565. cp.ReferencedAssemblies.Add ("System.dll");
  566. if (!cp.ReferencedAssemblies.Contains ("System.Xml"))
  567. cp.ReferencedAssemblies.Add ("System.Xml");
  568. if (!cp.ReferencedAssemblies.Contains ("System.Data"))
  569. cp.ReferencedAssemblies.Add ("System.Data");
  570. CompilerResults res = comp.CompileAssemblyFromFile (cp, file);
  571. if (res.Errors.Count > 0)
  572. {
  573. Console.WriteLine ("Error while compiling generated serializer");
  574. foreach (CompilerError error in res.Errors)
  575. Console.WriteLine (error);
  576. cp.TempFiles.Delete ();
  577. return null;
  578. }
  579. GenerationResult[] results = gen.GenerationResults;
  580. for (int n=0; n<results.Length; n++)
  581. {
  582. GenerationResult gres = results[n];
  583. SerializerData sd = batch.Datas [n];
  584. lock (sd)
  585. {
  586. sd.WriterType = res.CompiledAssembly.GetType (gres.Namespace + "." + gres.WriterClassName);
  587. sd.ReaderType = res.CompiledAssembly.GetType (gres.Namespace + "." + gres.ReaderClassName);
  588. sd.WriterMethod = sd.WriterType.GetMethod (gres.WriteMethodName);
  589. sd.ReaderMethod = sd.ReaderType.GetMethod (gres.ReadMethodName);
  590. sd.Batch = null;
  591. }
  592. }
  593. cp.TempFiles.Delete ();
  594. if (!deleteTempFiles)
  595. Console.WriteLine ("Generation finished - " + (DateTime.Now - tim).TotalMilliseconds + " ms");
  596. return res.CompiledAssembly;
  597. }
  598. #if NET_2_0
  599. GenerationBatch LoadFromSatelliteAssembly (GenerationBatch batch)
  600. {
  601. return batch;
  602. }
  603. #else
  604. GenerationBatch LoadFromSatelliteAssembly (GenerationBatch batch)
  605. {
  606. return batch;
  607. }
  608. #endif
  609. #endregion // Methods
  610. }
  611. }