XmlSerializer.cs 19 KB

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