ReflectionHelper.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. //
  2. // System.Xml.Serialization.ReflectionHelper
  3. //
  4. // Author:
  5. // Lluis Sanchez Gual ([email protected])
  6. //
  7. // Copyright (C) 2003 Ximian, Inc.
  8. //
  9. using System.Reflection;
  10. using System.Collections;
  11. namespace System.Xml.Serialization
  12. {
  13. internal class ReflectionHelper
  14. {
  15. Hashtable _clrTypes = new Hashtable ();
  16. Hashtable _schemaTypes = new Hashtable ();
  17. public void RegisterSchemaType (XmlTypeMapping map, string xmlType, string ns)
  18. {
  19. string mapKey = xmlType + "/" + ns;
  20. if (!_schemaTypes.ContainsKey (xmlType))
  21. _schemaTypes.Add (mapKey, map);
  22. }
  23. public XmlTypeMapping GetRegisteredSchemaType (string xmlType, string ns)
  24. {
  25. string mapKey = xmlType + "/" + ns;
  26. return _schemaTypes[mapKey] as XmlTypeMapping;
  27. }
  28. public void RegisterClrType (XmlTypeMapping map, Type type, string ns)
  29. {
  30. if (type == typeof(object)) ns = "";
  31. string mapKey = type.FullName + "/" + ns;
  32. if (!_clrTypes.ContainsKey (mapKey))
  33. _clrTypes.Add (mapKey, map);
  34. }
  35. public XmlTypeMapping GetRegisteredClrType (Type type, string ns)
  36. {
  37. if (type == typeof(object)) ns = "";
  38. string mapKey = type.FullName + "/" + ns;
  39. return _clrTypes[mapKey] as XmlTypeMapping;
  40. }
  41. public Exception CreateError (XmlTypeMapping map, string message)
  42. {
  43. return new InvalidOperationException ("There was an error reflecting '" + map.TypeFullName + "': " + message);
  44. }
  45. }
  46. }