code_junkie

How to XML Serialize a 'Type'

Nov 12th, 2011
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. public class NewObject
  2. {
  3. }
  4.  
  5. [XmlRoot]
  6. public class XmlData
  7. {
  8. private Type t;
  9.  
  10. public Type T
  11. {
  12. get { return t; }
  13. set { t = value; }
  14. }
  15. }
  16. static void Main(string[] args)
  17. {
  18. XmlData data = new XmlData();
  19. data.T = typeof(NewObject);
  20. try
  21. {
  22. XmlSerializer serializer = new XmlSerializer(typeof(XmlData));
  23. try
  24. {
  25. using (FileStream fs = new FileStream("test.xml", FileMode.Create))
  26. {
  27. serializer.Serialize(fs, data);
  28. }
  29. }
  30. catch (Exception ex)
  31. {
  32.  
  33. }
  34. }
  35. catch (Exception ex)
  36. {
  37.  
  38. }
  39. }
  40.  
  41. public class c
  42. {
  43. [XmlIgnore]
  44. private Type t;
  45. [XmlIgnore]
  46. public Type T {
  47. get { return t; }
  48. set {
  49. t = value;
  50. tName = value.AssemblyQualifiedName;
  51. }
  52. }
  53.  
  54. public string tName{
  55. get { return t.AssemblyQualifiedName; }
  56. set { t = Type.GetType(value);}
  57. }
  58. }
  59.  
  60. Class dummie
  61. {
  62. Type objType;
  63. string xml;
  64. }
Add Comment
Please, Sign In to add comment