svn path=/branches/mono-1-1-9/mcs/; revision=51207
[mono.git] / mcs / class / System.XML / System.Xml.Serialization / XmlSerializer.cs
1 //
2 // XmlSerializer.cs: 
3 //
4 // Author:
5 //   Lluis Sanchez Gual (lluis@ximian.com)
6 //
7 // (C) 2002, 2003 Ximian, Inc.  http://www.ximian.com
8 //
9
10 //
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:
18 // 
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 // 
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.
29 //
30
31 using System;
32 using System.Threading;
33 using System.Collections;
34 using System.Globalization;
35 using System.IO;
36 using System.Reflection;
37 using System.Xml;
38 using System.Xml.Schema;
39 using System.Text;
40 #if !TARGET_JVM
41 using System.CodeDom;
42 using System.CodeDom.Compiler;
43 using Microsoft.CSharp;
44 #endif
45 using System.Configuration;
46 using System.Security.Policy;
47
48 namespace System.Xml.Serialization
49 {
50
51         public class XmlSerializer
52         {
53                 internal const string WsdlNamespace = "http://schemas.xmlsoap.org/wsdl/";
54                 internal const string EncodingNamespace = "http://schemas.xmlsoap.org/soap/encoding/";
55                 static int generationThreshold;
56                 static bool backgroundGeneration = true;
57                 static bool deleteTempFiles = true;
58
59                 bool customSerializer;
60                 XmlMapping typeMapping;
61                 
62                 SerializerData serializerData;
63                 
64                 static Hashtable serializerTypes = new Hashtable ();
65                 
66                 internal class SerializerData
67                 {
68                         public int UsageCount;
69                         public Type ReaderType;
70                         public MethodInfo ReaderMethod;
71                         public Type WriterType;
72                         public MethodInfo WriterMethod;
73                         public GenerationBatch Batch;
74                         public IXmlSerializerImplementation Implementation = null;
75                         
76                         public XmlSerializationReader CreateReader () {
77                                 if (ReaderType != null)
78                                         return (XmlSerializationReader) Activator.CreateInstance (ReaderType);
79                                 else if (Implementation != null)
80                                         return Implementation.Reader;
81                                 else
82                                         return null;
83                         }
84                         
85                         public XmlSerializationWriter CreateWriter () {
86                                 if (WriterType != null)
87                                         return (XmlSerializationWriter) Activator.CreateInstance (WriterType);
88                                 else if (Implementation != null)
89                                         return Implementation.Writer;
90                                 else
91                                         return null;
92                         }
93                 }
94                 
95                 internal class GenerationBatch
96                 {
97                         public bool Done;
98                         public XmlMapping[] Maps;
99                         public SerializerData[] Datas;
100                 }
101                 
102                 static XmlSerializer ()
103                 {
104                         
105 #if TARGET_JVM
106                         string db = null;
107                         string th = null;
108                         generationThreshold = -1;
109                         backgroundGeneration = false;
110 #else
111                         string db = Environment.GetEnvironmentVariable ("MONO_XMLSERIALIZER_DEBUG");
112                         string th = Environment.GetEnvironmentVariable ("MONO_XMLSERIALIZER_THS");
113                         
114                         if (th == null) {
115                                 generationThreshold = 50;
116                                 backgroundGeneration = true;
117                         }
118                         else if (th.ToLower(CultureInfo.InvariantCulture) == "no") 
119                                 generationThreshold = -1;
120                         else {
121                                 generationThreshold = int.Parse (th, CultureInfo.InvariantCulture);
122                                 backgroundGeneration = (generationThreshold != 0);
123                                 if (generationThreshold < 1) generationThreshold = 1;
124                         }
125 #endif
126                         deleteTempFiles = (db == null || db == "no");
127                         
128                         IDictionary table = (IDictionary) ConfigurationSettings.GetConfig("system.diagnostics");
129                         if (table != null) 
130                         {
131                                 table = (IDictionary) table["switches"];
132                                 if (table != null) 
133                                 {
134                                         string val = (string) table ["XmlSerialization.Compilation"];
135                                         if (val == "1") deleteTempFiles = false;
136                                 }
137                         }
138                 }
139
140 #region Constructors
141
142                 protected XmlSerializer ()
143                 {
144                         customSerializer = true;
145                 }
146
147                 public XmlSerializer (Type type)
148                         : this (type, null, null, null, null)
149                 {
150                 }
151
152                 public XmlSerializer (XmlTypeMapping xmlTypeMapping)
153                 {
154                         typeMapping = xmlTypeMapping;
155                 }
156
157                 internal XmlSerializer (XmlMapping mapping, SerializerData data)
158                 {
159                         typeMapping = mapping;
160                         serializerData = data;
161                 }
162
163                 public XmlSerializer (Type type, string defaultNamespace)
164                         : this (type, null, null, null, defaultNamespace)
165                 {
166                 }
167
168                 public XmlSerializer (Type type, Type[] extraTypes)
169                         : this (type, null, extraTypes, null, null)
170                 {
171                 }
172
173                 public XmlSerializer (Type type, XmlAttributeOverrides overrides)
174                         : this (type, overrides, null, null, null)
175                 {
176                 }
177
178                 public XmlSerializer (Type type, XmlRootAttribute root)
179                         : this (type, null, null, root, null)
180                 {
181                 }
182
183                 public XmlSerializer (Type type,
184                         XmlAttributeOverrides overrides,
185                         Type [] extraTypes,
186                         XmlRootAttribute root,
187                         string defaultNamespace)
188                 {
189                         if (type == null)
190                                 throw new ArgumentNullException ("type");
191
192                         XmlReflectionImporter importer = new XmlReflectionImporter (overrides, defaultNamespace);
193
194                         if (extraTypes != null) 
195                         {
196                                 foreach (Type intype in extraTypes)
197                                         importer.IncludeType (intype);
198                         }
199
200                         typeMapping = importer.ImportTypeMapping (type, root, defaultNamespace);
201                 }
202                 
203                 internal XmlMapping Mapping
204                 {
205                         get { return typeMapping; }
206                 }
207
208 #if NET_2_0
209
210                 [MonoTODO]
211                 public XmlSerializer (Type type,
212                         XmlAttributeOverrides overrides,
213                         Type [] extraTypes,
214                         XmlRootAttribute root,
215                         string defaultNamespace,
216                         string location,
217                         Evidence evidence)
218                 {
219                 }
220 #endif
221
222 #endregion // Constructors
223
224 #region Events
225
226                 private XmlAttributeEventHandler onUnknownAttribute;
227                 private XmlElementEventHandler onUnknownElement;
228                 private XmlNodeEventHandler onUnknownNode;
229                 private UnreferencedObjectEventHandler onUnreferencedObject;
230
231                 public event XmlAttributeEventHandler UnknownAttribute 
232                 {
233                         add { onUnknownAttribute += value; } remove { onUnknownAttribute -= value; }
234                 }
235
236                 public event XmlElementEventHandler UnknownElement 
237                 {
238                         add { onUnknownElement += value; } remove { onUnknownElement -= value; }
239                 }
240
241                 public event XmlNodeEventHandler UnknownNode 
242                 {
243                         add { onUnknownNode += value; } remove { onUnknownNode -= value; }
244                 }
245
246                 public event UnreferencedObjectEventHandler UnreferencedObject 
247                 {
248                         add { onUnreferencedObject += value; } remove { onUnreferencedObject -= value; }
249                 }
250
251
252                 internal virtual void OnUnknownAttribute (XmlAttributeEventArgs e) 
253                 {
254                         if (onUnknownAttribute != null) onUnknownAttribute(this, e);
255                 }
256
257                 internal virtual void OnUnknownElement (XmlElementEventArgs e) 
258                 {
259                         if (onUnknownElement != null) onUnknownElement(this, e);
260                 }
261
262                 internal virtual void OnUnknownNode (XmlNodeEventArgs e) 
263                 {
264                         if (onUnknownNode != null) onUnknownNode(this, e);
265                 }
266
267                 internal virtual void OnUnreferencedObject (UnreferencedObjectEventArgs e) 
268                 {
269                         if (onUnreferencedObject != null) onUnreferencedObject(this, e);
270                 }
271
272
273 #endregion // Events
274
275 #region Methods
276
277                 public virtual bool CanDeserialize (XmlReader xmlReader)
278                 {
279                         xmlReader.MoveToContent ();
280                         if (typeMapping is XmlMembersMapping) 
281                                 return true;
282                         else
283                                 return ((XmlTypeMapping)typeMapping).ElementName == xmlReader.LocalName;
284                 }
285
286                 protected virtual XmlSerializationReader CreateReader ()
287                 {
288                         // Must be implemented in derived class
289                         throw new NotImplementedException ();
290                 }
291
292                 protected virtual XmlSerializationWriter CreateWriter ()
293                 {
294                         // Must be implemented in derived class
295                         throw new NotImplementedException ();
296                 }
297
298                 public object Deserialize (Stream stream)
299                 {
300                         XmlTextReader xmlReader = new XmlTextReader(stream);
301                         xmlReader.Normalization = true;
302                         return Deserialize(xmlReader);
303                 }
304
305                 public object Deserialize (TextReader textReader)
306                 {
307                         XmlTextReader xmlReader = new XmlTextReader(textReader);
308                         xmlReader.Normalization = true;
309                         return Deserialize(xmlReader);
310                 }
311
312                 public object Deserialize (XmlReader xmlReader)
313                 {
314                         XmlSerializationReader xsReader;
315                         if (customSerializer)
316                                 xsReader = CreateReader ();
317                         else
318                                 xsReader = CreateReader (typeMapping);
319                                 
320                         xsReader.Initialize (xmlReader, this);
321                         return Deserialize (xsReader);
322                 }
323
324                 protected virtual object Deserialize (XmlSerializationReader reader)
325                 {
326                         if (customSerializer)
327                                 // Must be implemented in derived class
328                                 throw new NotImplementedException ();
329                         
330                         if (reader is XmlSerializationReaderInterpreter)
331                                 return ((XmlSerializationReaderInterpreter)reader).ReadRoot ();
332                         else
333                                 return serializerData.ReaderMethod.Invoke (reader, null);
334                 }
335
336                 public static XmlSerializer [] FromMappings (XmlMapping [] mappings)
337                 {
338                         XmlSerializer[] sers = new XmlSerializer [mappings.Length];
339                         SerializerData[] datas = new SerializerData [mappings.Length];
340                         GenerationBatch batch = new GenerationBatch ();
341                         batch.Maps = mappings;
342                         batch.Datas = datas;
343                         
344                         for (int n=0; n<mappings.Length; n++)
345                         {
346                                 if (mappings[n] != null)
347                                 {
348                                         SerializerData data = new SerializerData ();
349                                         data.Batch = batch;
350                                         sers[n] = new XmlSerializer (mappings[n], data);
351                                         datas[n] = data;
352                                 }
353                         }
354                         
355                         return sers;
356                 }
357
358                 public static XmlSerializer [] FromTypes (Type [] mappings)
359                 {
360                         XmlSerializer [] sers = new XmlSerializer [mappings.Length];
361                         for (int n=0; n<mappings.Length; n++)
362                                 sers[n] = new XmlSerializer (mappings[n]);
363                         return sers;
364                 }
365
366                 protected virtual void Serialize (object o, XmlSerializationWriter writer)
367                 {
368                         if (customSerializer)
369                                 // Must be implemented in derived class
370                                 throw new NotImplementedException ();
371                                 
372                         if (writer is XmlSerializationWriterInterpreter)
373                                 ((XmlSerializationWriterInterpreter)writer).WriteRoot (o);
374                         else
375                                 serializerData.WriterMethod.Invoke (writer, new object[] {o});
376                 }
377
378                 public void Serialize (Stream stream, object o)
379                 {
380                         XmlTextWriter xmlWriter = new XmlTextWriter (stream, System.Text.Encoding.Default);
381                         xmlWriter.Formatting = Formatting.Indented;
382                         Serialize (xmlWriter, o, null);
383                 }
384
385                 public void Serialize (TextWriter textWriter, object o)
386                 {
387                         XmlTextWriter xmlWriter = new XmlTextWriter (textWriter);
388                         xmlWriter.Formatting = Formatting.Indented;
389                         Serialize (xmlWriter, o, null);
390                 }
391
392                 public void Serialize (XmlWriter xmlWriter, object o)
393                 {
394                         Serialize (xmlWriter, o, null);
395                 }
396
397                 public void Serialize (Stream stream, object o, XmlSerializerNamespaces namespaces)
398                 {
399                         XmlTextWriter xmlWriter = new XmlTextWriter (stream, System.Text.Encoding.Default);
400                         xmlWriter.Formatting = Formatting.Indented;
401                         Serialize (xmlWriter, o, namespaces);
402                 }
403
404                 public void Serialize (TextWriter textWriter, object o, XmlSerializerNamespaces namespaces)
405                 {
406                         XmlTextWriter xmlWriter = new XmlTextWriter (textWriter);
407                         xmlWriter.Formatting = Formatting.Indented;
408                         Serialize (xmlWriter, o, namespaces);
409                         xmlWriter.Flush();
410                 }
411
412                 public void Serialize (XmlWriter writer, object o, XmlSerializerNamespaces namespaces)
413                 {
414                         XmlSerializationWriter xsWriter;
415                         
416                         if (customSerializer)
417                                 xsWriter = CreateWriter ();
418                         else
419                                 xsWriter = CreateWriter (typeMapping);
420                                 
421                         if (namespaces == null || namespaces.Count == 0)
422                         {
423                                 namespaces = new XmlSerializerNamespaces ();
424                                 namespaces.Add ("xsd", XmlSchema.Namespace);
425                                 namespaces.Add ("xsi", XmlSchema.InstanceNamespace);
426                         }
427                         
428                         xsWriter.Initialize (writer, namespaces);
429                         Serialize (o, xsWriter);
430                         writer.Flush ();
431                 }
432                 
433 #if NET_2_0
434                 
435                 [MonoTODO]
436                 public object Deserialize (XmlReader xmlReader, string encodingStyle, XmlDeserializationEvents events)
437                 {
438                         throw new NotImplementedException ();
439                 }
440
441                 [MonoTODO]
442                 public object Deserialize (XmlReader xmlReader, string encodingStyle)
443                 {
444                         throw new NotImplementedException ();
445                 }
446
447                 [MonoTODO]
448                 public object Deserialize (XmlReader xmlReader, XmlDeserializationEvents events)
449                 {
450                         throw new NotImplementedException ();
451                 }
452                 
453                 [MonoTODO]
454                 public static XmlSerializer[] FromMappings (XmlMapping[] mappings, Evidence evidence)
455                 {
456                         throw new NotImplementedException ();
457                 }
458
459                 [MonoTODO]
460                 public static XmlSerializer[] FromMappings (XmlMapping[] mappings, Type type)
461                 {
462                         throw new NotImplementedException ();
463                 }
464
465                 public static Assembly GenerateSerializer (Type[] types, XmlMapping[] mappings)
466                 {
467                         return GenerateSerializer (types, mappings, null);
468                 }
469                 
470                 [MonoTODO]
471                 public static Assembly GenerateSerializer (Type[] types, XmlMapping[] mappings, CompilerParameters parameters)
472                 {
473                         GenerationBatch batch = new GenerationBatch ();
474                         batch.Maps = mappings;
475                         batch.Datas = new SerializerData [mappings.Length];
476                         
477                         for (int n=0; n<mappings.Length; n++) {
478                                 SerializerData data = new SerializerData ();
479                                 data.Batch = batch;
480                                 batch.Datas [n] = data;
481                         }
482                         
483                         return GenerateSerializers (batch, parameters);
484                 }
485                 
486                 [MonoTODO]
487                 [Obsolete]
488                 public static Assembly GenerateSerializer (Type[] types, 
489                         XmlMapping[] mappings, 
490                         string codePath, 
491                         bool debug, 
492                         bool keepFiles)
493                 {
494                         throw new NotImplementedException ();
495                 }
496                 
497                 [MonoTODO]
498                 [Obsolete]
499                 public static Assembly GenerateSerializer (Type[] types, 
500                         XmlMapping[] mappings, 
501                         string codePath, 
502                         bool debug, 
503                         bool keepFiles, 
504                         string compilerOptions)
505                 {
506                         throw new NotImplementedException ();
507                 }
508
509                 public static string GetXmlSerializerAssemblyName (Type type)
510                 {
511                         return type.Assembly.GetName().Name + ".XmlSerializers";
512                 }
513
514                 public static string GetXmlSerializerAssemblyName (Type type, string defaultNamespace)
515                 {
516                         return GetXmlSerializerAssemblyName (type) + "." + defaultNamespace.GetHashCode ();
517                 }
518                 
519                 [MonoTODO]
520                 public void Serialize (XmlWriter xmlWriter, object o, XmlSerializerNamespaces namespaces, string encodingStyle)
521                 {
522                         throw new NotImplementedException ();
523                 }
524
525 #endif
526                 
527                 XmlSerializationWriter CreateWriter (XmlMapping typeMapping)
528                 {
529                         XmlSerializationWriter writer;
530                         
531                         lock (this) {
532                                 if (serializerData != null) {
533                                         lock (serializerData) {
534                                                 writer = serializerData.CreateWriter ();
535                                         }
536                                         if (writer != null) return writer;
537                                 }
538                         }
539                         
540                         if (!typeMapping.Source.CanBeGenerated || generationThreshold == -1)
541                                 return new XmlSerializationWriterInterpreter (typeMapping);
542
543                         CheckGeneratedTypes (typeMapping);
544                         
545                         lock (this) {
546                                 lock (serializerData) {
547                                         writer = serializerData.CreateWriter ();
548                                 }
549                                 if (writer != null) return writer;
550                         }
551                         
552                         return new XmlSerializationWriterInterpreter (typeMapping);
553                 }
554                 
555                 XmlSerializationReader CreateReader (XmlMapping typeMapping)
556                 {
557                         XmlSerializationReader reader;
558                         
559                         lock (this) {
560                                 if (serializerData != null) {
561                                         lock (serializerData) {
562                                                 reader = serializerData.CreateReader ();
563                                         }
564                                         if (reader != null) return reader;
565                                 }
566                         }
567                         
568                         if (!typeMapping.Source.CanBeGenerated || generationThreshold == -1)
569                                 return new XmlSerializationReaderInterpreter (typeMapping);
570
571                         CheckGeneratedTypes (typeMapping);
572                         
573                         lock (this) {
574                                 lock (serializerData) {
575                                         reader = serializerData.CreateReader ();
576                                 }
577                                 if (reader != null) return reader;
578                         }
579                         
580                         return new XmlSerializationReaderInterpreter (typeMapping);
581                 }
582                 
583 #if TARGET_JVM
584                 void CheckGeneratedTypes (XmlMapping typeMapping)
585                 {
586                         throw new NotImplementedException();
587                 }
588                 void GenerateSerializersAsync (GenerationBatch batch)
589                 {
590                         throw new NotImplementedException();
591                 }
592                 void RunSerializerGeneration (object obj)
593                 {
594                         throw new NotImplementedException();
595                 }
596 #else
597                 void CheckGeneratedTypes (XmlMapping typeMapping)
598                 {
599                         lock (this)
600                         {
601                                 if (serializerData == null) 
602                                 {
603                                         lock (serializerTypes)
604                                         {
605                                                 serializerData = (SerializerData) serializerTypes [typeMapping.Source];
606                                                 if (serializerData == null) {
607                                                         serializerData = new SerializerData();
608                                                         serializerTypes [typeMapping.Source] = serializerData;
609                                                 }
610                                         }
611                                 }
612                         }
613                         
614                         bool generate = false;
615                         lock (serializerData)
616                         {
617                                 generate = (++serializerData.UsageCount == generationThreshold);
618                         }
619                         
620                         if (generate)
621                         {
622                                 if (serializerData.Batch != null)
623                                         GenerateSerializersAsync (serializerData.Batch);
624                                 else
625                                 {
626                                         GenerationBatch batch = new GenerationBatch ();
627                                         batch.Maps = new XmlMapping[] {typeMapping};
628                                         batch.Datas = new SerializerData[] {serializerData};
629                                         GenerateSerializersAsync (batch);
630                                 }
631                         }
632                 }
633                 
634                 void GenerateSerializersAsync (GenerationBatch batch)
635                 {
636                         if (batch.Maps.Length != batch.Datas.Length)
637                                 throw new ArgumentException ("batch");
638
639                         lock (batch)
640                         {
641                                 if (batch.Done) return;
642                                 batch.Done = true;
643                         }
644                         
645                         if (backgroundGeneration)
646                                 ThreadPool.QueueUserWorkItem (new WaitCallback (RunSerializerGeneration), batch);
647                         else
648                                 RunSerializerGeneration (batch);
649                 }
650                 
651                 void RunSerializerGeneration (object obj)
652                 {
653                         try
654                         {
655                                 GenerationBatch batch = (GenerationBatch) obj;
656                                 batch = LoadFromSatelliteAssembly (batch);
657                                 
658                                 if (batch != null)
659                                         GenerateSerializers (batch, null);
660                         }
661                         catch (Exception ex)
662                         {
663                                 Console.WriteLine (ex);
664                         }
665                 }
666                 
667                 static Assembly GenerateSerializers (GenerationBatch batch, CompilerParameters cp)
668                 {
669                         DateTime tim = DateTime.Now;
670                         
671                         XmlMapping[] maps = batch.Maps;
672                         
673                         if (cp == null) {
674                                 cp = new CompilerParameters();
675                                 cp.IncludeDebugInformation = false;
676                                 cp.GenerateInMemory = true;
677                                 cp.TempFiles.KeepFiles = !deleteTempFiles;
678                         }
679                         
680                         string file = cp.TempFiles.AddExtension ("cs");
681                         StreamWriter sw = new StreamWriter (file);
682                         
683                         if (!deleteTempFiles)
684                                 Console.WriteLine ("Generating " + file);
685                         
686                         SerializationCodeGenerator gen = new SerializationCodeGenerator (maps);
687                         
688                         try
689                         {
690                                 gen.GenerateSerializers (sw);
691                         }
692                         catch (Exception ex)
693                         {
694                                 Console.WriteLine ("Serializer could not be generated");
695                                 Console.WriteLine (ex);
696                                 cp.TempFiles.Delete ();
697                                 return null;
698                         }
699                         sw.Close ();
700                         
701                         CSharpCodeProvider provider = new CSharpCodeProvider();
702                         ICodeCompiler comp = provider.CreateCompiler ();
703                         
704                         cp.GenerateExecutable = false;
705                         
706                         foreach (Type rtype in gen.ReferencedTypes)
707                         {
708                                 if (!cp.ReferencedAssemblies.Contains (rtype.Assembly.Location))
709                                         cp.ReferencedAssemblies.Add (rtype.Assembly.Location);
710                         }
711                                 
712                         if (!cp.ReferencedAssemblies.Contains ("System.dll"))
713                                 cp.ReferencedAssemblies.Add ("System.dll");
714                         if (!cp.ReferencedAssemblies.Contains ("System.Xml"))
715                                 cp.ReferencedAssemblies.Add ("System.Xml");
716                         if (!cp.ReferencedAssemblies.Contains ("System.Data"))
717                                 cp.ReferencedAssemblies.Add ("System.Data");
718                         
719                         CompilerResults res = comp.CompileAssemblyFromFile (cp, file);
720                         if (res.Errors.HasErrors || res.CompiledAssembly == null) {
721                                 Console.WriteLine ("Error while compiling generated serializer");
722                                 foreach (CompilerError error in res.Errors)
723                                         Console.WriteLine (error);
724                                         
725                                 cp.TempFiles.Delete ();
726                                 return null;
727                         }
728                         
729                         GenerationResult[] results = gen.GenerationResults;
730                         for (int n=0; n<results.Length; n++)
731                         {
732                                 GenerationResult gres = results[n];
733                                 SerializerData sd = batch.Datas [n];
734                                 lock (sd)
735                                 {
736                                         sd.WriterType = res.CompiledAssembly.GetType (gres.Namespace + "." + gres.WriterClassName);
737                                         sd.ReaderType = res.CompiledAssembly.GetType (gres.Namespace + "." + gres.ReaderClassName);
738                                         sd.WriterMethod = sd.WriterType.GetMethod (gres.WriteMethodName);
739                                         sd.ReaderMethod = sd.ReaderType.GetMethod (gres.ReadMethodName);
740                                         sd.Batch = null;
741                                 }
742                         }
743                         
744                         cp.TempFiles.Delete ();
745
746                         if (!deleteTempFiles)
747                                 Console.WriteLine ("Generation finished - " + (DateTime.Now - tim).TotalMilliseconds + " ms");
748                                 
749                         return res.CompiledAssembly;
750                 }
751 #endif
752                 
753 #if NET_2_0
754                 GenerationBatch LoadFromSatelliteAssembly (GenerationBatch batch)
755                 {
756                         return batch;
757                 }
758 #else
759                 GenerationBatch LoadFromSatelliteAssembly (GenerationBatch batch)
760                 {
761                         return batch;
762                 }
763 #endif
764                 
765 #endregion // Methods
766         }
767 }