[2019-12] [threads] Add back mono_threads_attach_tools_thread as a public API (#18074)
[mono-project.git] / mono / tests / bug-2907.cs
blobc1223c44379a8c6411caacf9732c1e4bb3071d9a
1 using System;
2 using System.IO;
3 using System.Xml.Serialization;
6 class Program
8 static public T DeserializeFromString<T>(string xml) where T : class
11 if (String.IsNullOrEmpty(xml))
13 return null;
16 StringReader reader = null;
17 T deserializedObject = null;
18 try
20 reader = new StringReader(xml);
21 XmlSerializer serializer = new XmlSerializer(typeof(T));
22 deserializedObject = serializer.Deserialize(reader) as T;
24 finally
26 if (null != reader)
28 reader.Close();
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);
41 if(data == null)
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">
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>
67 //------------------------------------------------------------------------------
68 // <auto-generated>
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.
74 // </auto-generated>
75 //------------------------------------------------------------------------------
77 //
78 // This source code was auto-generated by xsd, Version=4.0.30319.1.
79 //
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 {
91 private object itemField;
93 private ItemChoiceType itemElementNameField;
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;
103 set {
104 this.itemField = value;
108 /// <remarks/>
109 [System.Xml.Serialization.XmlElementAttribute(Order=1)]
110 [System.Xml.Serialization.XmlIgnoreAttribute()]
111 public ItemChoiceType ItemElementName {
112 get {
113 return this.itemElementNameField;
115 set {
116 this.itemElementNameField = value;
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 {
127 /// <remarks/>
128 OptionA,
130 /// <remarks/>
131 OptionB,