Files
mono/mcs/class/System.XML/System.Xml.Serialization/ReflectionHelper.cs
T
Lluis Sanchez 304353fc3f * SerializationCodeGenerator.cs, XmlSerializationReaderInterpreter.cs:
When deserializing an encoded method response, if the return type of the
	  method is Object, assign to it the first element of the message, whatever
	  it is.
	* XmlSerializationReader.cs:
	* SoapReflectionImporter.cs, XmlReflectionImporter.cs: Set IsReturnValue of
	  the imported member.
	* TypeTranslator.cs: Added method to safely get a primitive TypeData.
	* XmlSerializationReader.cs: Don't throw an exception when the CLR type for
	  a given xsi type is not found. Just read it as primitive type.
	* XmlTypeMapMember.cs: Added IsReturnValue property.
	* XmlTypeMapping.cs: Added ReturnMember property.
	* XmlSerializer.cs: Reference System.Data when compiling the serializer.

svn path=/trunk/mcs/; revision=26836
2004-05-06 15:08:58 +00:00

68 lines
2.0 KiB
C#

//
// System.Xml.Serialization.ReflectionHelper
//
// Author:
// Lluis Sanchez Gual ([email protected])
//
// Copyright (C) 2003 Ximian, Inc.
//
using System.Reflection;
using System.Collections;
namespace System.Xml.Serialization
{
internal class ReflectionHelper
{
Hashtable _clrTypes = new Hashtable ();
Hashtable _schemaTypes = new Hashtable ();
public void RegisterSchemaType (XmlTypeMapping map, string xmlType, string ns)
{
string mapKey = xmlType + "/" + ns;
if (!_schemaTypes.ContainsKey (xmlType))
_schemaTypes.Add (mapKey, map);
}
public XmlTypeMapping GetRegisteredSchemaType (string xmlType, string ns)
{
string mapKey = xmlType + "/" + ns;
return _schemaTypes[mapKey] as XmlTypeMapping;
}
public void RegisterClrType (XmlTypeMapping map, Type type, string ns)
{
if (type == typeof(object)) ns = "";
string mapKey = type.FullName + "/" + ns;
if (!_clrTypes.ContainsKey (mapKey))
_clrTypes.Add (mapKey, map);
}
public XmlTypeMapping GetRegisteredClrType (Type type, string ns)
{
if (type == typeof(object)) ns = "";
string mapKey = type.FullName + "/" + ns;
return _clrTypes[mapKey] as XmlTypeMapping;
}
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 (type.IsArray) return;
if (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");
}
}
}