X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Fclass%2FSystem.XML%2FSystem.Xml.Serialization%2FReflectionHelper.cs;h=ca683f99c7354f221df56c16630d8855fc601b28;hb=018c4be8c5ef6e23ccd9bf798513a6178631e1ea;hp=07890b67663e94698662088a5ced349c222e1972;hpb=304353fc3f8f965b438081f0e7a917fee164f8b9;p=mono.git diff --git a/mcs/class/System.XML/System.Xml.Serialization/ReflectionHelper.cs b/mcs/class/System.XML/System.Xml.Serialization/ReflectionHelper.cs index 07890b67663..ca683f99c73 100644 --- a/mcs/class/System.XML/System.Xml.Serialization/ReflectionHelper.cs +++ b/mcs/class/System.XML/System.Xml.Serialization/ReflectionHelper.cs @@ -7,6 +7,27 @@ // Copyright (C) 2003 Ximian, Inc. // +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + using System.Reflection; using System.Collections; @@ -20,7 +41,7 @@ namespace System.Xml.Serialization 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); } @@ -50,18 +71,47 @@ namespace System.Xml.Serialization return new InvalidOperationException ("There was an error reflecting '" + map.TypeFullName + "': " + message); } - public static void CheckSerializableType (Type type) + public static void CheckSerializableType (Type type, bool allowPrivateConstructors) { if (type.IsArray) return; - if (type.GetConstructor (Type.EmptyTypes) == null && !type.IsAbstract && !type.IsValueType) + if (!allowPrivateConstructors && type.GetConstructor (Type.EmptyTypes) == null && !type.IsAbstract && !type.IsValueType) throw new InvalidOperationException (type.FullName + " cannot be serialized because it does not have a default public constructor"); if (type.IsInterface) throw new InvalidOperationException (type.FullName + " cannot be serialized because it is an interface"); - if (type.IsNotPublic) - throw new InvalidOperationException (type.FullName + " is inaccessible due to its protection level. Only public types can be processed"); + Type t = type; + do { + if (!t.IsPublic && !t.IsNestedPublic) + throw new InvalidOperationException (type.FullName + " is inaccessible due to its protection level. Only public types can be processed"); + t = t.DeclaringType; + } + while (t != null); + } + + 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 0) res += ", "; + res += pars[n].ParameterType.FullName; + } + res += ")"; + + if (tag != null) + res += ":" + tag; + + return res; } } }