Merge pull request #5714 from alexischr/update_bockbuild
[mono.git] / mono / tests / bug-2907.cs
1 using System;
2 using System.IO;
3 using System.Xml.Serialization;
4
5
6 class Program
7 {
8     static public T DeserializeFromString<T>(string xml) where T : class
9     {
10
11         if (String.IsNullOrEmpty(xml))
12         {
13             return null;
14         }
15
16         StringReader reader = null;
17         T deserializedObject = null;
18         try
19         {
20             reader = new StringReader(xml);
21             XmlSerializer serializer = new XmlSerializer(typeof(T));
22             deserializedObject = serializer.Deserialize(reader) as T;
23         }
24         finally
25         {
26             if (null != reader)
27             {
28                 reader.Close();
29             }
30         }
31         return deserializedObject;
32     }
33
34
35     static void Main(string[] args)
36     {
37         string myXML = @"<?xml version=""1.0"" encoding=""utf-8""?><TASK><OptionA/></TASK>";
38
39         // The following line fails on Mono 2.8 2.10 2.10.8.1 2.10.9
40         TASK data = DeserializeFromString<TASK>(myXML);
41         if(data == null)
42         {
43             throw new Exception("A#01");
44         }
45         if(data.ItemElementName != ItemChoiceType.OptionA)
46         {
47             throw new Exception("A#02");
48         }
49     }
50 }
51
52 // Below is the code generated from the following XSD:
53 /*
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">
57                 <xs:complexType>
58                         <xs:choice>
59                                 <xs:element name="OptionA"/>
60                                 <xs:element name="OptionB"/>
61                         </xs:choice>
62                 </xs:complexType>
63         </xs:element>
64 </xs:schema>
65 */
66
67 //------------------------------------------------------------------------------
68 // <auto-generated>
69 //     This code was generated by a tool.
70 //     Runtime Version:4.0.30319.239
71 //
72 //     Changes to this file may cause incorrect behavior and will be lost if
73 //     the code is regenerated.
74 // </auto-generated>
75 //------------------------------------------------------------------------------
76
77 // 
78 // This source code was auto-generated by xsd, Version=4.0.30319.1.
79 // 
80
81
82 /// <remarks/>
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 {
90     
91     private object itemField;
92     
93     private ItemChoiceType itemElementNameField;
94     
95     /// <remarks/>
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")]
99     public object Item {
100         get {
101             return this.itemField;
102         }
103         set {
104             this.itemField = value;
105         }
106     }
107     
108     /// <remarks/>
109     [System.Xml.Serialization.XmlElementAttribute(Order=1)]
110     [System.Xml.Serialization.XmlIgnoreAttribute()]
111     public ItemChoiceType ItemElementName {
112         get {
113             return this.itemElementNameField;
114         }
115         set {
116             this.itemElementNameField = value;
117         }
118     }
119 }
120
121 /// <remarks/>
122 [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.1")]
123 [System.SerializableAttribute()]
124 [System.Xml.Serialization.XmlTypeAttribute(IncludeInSchema=false)]
125 public enum ItemChoiceType {
126     
127     /// <remarks/>
128     OptionA,
129     
130     /// <remarks/>
131     OptionB,
132 }