3 using System
.Xml
.Serialization
;
8 static public T DeserializeFromString
<T
>(string xml
) where T
: class
11 if (String
.IsNullOrEmpty(xml
))
16 StringReader reader
= null;
17 T deserializedObject
= null;
20 reader
= new StringReader(xml
);
21 XmlSerializer serializer
= new XmlSerializer(typeof(T
));
22 deserializedObject
= serializer
.Deserialize(reader
) as T
;
31 return deserializedObject
;
35 static void Main(string[] args
)
37 string myXML
= @"<?xml version=""1.0"" encoding=""utf-8""?><TASK><OptionA/></TASK>";
39 // The following line fails on Mono 2.8 2.10 2.10.8.1 2.10.9
40 TASK data
= DeserializeFromString
<TASK
>(myXML
);
43 throw new Exception("A#01");
45 if(data
.ItemElementName
!= ItemChoiceType
.OptionA
)
47 throw new Exception("A#02");
52 // Below is the code generated from the following XSD:
54 <?xml version="1.0" encoding="UTF-8"?>
55 <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
56 <xs:element name="TASK">
59 <xs:element name="OptionA"/>
60 <xs:element name="OptionB"/>
67 //------------------------------------------------------------------------------
69 // This code was generated by a tool.
70 // Runtime Version:4.0.30319.239
72 // Changes to this file may cause incorrect behavior and will be lost if
73 // the code is regenerated.
75 //------------------------------------------------------------------------------
78 // This source code was auto-generated by xsd, Version=4.0.30319.1.
83 [System
.CodeDom
.Compiler
.GeneratedCodeAttribute("xsd", "4.0.30319.1")]
84 [System
.SerializableAttribute()]
85 [System
.Diagnostics
.DebuggerStepThroughAttribute()]
86 [System
.ComponentModel
.DesignerCategoryAttribute("code")]
87 [System
.Xml
.Serialization
.XmlTypeAttribute(AnonymousType
=true)]
88 [System
.Xml
.Serialization
.XmlRootAttribute(Namespace
="", IsNullable
=false)]
89 public partial class TASK
{
91 private object itemField
;
93 private ItemChoiceType itemElementNameField
;
96 [System
.Xml
.Serialization
.XmlElementAttribute("OptionA", typeof(object), Order
=0)]
97 [System
.Xml
.Serialization
.XmlElementAttribute("OptionB", typeof(object), Order
=0)]
98 [System
.Xml
.Serialization
.XmlChoiceIdentifierAttribute("ItemElementName")]
101 return this.itemField
;
104 this.itemField
= value;
109 [System
.Xml
.Serialization
.XmlElementAttribute(Order
=1)]
110 [System
.Xml
.Serialization
.XmlIgnoreAttribute()]
111 public ItemChoiceType ItemElementName
{
113 return this.itemElementNameField
;
116 this.itemElementNameField
= value;
122 [System
.CodeDom
.Compiler
.GeneratedCodeAttribute("xsd", "4.0.30319.1")]
123 [System
.SerializableAttribute()]
124 [System
.Xml
.Serialization
.XmlTypeAttribute(IncludeInSchema
=false)]
125 public enum ItemChoiceType
{