Moved chain building and validation from Mono.Security to System
[mono.git] / mcs / class / System.XML / System.Xml.Serialization / ReflectionHelper.cs
index 99e77494c1f73b4f67f905c47a4a9462f4b0c3c5..a44b9b836f821ea8a82251d34bdff5bce3a77c41 100644 (file)
@@ -4,7 +4,7 @@
 // Author:
 //   Lluis Sanchez Gual (lluis@ximian.com)
 //
-// Copyright (C) 2003 Ximian, Inc.\r
+// Copyright (C) 2003 Ximian, Inc.
 //
 
 //
 
 using System.Reflection;
 using System.Collections;
-\r
-namespace System.Xml.Serialization\r
-{\r
-       internal class ReflectionHelper\r
-       {\r
+
+namespace System.Xml.Serialization
+{
+       internal class ReflectionHelper
+       {
                Hashtable _clrTypes = new Hashtable ();
                Hashtable _schemaTypes = new Hashtable ();
-\r
+
                public void RegisterSchemaType (XmlTypeMapping map, string xmlType, string ns)
                {
                        string mapKey = xmlType + "/" + ns;
@@ -64,18 +64,26 @@ namespace System.Xml.Serialization
                        if (type == typeof(object)) ns = "";
                        string mapKey = type.FullName + "/" + ns;
                        return _clrTypes[mapKey] as XmlTypeMapping;
-               }       \r
-\r
+               }       
+
                public Exception CreateError (XmlTypeMapping map, string message)
                {
                        return new InvalidOperationException ("There was an error reflecting '" + map.TypeFullName + "': " + message);
                }
-               
+
+#if NET_2_0
+               static readonly ParameterModifier [] empty_modifiers = new ParameterModifier [0];
+#endif         
+
                public static void CheckSerializableType (Type type, bool allowPrivateConstructors)
                {
                        if (type.IsArray) return;
                        
+#if NET_2_0
+                       if (!allowPrivateConstructors && type.GetConstructor (BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance, null, Type.EmptyTypes, empty_modifiers) == null && !type.IsAbstract && !type.IsValueType)
+#else
                        if (!allowPrivateConstructors && type.GetConstructor (Type.EmptyTypes) == null && !type.IsAbstract && !type.IsValueType)
+#endif
                                throw new InvalidOperationException (type.FullName + " cannot be serialized because it does not have a default public constructor");
                                
                        if (type.IsInterface && !TypeTranslator.GetTypeData (type).IsListType)
@@ -115,5 +123,5 @@ namespace System.Xml.Serialization
                                
                        return res;
                }
-       }\r
+       }
 }