// 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;
- if (!_schemaTypes.ContainsKey (xmlType))
+ if (!_schemaTypes.ContainsKey (mapKey))
_schemaTypes.Add (mapKey, map);
}
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);
}
-
- public static void CheckSerializableType (Type type)
+
+#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 (type.GetConstructor (Type.EmptyTypes) == null && !type.IsAbstract && !type.IsValueType)
+#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)
+ if (type.IsInterface && !TypeTranslator.GetTypeData (type).IsListType)
throw new InvalidOperationException (type.FullName + " cannot be serialized because it is an interface");
Type t = type;
+ Type oldt = null;
do {
if (!t.IsPublic && !t.IsNestedPublic)
throw new InvalidOperationException (type.FullName + " is inaccessible due to its protection level. Only public types can be processed");
+ oldt = t;
t = t.DeclaringType;
}
- while (t != null);
+ while (t != null && t != oldt);
+ }
+
+ public static string BuildMapKey (Type type)
+ {
+ return type.FullName + "::";
+ }
+
+ public static string BuildMapKey (MethodInfo method, string tag)
+ {
+ string res = method.DeclaringType.FullName + ":" + method.ReturnType.FullName + " " + method.Name + "(";
+
+ ParameterInfo[] pars = method.GetParameters ();
+
+ for (int n=0; n<pars.Length; n++)
+ {
+ if (n > 0) res += ", ";
+ res += pars[n].ParameterType.FullName;
+ }
+ res += ")";
+
+ if (tag != null)
+ res += ":" + tag;
+
+ return res;
}
- }\r
+ }
}