Merge pull request #3626 from lateralusX/jlorenss/win-api-family-support-eglib
[mono.git] / mcs / class / System.XML / System.Xml.Serialization / XmlSerializer.cs
index aee785818630027d795b61db1cde43f2d327a68c..60bbc316699e378070fa9628ddd884b9e818f2da 100644 (file)
@@ -37,7 +37,7 @@ using System.Reflection;
 using System.Xml;
 using System.Xml.Schema;
 using System.Text;
-#if !TARGET_JVM && !NET_2_1
+#if !MOBILE
 using System.CodeDom;
 using System.CodeDom.Compiler;
 using Microsoft.CSharp;
@@ -68,6 +68,7 @@ namespace System.Xml.Serialization
                internal class SerializerData
                {
                        public int UsageCount;
+                       public bool Generated;
                        public Type ReaderType;
                        public MethodInfo ReaderMethod;
                        public Type WriterType;
@@ -120,7 +121,7 @@ namespace System.Xml.Serialization
                        //       debugging pourposes by adding the "nofallback" option.
                        //       For example: MONO_XMLSERIALIZER_THS=0,nofallback
                        
-#if TARGET_JVM || NET_2_1
+#if MOBILE
                        string db = null;
                        string th = null;
                        generationThreshold = -1;
@@ -145,20 +146,26 @@ namespace System.Xml.Serialization
                                else {
                                        generationThreshold = int.Parse (th, CultureInfo.InvariantCulture);
                                        backgroundGeneration = (generationThreshold != 0);
-                                       if (generationThreshold < 1) generationThreshold = 1;
                                }
                        }
 #endif
                        deleteTempFiles = (db == null || db == "no");
-#if !NET_2_1
-                       IDictionary table = (IDictionary) ConfigurationSettings.GetConfig("system.diagnostics");
+#if !MOBILE && CONFIGURATION_DEP
+                       // DiagnosticsSection
+                       ConfigurationSection table = (ConfigurationSection) ConfigurationSettings.GetConfig("system.diagnostics");
+                       var bf = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance;
                        if (table != null) 
                        {
-                               table = (IDictionary) table["switches"];
-                               if (table != null) 
-                               {
-                                       string val = (string) table ["XmlSerialization.Compilation"];
-                                       if (val == "1") deleteTempFiles = false;
+                               // SwitchElementsCollection
+                               var pi = table.GetType ().GetProperty ("Switches", bf);
+                               var switchesElement = (ConfigurationElementCollection) pi.GetValue (table, null);
+                               foreach (ConfigurationElement e in switchesElement) {
+                                       // SwitchElement
+                                       if (e.GetType ().GetProperty ("Name", bf).GetValue (e, null) as string == "XmlSerialization.Compilation") {
+                                               if (e.GetType ().GetProperty ("Value", bf).GetValue (e, null) as string == "1")
+                                                       deleteTempFiles = false;
+                                               break;
+                                       }
                                }
                        }
 #endif
@@ -197,6 +204,11 @@ namespace System.Xml.Serialization
                {
                }
 
+               public XmlSerializer (Type type, XmlAttributeOverrides overrides, Type[] extraTypes, XmlRootAttribute root, string defaultNamespace, string location)
+                       : this (type, overrides, extraTypes, root, defaultNamespace, location, null)
+               {
+               }
+
                public XmlSerializer (Type type, XmlAttributeOverrides overrides)
                        : this (type, overrides, null, null, null)
                {
@@ -232,7 +244,6 @@ namespace System.Xml.Serialization
                        get { return typeMapping; }
                }
 
-#if NET_2_0
 
                [MonoTODO]
                public XmlSerializer (Type type,
@@ -244,7 +255,6 @@ namespace System.Xml.Serialization
                        Evidence evidence)
                {
                }
-#endif
 
 #endregion // Constructors
 
@@ -467,13 +477,8 @@ namespace System.Xml.Serialization
 
                                if (namespaces == null || namespaces.Count == 0) {
                                        namespaces = new XmlSerializerNamespaces ();
-#if NET_2_0
                                        namespaces.Add ("xsi", XmlSchema.InstanceNamespace);
                                        namespaces.Add ("xsd", XmlSchema.Namespace);
-#else
-                                       namespaces.Add ("xsd", XmlSchema.Namespace);
-                                       namespaces.Add ("xsi", XmlSchema.InstanceNamespace);
-#endif
                                }
 
                                xsWriter.Initialize (xmlWriter, namespaces);
@@ -491,8 +496,6 @@ namespace System.Xml.Serialization
                        }
                }
                
-#if !NET_2_1
-               
                [MonoTODO]
                public object Deserialize (XmlReader xmlReader, string encodingStyle, XmlDeserializationEvents events)
                {
@@ -523,7 +526,7 @@ namespace System.Xml.Serialization
                        throw new NotImplementedException ();
                }
 
-#if !TARGET_JVM && !MOBILE
+#if !MOBILE
                public static Assembly GenerateSerializer (Type[] types, XmlMapping[] mappings)
                {
                        return GenerateSerializer (types, mappings, null);
@@ -567,7 +570,6 @@ namespace System.Xml.Serialization
                {
                        throw new NotImplementedException ();
                }
-#endif
                
                XmlSerializationWriter CreateWriter (XmlMapping typeMapping)
                {
@@ -582,7 +584,7 @@ namespace System.Xml.Serialization
                                }
                        }
                        
-#if !NET_2_1
+#if !MOBILE
                        if (!typeMapping.Source.CanBeGenerated || generationThreshold == -1)
                                return new XmlSerializationWriterInterpreter (typeMapping);
 
@@ -603,7 +605,7 @@ namespace System.Xml.Serialization
                
                XmlSerializationReader CreateReader (XmlMapping typeMapping)
                {
-#if !NET_2_1
+#if !MOBILE
                        XmlSerializationReader reader;
                        
                        lock (this) {
@@ -633,7 +635,7 @@ namespace System.Xml.Serialization
                        return new XmlSerializationReaderInterpreter (typeMapping);
                }
                
-#if TARGET_JVM || NET_2_1
+#if MOBILE
                void CheckGeneratedTypes (XmlMapping typeMapping)
                {
                        throw new NotImplementedException();
@@ -667,7 +669,10 @@ namespace System.Xml.Serialization
                        bool generate = false;
                        lock (serializerData)
                        {
-                               generate = (++serializerData.UsageCount == generationThreshold);
+                               if (serializerData.UsageCount >= generationThreshold && !serializerData.Generated)
+                                       serializerData.Generated = generate = true;
+
+                               serializerData.UsageCount++;
                        }
                        
                        if (generate)
@@ -769,6 +774,8 @@ namespace System.Xml.Serialization
                                cp.ReferencedAssemblies.Add ("System.Xml");
                        if (!cp.ReferencedAssemblies.Contains ("System.Data"))
                                cp.ReferencedAssemblies.Add ("System.Data");
+                       if (!cp.ReferencedAssemblies.Contains ("System.Web.Services"))
+                               cp.ReferencedAssemblies.Add ("System.Web.Services");
                        
                        CompilerResults res = comp.CompileAssemblyFromFile (cp, file);
                        if (res.Errors.HasErrors || res.CompiledAssembly == null) {
@@ -804,17 +811,10 @@ namespace System.Xml.Serialization
                }
 #endif
                
-#if NET_2_0
                GenerationBatch LoadFromSatelliteAssembly (GenerationBatch batch)
                {
                        return batch;
                }
-#else
-               GenerationBatch LoadFromSatelliteAssembly (GenerationBatch batch)
-               {
-                       return batch;
-               }
-#endif
                
 #endregion // Methods
        }