Merge pull request #439 from mono-soc-2012/garyb/iconfix
[mono.git] / mcs / class / System.Xml.Linq / Test / System.Xml.Linq / XAttributeTest.cs
1 //
2 // Authors:
3 //   Atsushi Enomoto
4 //
5 // Copyright 2007 Novell (http://www.novell.com)
6 //
7 // Permission is hereby granted, free of charge, to any person obtaining
8 // a copy of this software and associated documentation files (the
9 // "Software"), to deal in the Software without restriction, including
10 // without limitation the rights to use, copy, modify, merge, publish,
11 // distribute, sublicense, and/or sell copies of the Software, and to
12 // permit persons to whom the Software is furnished to do so, subject to
13 // the following conditions:
14 // 
15 // The above copyright notice and this permission notice shall be
16 // included in all copies or substantial portions of the Software.
17 // 
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 //
26
27 using System;
28 using System.Collections.Generic;
29 using System.Linq;
30 using System.Xml;
31 using System.Xml.Linq;
32
33 using NUnit.Framework;
34
35 namespace MonoTests.System.Xml.Linq
36 {
37         [TestFixture]
38         public class XAttributeTest
39         {
40                 [Test]
41                 public void Annotations_GetSubclass()
42                 {
43                         var x = new XAttribute("foo", "bar");
44                         var annotation = new InvalidCastException();
45                         x.AddAnnotation(annotation);
46                         
47                         Assert.AreSame(annotation, x.Annotation<InvalidCastException>(), "#1");
48                         Assert.AreSame(annotation, x.Annotation<object>(), "#2");
49                         Assert.AreSame(annotation, x.Annotations<object>().Single (), "#3");
50                 }
51
52                 [Test]
53                 public void Annotations_SameTypeTwice()
54                 {
55                         var x = new XAttribute("foo", "bar");
56                         var first = new InvalidCastException();
57                         var second = new InvalidCastException();
58                         x.AddAnnotation(first);
59                         x.AddAnnotation(second);
60                         Assert.AreEqual(2, x.Annotations<object>().Count(), "#1");
61                         Assert.AreSame(first, x.Annotation<object>(), "#2");
62                 }
63
64                 [Test]
65                 public void Constructor_NullParameters ()
66                 {
67                         AssertThrows<ArgumentNullException>(() => new XAttribute(null, "v"), "#1");
68                         AssertThrows<ArgumentNullException>(() => new XAttribute(XName.Get("a"), null), "#2");
69                         AssertThrows<ArgumentNullException>(() => new XAttribute((XAttribute) null), "#3");
70                 }
71
72                 [Test]
73                 public void IsNamespaceDeclaration ()
74                 {
75                         string xml = "<root a='v' xmlns='urn:foo' xmlns:x='urn:x' x:a='v' xmlns:xml='http://www.w3.org/XML/1998/namespace' />";
76                         XElement el = XElement.Parse (xml);
77                         List<XAttribute> l = new List<XAttribute> (el.Attributes ());
78                         Assert.IsFalse (l [0].IsNamespaceDeclaration, "#1");
79                         Assert.IsTrue (l [1].IsNamespaceDeclaration, "#2");
80                         Assert.IsTrue (l [2].IsNamespaceDeclaration, "#3");
81                         Assert.IsFalse (l [3].IsNamespaceDeclaration, "#4");
82                         Assert.IsTrue (l [4].IsNamespaceDeclaration, "#5");
83
84                         Assert.AreEqual ("a", l [0].Name.LocalName, "#2-1");
85                         Assert.AreEqual ("xmlns", l [1].Name.LocalName, "#2-2");
86                         Assert.AreEqual ("x", l [2].Name.LocalName, "#2-3");
87                         Assert.AreEqual ("a", l [3].Name.LocalName, "#2-4");
88                         Assert.AreEqual ("xml", l [4].Name.LocalName, "#2-5");
89
90                         Assert.AreEqual ("", l [0].Name.NamespaceName, "#3-1");
91                         // not sure how current Orcas behavior makes sense here though ...
92                         Assert.AreEqual ("", l [1].Name.NamespaceName, "#3-2");
93                         Assert.AreEqual ("http://www.w3.org/2000/xmlns/", l [2].Name.NamespaceName, "#3-3");
94                         Assert.AreEqual ("urn:x", l [3].Name.NamespaceName, "#3-4");
95                         Assert.AreEqual ("http://www.w3.org/2000/xmlns/", l [4].Name.NamespaceName, "#3-5");
96                 }
97
98                 [Test]
99                 public void Document ()
100                 {
101                         XDocument doc = XDocument.Parse ("<root a='v' />");
102                         Assert.AreEqual (doc, doc.Root.Document, "#1");
103                         foreach (XAttribute a in doc.Root.Attributes ())
104                                 Assert.AreEqual (doc, a.Document, "#2");
105                         Assert.AreEqual (doc, doc.Document, "#3");
106                 }
107
108                 [Test]
109                 public void SetValue ()
110                 {
111                         XAttribute a = new XAttribute (XName.Get ("a"), "v");
112                         a.SetValue (new XDeclaration ("1.0", null, null));
113                         // value object is converted to a string.
114                         Assert.AreEqual ("<?xml version=\"1.0\"?>", a.Value, "#1");
115                 }
116
117                 [Test]
118                 public void SetValue_Null()
119                 {
120                         var a = new XAttribute("foo", "bar");
121                         AssertThrows<ArgumentNullException>(() => a.Value = null, "#1");
122                         AssertThrows<ArgumentNullException>(() => a.SetValue (null), "#2");
123                 }
124
125                 [Test]
126                 public void SetValue_ChangeTriggers()
127                 {
128                         bool changing = false;
129                         bool changed = false;
130
131                         var a = new XAttribute("foo", "bar");
132                         a.Changing += (o, e) => {
133                                 Assert.IsFalse(changing, "#1");
134                                 Assert.IsFalse(changed, "#2");
135                                 Assert.AreSame(a, o, "#3");
136                                 Assert.AreEqual(XObjectChange.Value, e.ObjectChange, "#4");
137                                 changing = true;
138                         };
139                         a.Changed += (o, e) => {
140                                 Assert.IsTrue(changing, "#5");
141                                 Assert.IsFalse(changed, "#6");
142                                 Assert.AreSame(a, o, "#7");
143                                 Assert.AreEqual(XObjectChange.Value, e.ObjectChange, "#8");
144                                 changed = true;
145                         };
146                         a.Value = "foo";
147                         Assert.IsTrue(changing, "changing");
148                         Assert.IsTrue(changed, "changed");
149                 }
150
151                 [Test]
152                 public void SetValue2_ChangeTriggers()
153                 {
154                         bool changing = false;
155                         bool changed = false;
156                         
157                         var a = new XAttribute("foo", "bar");
158                         a.Changing += (o, e) =>
159                         {
160                                 Assert.IsFalse(changing, "#1");
161                                 Assert.IsFalse(changed, "#2");
162                                 Assert.AreSame(a, o, "#3");
163                                 Assert.AreEqual(XObjectChange.Value, e.ObjectChange, "#4");
164                                 changing = true;
165                         };
166                         a.Changed += (o, e) =>
167                         {
168                                 Assert.IsTrue(changing, "#5");
169                                 Assert.IsFalse(changed, "#6");
170                                 Assert.AreSame(a, o, "#7");
171                                 Assert.AreEqual(XObjectChange.Value, e.ObjectChange, "#8");
172                                 changed = true;
173                         };
174                         a.SetValue("zap");
175                         Assert.IsTrue(changing, "changing");
176                         Assert.IsTrue(changed, "changed");
177                 }
178
179                 [Test]
180                 public void SetValue_SameValue_ChangeTrigger()
181                 {
182                         int changed = 0;
183                         int changing = 0;
184
185                         var a = new XAttribute("foo", "bar");
186                         a.Changed += (o, e) => changed++;
187                         a.Changing += (o, e) => changing++;
188
189                         a.SetValue("bar");
190                         Assert.AreEqual(1, changed, "#1");
191                         Assert.AreEqual(1, changing, "#2");
192
193                         a.Value = "bar";
194                         Assert.AreEqual(2, changed, "#3");
195                         Assert.AreEqual(2, changing, "#4");
196                 }
197
198                 [Test]
199                 public void ToString ()
200                 {
201                         XAttribute a = new XAttribute (XName.Get ("a"), "v");
202                         Assert.AreEqual ("a=\"v\"", a.ToString ());
203
204                         a = new XAttribute (XName.Get ("a"), " >_< ");
205                         Assert.AreEqual ("a=\" &gt;_&lt; \"", a.ToString ());
206                 }
207
208                 [Test]
209                 public void DateTimeAttribute ()
210                 {
211                         var date = DateTime.Now;
212                         var attribute = new XAttribute ("Date", date);
213
214                         var value = (DateTime) attribute;
215
216                         Assert.AreEqual (date, value);
217                 }
218
219 #pragma warning disable 219
220                 [Test]
221                 public void CastNulls ()
222                 {
223                         const XAttribute a = null;
224
225                         Assert.AreEqual (null, (bool?) a, "bool?");
226                         Assert.AreEqual (null, (DateTime?) a, "DateTime?");
227                         Assert.AreEqual (null, (DateTimeOffset?) a, "DateTimeOffset?");
228                         Assert.AreEqual (null, (decimal?) a, "decimal?");
229                         Assert.AreEqual (null, (double?) a, "double?");
230                         Assert.AreEqual (null, (float?) a, "float?");
231                         Assert.AreEqual (null, (Guid?) a, "Guid?");
232                         Assert.AreEqual (null, (int?) a, "int?");
233                         Assert.AreEqual (null, (long?) a, "long?");
234                         Assert.AreEqual (null, (uint?) a, "uint?");
235                         Assert.AreEqual (null, (ulong?) a, "ulong?");
236                         Assert.AreEqual (null, (TimeSpan?) a, "TimeSpan?");
237                         Assert.AreEqual (null, (string) a, "string");
238                         AssertThrows<ArgumentNullException> (() => { bool z = (bool) a; }, "bool");
239                         AssertThrows<ArgumentNullException> (() => { DateTime z = (DateTime) a; }, "DateTime");
240                         AssertThrows<ArgumentNullException> (() => { DateTimeOffset z = (DateTimeOffset) a; }, "DateTimeOffset");
241                         AssertThrows<ArgumentNullException> (() => { decimal z = (decimal) a; }, "decimal");
242                         AssertThrows<ArgumentNullException> (() => { double z = (double) a; }, "double");
243                         AssertThrows<ArgumentNullException> (() => { float z = (float) a; }, "float");
244                         AssertThrows<ArgumentNullException> (() => { Guid z = (Guid) a; }, "Guid");
245                         AssertThrows<ArgumentNullException> (() => { int z = (int) a; }, "int");
246                         AssertThrows<ArgumentNullException> (() => { long z = (long) a; }, "long");
247                         AssertThrows<ArgumentNullException> (() => { uint z = (uint) a; }, "uint");
248                         AssertThrows<ArgumentNullException> (() => { ulong z = (ulong) a; }, "ulong");
249                         AssertThrows<ArgumentNullException> (() => { TimeSpan z = (TimeSpan) a; }, "TimeSpan");
250                 }
251
252                 /// <remarks>
253                 /// Provides functionality similar to Assert.Throws that is available on newer versions of NUnit.
254                 /// </remarks>
255                 private static T AssertThrows<T> (Action code, string message, params object[] args) where T : Exception
256                 {
257                         Exception actual = null;
258                         try {
259                                 code ();
260                         } catch (Exception exception) {
261                                 actual = exception;
262                         }
263                         Assert.That (actual, new NUnit.Framework.Constraints.ExactTypeConstraint (typeof (T)), message, args);
264                         return (T) actual;
265                 }
266
267                 [Test]
268                 public void CastEmptiesOrBlanks ()
269                 {
270                         XAttribute a = new XAttribute ("a", String.Empty);
271
272                         // Verify expected "cloning" and "empty/blank" behaviour as prerequisites
273                         Assert.AreEqual (String.Empty, a.Value, "#1-1");
274                         Assert.AreEqual (String.Empty, new XAttribute (a).Value, "#1-2");
275                         Assert.AreNotSame (a, new XAttribute (a), "#2-1");
276                         Assert.AreEqual (a.ToString (), new XAttribute (a).ToString (), "#2-2");
277                         Assert.AreEqual ("a=\"\"", a.ToString (), "#2-3");
278
279                         // Execute the primary assertions of this test
280                         AssertThrows<FormatException> (() => { bool? z = (bool?) new XAttribute (a); }, "bool?");
281                         AssertThrows<FormatException> (() => { DateTime? z = (DateTime?) new XAttribute (a); }, "DateTime?");
282                         AssertThrows<FormatException> (() => { DateTimeOffset? z = (DateTimeOffset?) new XAttribute (a); }, "DateTimeOffset?");
283                         AssertThrows<FormatException> (() => { decimal? z = (decimal?) new XAttribute (a); }, "decimal?");
284                         AssertThrows<FormatException> (() => { double? z = (double?) new XAttribute (a); }, "double?");
285                         AssertThrows<FormatException> (() => { float? z = (float?) new XAttribute (a); }, "float?");
286                         AssertThrows<FormatException> (() => { Guid? z = (Guid?) new XAttribute (a); }, "Guid?");
287                         AssertThrows<FormatException> (() => { int? z = (int?) new XAttribute (a); }, "int?");
288                         AssertThrows<FormatException> (() => { long? z = (long?) new XAttribute (a); }, "long?");
289                         AssertThrows<FormatException> (() => { uint? z = (uint?) new XAttribute (a); }, "uint?");
290                         AssertThrows<FormatException> (() => { ulong? z = (ulong?) new XAttribute (a); }, "ulong?");
291                         AssertThrows<FormatException> (() => { TimeSpan? z = (TimeSpan?) new XAttribute (a); }, "TimeSpan?");
292                         Assert.AreEqual (String.Empty, (string) new XAttribute (a), "string");
293                         AssertThrows<FormatException> (() => { bool z = (bool) new XAttribute (a); }, "bool");
294                         AssertThrows<FormatException> (() => { DateTime z = (DateTime) new XAttribute (a); }, "DateTime");
295                         AssertThrows<FormatException> (() => { DateTimeOffset z = (DateTimeOffset) new XAttribute (a); }, "DateTimeOffset");
296                         AssertThrows<FormatException> (() => { decimal z = (decimal) new XAttribute (a); }, "decimal");
297                         AssertThrows<FormatException> (() => { double z = (double) new XAttribute (a); }, "double");
298                         AssertThrows<FormatException> (() => { float z = (float) new XAttribute (a); }, "float");
299                         AssertThrows<FormatException> (() => { Guid z = (Guid) new XAttribute (a); }, "Guid");
300                         AssertThrows<FormatException> (() => { int z = (int) new XAttribute (a); }, "int");
301                         AssertThrows<FormatException> (() => { long z = (long) new XAttribute (a); }, "long");
302                         AssertThrows<FormatException> (() => { uint z = (uint) new XAttribute (a); }, "uint");
303                         AssertThrows<FormatException> (() => { ulong z = (ulong) new XAttribute (a); }, "ulong");
304                         AssertThrows<FormatException> (() => { TimeSpan z = (TimeSpan) new XAttribute (a); }, "TimeSpan");
305                 }
306
307                 [Test]
308                 public void CastSpaces ()
309                 {
310                         XAttribute a = new XAttribute ("a", " ");
311
312                         // Verify expected "cloning" and "space" behaviour as prerequisites
313                         Assert.AreEqual (" ", a.Value, "#1-1");
314                         Assert.AreEqual (" ", new XAttribute (a).Value, "#1-2");
315                         Assert.AreNotSame (a, new XAttribute (a), "#2-1");
316                         Assert.AreEqual (a.ToString (), new XAttribute (a).ToString (), "#2-2");
317                         Assert.AreEqual ("a=\" \"", a.ToString (), "#2-3");
318                         Assert.AreEqual (a.ToString (), new XAttribute ("a", ' ').ToString (), "#2-4");
319
320                         // Execute the primary assertions of this test
321                         AssertThrows<FormatException> (() => { bool? z = (bool?) new XAttribute (a); }, "bool?");
322                         AssertThrows<FormatException> (() => { DateTime? z = (DateTime?) new XAttribute (a); }, "DateTime?");
323                         AssertThrows<FormatException> (() => { DateTimeOffset? z = (DateTimeOffset?) new XAttribute (a); }, "DateTimeOffset?");
324                         AssertThrows<FormatException> (() => { decimal? z = (decimal?) new XAttribute (a); }, "decimal?");
325                         AssertThrows<FormatException> (() => { double? z = (double?) new XAttribute (a); }, "double?");
326                         AssertThrows<FormatException> (() => { float? z = (float?) new XAttribute (a); }, "float?");
327                         AssertThrows<FormatException> (() => { Guid? z = (Guid?) new XAttribute (a); }, "Guid?");
328                         AssertThrows<FormatException> (() => { int? z = (int?) new XAttribute (a); }, "int?");
329                         AssertThrows<FormatException> (() => { long? z = (long?) new XAttribute (a); }, "long?");
330                         AssertThrows<FormatException> (() => { uint? z = (uint?) new XAttribute (a); }, "uint?");
331                         AssertThrows<FormatException> (() => { ulong? z = (ulong?) new XAttribute (a); }, "ulong?");
332                         AssertThrows<FormatException> (() => { TimeSpan? z = (TimeSpan?) new XAttribute (a); }, "TimeSpan?");
333                         Assert.AreEqual (" ", (string) new XAttribute (a), "string");
334                         AssertThrows<FormatException> (() => { bool z = (bool) new XAttribute (a); }, "bool");
335                         AssertThrows<FormatException> (() => { DateTime z = (DateTime) new XAttribute (a); }, "DateTime");
336                         AssertThrows<FormatException> (() => { DateTimeOffset z = (DateTimeOffset) new XAttribute (a); }, "DateTimeOffset");
337                         AssertThrows<FormatException> (() => { decimal z = (decimal) new XAttribute (a); }, "decimal");
338                         AssertThrows<FormatException> (() => { double z = (double) new XAttribute (a); }, "double");
339                         AssertThrows<FormatException> (() => { float z = (float) new XAttribute (a); }, "float");
340                         AssertThrows<FormatException> (() => { Guid z = (Guid) new XAttribute (a); }, "Guid");
341                         AssertThrows<FormatException> (() => { int z = (int) new XAttribute (a); }, "int");
342                         AssertThrows<FormatException> (() => { long z = (long) new XAttribute (a); }, "long");
343                         AssertThrows<FormatException> (() => { uint z = (uint) new XAttribute (a); }, "uint");
344                         AssertThrows<FormatException> (() => { ulong z = (ulong) new XAttribute (a); }, "ulong");
345                         AssertThrows<FormatException> (() => { TimeSpan z = (TimeSpan) new XAttribute (a); }, "TimeSpan");
346                 }
347
348                 [Test]
349                 public void CastNumbers ()
350                 {
351                         XAttribute a = new XAttribute ("a", "7");
352                         XAttribute b = new XAttribute ("b", "  42 ");
353                         XAttribute c = new XAttribute ("c", " \n\r   123 \t  ");
354                         XAttribute d = new XAttribute ("d", -101);
355                         XAttribute o = new XAttribute ("o", "0");
356                         XAttribute l = new XAttribute ("l", "1");
357                         XAttribute I = new XAttribute ("I", "\t    INF    ");
358                         XAttribute i = new XAttribute ("i", "Infinity");
359                         XAttribute M = new XAttribute ("M", "-INF");
360                         XAttribute m = new XAttribute ("m", " -Infinity  ");
361                         XAttribute n = new XAttribute ("n", "NaN");
362
363                         // Verify expected "cloning" and basic conversion behaviour as prerequisites
364                         Assert.AreEqual (" \n\r   123 \t  ", c.Value, "#1-1");
365                         Assert.AreEqual ("-101", new XAttribute (d).Value, "#1-2");
366                         Assert.AreNotSame (o, new XAttribute (o), "#2-1");
367                         Assert.AreEqual (l.ToString (), new XAttribute (l).ToString (), "#2-2");
368                         Assert.AreEqual ("a=\"7\"", a.ToString (), "#2-3a");
369                         Assert.AreEqual ("b=\"  42 \"", b.ToString (), "#2-3b");
370                         Assert.AreEqual ("c=\" &#xA;&#xD;   123 &#x9;  \"", c.ToString (), "#2-3c");
371                         Assert.AreEqual ("d=\"-101\"", d.ToString (), "#2-3d");
372                         Assert.AreEqual ("o=\"0\"", new XAttribute ("o", 0.0).ToString (), "#2-3o");
373                         Assert.AreEqual ("l=\"1\"", new XAttribute ("l", 1.0f).ToString (), "#2-3l");
374                         Assert.AreEqual ("n=\"NaN\"", new XAttribute ("n", double.NaN).ToString (), "#2-3n");
375                         Assert.AreEqual (a.ToString (), new XAttribute ("a", '7').ToString (), "#2-4a");
376                         Assert.AreEqual (d.ToString (), new XAttribute ("d", "-101").ToString (), "#2-4d");
377                         Assert.AreEqual (o.ToString (), new XAttribute ("o", 0L).ToString (), "#2-4o");
378                         Assert.AreEqual (l.ToString (), new XAttribute ("l", 1m).ToString (), "#2-4l");
379
380                         // Execute the primary assertions of this test
381                         AssertThrows<FormatException> (() => { bool? z = (bool?) new XAttribute (a); }, "a:bool?");
382                         AssertThrows<FormatException> (() => { bool? z = (bool?) new XAttribute (b); }, "b:bool?");
383                         AssertThrows<FormatException> (() => { bool? z = (bool?) new XAttribute (c); }, "c:bool?");
384                         AssertThrows<FormatException> (() => { bool? z = (bool?) new XAttribute (d); }, "d:bool?");
385                         Assert.IsNotNull ((bool?) new XAttribute (o), "o:bool?:null");
386                         Assert.AreEqual (false, ((bool?) new XAttribute (o)).Value, "o:bool?:value");
387                         Assert.IsNotNull ((bool?) new XAttribute (l), "l:bool?:null");
388                         Assert.AreEqual (true, ((bool?) new XAttribute (l)).Value, "l:bool?:value");
389                         AssertThrows<FormatException> (() => { bool? z = (bool?) new XAttribute (I); }, "I:bool?");
390                         AssertThrows<FormatException> (() => { bool? z = (bool?) new XAttribute (i); }, "i:bool?");
391                         AssertThrows<FormatException> (() => { bool? z = (bool?) new XAttribute (M); }, "M:bool?");
392                         AssertThrows<FormatException> (() => { bool? z = (bool?) new XAttribute (m); }, "m:bool?");
393                         AssertThrows<FormatException> (() => { bool? z = (bool?) new XAttribute (n); }, "n:bool?");
394                         AssertThrows<FormatException> (() => { DateTime? z = (DateTime?) new XAttribute (a); }, "a:DateTime?");
395                         AssertThrows<FormatException> (() => { DateTime? z = (DateTime?) new XAttribute (b); }, "b:DateTime?");
396                         AssertThrows<FormatException> (() => { DateTime? z = (DateTime?) new XAttribute (c); }, "c:DateTime?");
397                         AssertThrows<FormatException> (() => { DateTime? z = (DateTime?) new XAttribute (d); }, "d:DateTime?");
398                         AssertThrows<FormatException> (() => { DateTime? z = (DateTime?) new XAttribute (o); }, "o:DateTime?");
399                         AssertThrows<FormatException> (() => { DateTime? z = (DateTime?) new XAttribute (l); }, "l:DateTime?");
400                         AssertThrows<FormatException> (() => { DateTime? z = (DateTime?) new XAttribute (I); }, "I:DateTime?");
401                         AssertThrows<FormatException> (() => { DateTime? z = (DateTime?) new XAttribute (i); }, "i:DateTime?");
402                         AssertThrows<FormatException> (() => { DateTime? z = (DateTime?) new XAttribute (M); }, "M:DateTime?");
403                         AssertThrows<FormatException> (() => { DateTime? z = (DateTime?) new XAttribute (m); }, "m:DateTime?");
404                         AssertThrows<FormatException> (() => { DateTime? z = (DateTime?) new XAttribute (n); }, "n:DateTime?");
405                         AssertThrows<FormatException> (() => { DateTimeOffset? z = (DateTimeOffset?) new XAttribute (a); }, "a:DateTimeOffset?");
406                         AssertThrows<FormatException> (() => { DateTimeOffset? z = (DateTimeOffset?) new XAttribute (b); }, "b:DateTimeOffset?");
407                         AssertThrows<FormatException> (() => { DateTimeOffset? z = (DateTimeOffset?) new XAttribute (c); }, "c:DateTimeOffset?");
408                         AssertThrows<FormatException> (() => { DateTimeOffset? z = (DateTimeOffset?) new XAttribute (d); }, "d:DateTimeOffset?");
409                         AssertThrows<FormatException> (() => { DateTimeOffset? z = (DateTimeOffset?) new XAttribute (o); }, "o:DateTimeOffset?");
410                         AssertThrows<FormatException> (() => { DateTimeOffset? z = (DateTimeOffset?) new XAttribute (l); }, "l:DateTimeOffset?");
411                         AssertThrows<FormatException> (() => { DateTimeOffset? z = (DateTimeOffset?) new XAttribute (I); }, "I:DateTimeOffset?");
412                         AssertThrows<FormatException> (() => { DateTimeOffset? z = (DateTimeOffset?) new XAttribute (i); }, "i:DateTimeOffset?");
413                         AssertThrows<FormatException> (() => { DateTimeOffset? z = (DateTimeOffset?) new XAttribute (M); }, "M:DateTimeOffset?");
414                         AssertThrows<FormatException> (() => { DateTimeOffset? z = (DateTimeOffset?) new XAttribute (m); }, "m:DateTimeOffset?");
415                         AssertThrows<FormatException> (() => { DateTimeOffset? z = (DateTimeOffset?) new XAttribute (n); }, "n:DateTimeOffset?");
416                         Assert.IsNotNull ((decimal?) new XAttribute (a), "a:decimal?:null");
417                         Assert.AreEqual (7m, ((decimal?) new XAttribute (a)).Value, "a:decimal?:value");
418                         Assert.IsNotNull ((decimal?) new XAttribute (b), "b:decimal?:null");
419                         Assert.AreEqual (42m, ((decimal?) new XAttribute (b)).Value, "b:decimal?:value");
420                         Assert.IsNotNull ((decimal?) new XAttribute (c), "c:decimal?:null");
421                         Assert.AreEqual (123m, ((decimal?) new XAttribute (c)).Value, "c:decimal?:value");
422                         Assert.IsNotNull ((decimal?) new XAttribute (d), "d:decimal?:null");
423                         Assert.AreEqual (-101m, ((decimal?) new XAttribute (d)).Value, "d:decimal?:value");
424                         Assert.IsNotNull ((decimal?) new XAttribute (o), "o:decimal?:null");
425                         Assert.AreEqual (0m, ((decimal?) new XAttribute (o)).Value, "o:decimal?:value");
426                         Assert.IsNotNull ((decimal?) new XAttribute (l), "l:decimal?:null");
427                         Assert.AreEqual (1m, ((decimal?) new XAttribute (l)).Value, "l:decimal?:value");
428                         AssertThrows<FormatException> (() => { decimal? z = (decimal?) new XAttribute (I); }, "I:decimal?");
429                         AssertThrows<FormatException> (() => { decimal? z = (decimal?) new XAttribute (i); }, "i:decimal?");
430                         AssertThrows<FormatException> (() => { decimal? z = (decimal?) new XAttribute (M); }, "M:decimal?");
431                         AssertThrows<FormatException> (() => { decimal? z = (decimal?) new XAttribute (m); }, "m:decimal?");
432                         AssertThrows<FormatException> (() => { decimal? z = (decimal?) new XAttribute (n); }, "n:decimal?");
433                         Assert.IsNotNull ((double?) new XAttribute (a), "a:double?:null");
434                         Assert.AreEqual (7d, ((double?) new XAttribute (a)).Value, "a:double?:value");
435                         Assert.IsNotNull ((double?) new XAttribute (b), "b:double?:null");
436                         Assert.AreEqual (42d, ((double?) new XAttribute (b)).Value, "b:double?:value");
437                         Assert.IsNotNull ((double?) new XAttribute (c), "c:double?:null");
438                         Assert.AreEqual (123d, ((double?) new XAttribute (c)).Value, "c:double?:value");
439                         Assert.IsNotNull ((double?) new XAttribute (d), "d:double?:null");
440                         Assert.AreEqual (-101d, ((double?) new XAttribute (d)).Value, "d:double?:value");
441                         Assert.IsNotNull ((double?) new XAttribute (o), "o:double?:null");
442                         Assert.AreEqual (0d, ((double?) new XAttribute (o)).Value, "o:double?:value");
443                         Assert.IsNotNull ((double?) new XAttribute (l), "l:double?:null");
444                         Assert.AreEqual (1d, ((double?) new XAttribute (l)).Value, "l:double?:value");
445                         Assert.IsNotNull ((double?) new XAttribute (I), "I:double?:null");
446                         Assert.AreEqual (double.PositiveInfinity, ((double?) new XAttribute (I)).Value, "I:double?:value");
447                         Assert.IsNotNull ((double?) new XAttribute (i), "i:double?:null");
448                         Assert.AreEqual (double.PositiveInfinity, ((double?) new XAttribute (i)).Value, "i:double?:value");
449                         Assert.IsNotNull ((double?) new XAttribute (M), "M:double?:null");
450                         Assert.AreEqual (double.NegativeInfinity, ((double?) new XAttribute (M)).Value, "M:double?:value");
451                         Assert.IsNotNull ((double?) new XAttribute (m), "m:double?:null");
452                         Assert.AreEqual (double.NegativeInfinity, ((double?) new XAttribute (m)).Value, "m:double?:value");
453                         Assert.IsNotNull ((double?) new XAttribute (n), "n:double?:null");
454                         Assert.IsNaN (((double?) new XAttribute (n)).Value, "n:double?:value");
455                         Assert.IsNotNull ((float?) new XAttribute (a), "a:float?:null");
456                         Assert.AreEqual (7f, ((float?) new XAttribute (a)).Value, "a:float?:value");
457                         Assert.IsNotNull ((float?) new XAttribute (b), "b:float?:null");
458                         Assert.AreEqual (42f, ((float?) new XAttribute (b)).Value, "b:float?:value");
459                         Assert.IsNotNull ((float?) new XAttribute (c), "c:float?:null");
460                         Assert.AreEqual (123f, ((float?) new XAttribute (c)).Value, "c:float?:value");
461                         Assert.IsNotNull ((float?) new XAttribute (d), "d:float?:null");
462                         Assert.AreEqual (-101f, ((float?) new XAttribute (d)).Value, "d:float?:value");
463                         Assert.IsNotNull ((float?) new XAttribute (o), "o:float?:null");
464                         Assert.AreEqual (0f, ((float?) new XAttribute (o)).Value, "o:float?:value");
465                         Assert.IsNotNull ((float?) new XAttribute (l), "l:float?:null");
466                         Assert.AreEqual (1f, ((float?) new XAttribute (l)).Value, "l:float?:value");
467                         Assert.IsNotNull ((float?) new XAttribute (I), "I:float?:null");
468                         Assert.AreEqual (float.PositiveInfinity, ((float?) new XAttribute (I)).Value, "I:float?:value");
469                         Assert.IsNotNull ((float?) new XAttribute (i), "i:float?:null");
470                         Assert.AreEqual (float.PositiveInfinity, ((float?) new XAttribute (i)).Value, "i:float?:value");
471                         Assert.IsNotNull ((float?) new XAttribute (M), "M:float?:null");
472                         Assert.AreEqual (float.NegativeInfinity, ((float?) new XAttribute (M)).Value, "M:float?:value");
473                         Assert.IsNotNull ((float?) new XAttribute (m), "m:float?:null");
474                         Assert.AreEqual (float.NegativeInfinity, ((float?) new XAttribute (m)).Value, "m:float?:value");
475                         Assert.IsNotNull ((float?) new XAttribute (n), "n:float?:null");
476                         Assert.IsNaN (((float?) new XAttribute (n)).Value, "n:float?:value");
477                         AssertThrows<FormatException> (() => { Guid? z = (Guid?) new XAttribute (a); }, "a:Guid?");
478                         AssertThrows<FormatException> (() => { Guid? z = (Guid?) new XAttribute (b); }, "b:Guid?");
479                         AssertThrows<FormatException> (() => { Guid? z = (Guid?) new XAttribute (c); }, "c:Guid?");
480                         AssertThrows<FormatException> (() => { Guid? z = (Guid?) new XAttribute (d); }, "d:Guid?");
481                         AssertThrows<FormatException> (() => { Guid? z = (Guid?) new XAttribute (o); }, "o:Guid?");
482                         AssertThrows<FormatException> (() => { Guid? z = (Guid?) new XAttribute (l); }, "l:Guid?");
483                         AssertThrows<FormatException> (() => { Guid? z = (Guid?) new XAttribute (I); }, "I:Guid?");
484                         AssertThrows<FormatException> (() => { Guid? z = (Guid?) new XAttribute (i); }, "i:Guid?");
485                         AssertThrows<FormatException> (() => { Guid? z = (Guid?) new XAttribute (M); }, "M:Guid?");
486                         AssertThrows<FormatException> (() => { Guid? z = (Guid?) new XAttribute (m); }, "m:Guid?");
487                         AssertThrows<FormatException> (() => { Guid? z = (Guid?) new XAttribute (n); }, "n:Guid?");
488                         Assert.IsNotNull ((int?) new XAttribute (a), "a:int?:null");
489                         Assert.AreEqual (7, ((int?) new XAttribute (a)).Value, "a:int?:value");
490                         Assert.IsNotNull ((int?) new XAttribute (b), "b:int?:null");
491                         Assert.AreEqual (42, ((int?) new XAttribute (b)).Value, "b:int?:value");
492                         Assert.IsNotNull ((int?) new XAttribute (c), "c:int?:null");
493                         Assert.AreEqual (123, ((int?) new XAttribute (c)).Value, "c:int?:value");
494                         Assert.IsNotNull ((int?) new XAttribute (d), "d:int?:null");
495                         Assert.AreEqual (-101, ((int?) new XAttribute (d)).Value, "d:int?:value");
496                         Assert.IsNotNull ((int?) new XAttribute (o), "o:int?:null");
497                         Assert.AreEqual (0, ((int?) new XAttribute (o)).Value, "o:int?:value");
498                         Assert.IsNotNull ((int?) new XAttribute (l), "l:int?:null");
499                         Assert.AreEqual (1, ((int?) new XAttribute (l)).Value, "l:int?:value");
500                         AssertThrows<FormatException> (() => { int? z = (int?) new XAttribute (I); }, "I:int?");
501                         AssertThrows<FormatException> (() => { int? z = (int?) new XAttribute (i); }, "i:int?");
502                         AssertThrows<FormatException> (() => { int? z = (int?) new XAttribute (M); }, "M:int?");
503                         AssertThrows<FormatException> (() => { int? z = (int?) new XAttribute (m); }, "m:int?");
504                         AssertThrows<FormatException> (() => { int? z = (int?) new XAttribute (n); }, "n:int?");
505                         Assert.IsNotNull ((long?) new XAttribute (a), "a:long?:null");
506                         Assert.AreEqual (7L, ((long?) new XAttribute (a)).Value, "a:long?:value");
507                         Assert.IsNotNull ((long?) new XAttribute (b), "b:long?:null");
508                         Assert.AreEqual (42L, ((long?) new XAttribute (b)).Value, "b:long?:value");
509                         Assert.IsNotNull ((long?) new XAttribute (c), "c:long?:null");
510                         Assert.AreEqual (123L, ((long?) new XAttribute (c)).Value, "c:long?:value");
511                         Assert.IsNotNull ((long?) new XAttribute (d), "d:long?:null");
512                         Assert.AreEqual (-101L, ((long?) new XAttribute (d)).Value, "d:long?:value");
513                         Assert.IsNotNull ((long?) new XAttribute (o), "o:long?:null");
514                         Assert.AreEqual (0L, ((long?) new XAttribute (o)).Value, "o:long?:value");
515                         Assert.IsNotNull ((long?) new XAttribute (l), "l:long?:null");
516                         Assert.AreEqual (1L, ((long?) new XAttribute (l)).Value, "l:long?:value");
517                         AssertThrows<FormatException> (() => { long? z = (long?) new XAttribute (I); }, "I:long?");
518                         AssertThrows<FormatException> (() => { long? z = (long?) new XAttribute (i); }, "i:long?");
519                         AssertThrows<FormatException> (() => { long? z = (long?) new XAttribute (M); }, "M:long?");
520                         AssertThrows<FormatException> (() => { long? z = (long?) new XAttribute (m); }, "m:long?");
521                         AssertThrows<FormatException> (() => { long? z = (long?) new XAttribute (n); }, "n:long?");
522                         Assert.IsNotNull ((uint?) new XAttribute (a), "a:uint?:null");
523                         Assert.AreEqual (7u, ((uint?) new XAttribute (a)).Value, "a:uint?:value");
524                         Assert.IsNotNull ((uint?) new XAttribute (b), "b:uint?:null");
525                         Assert.AreEqual (42u, ((uint?) new XAttribute (b)).Value, "b:uint?:value");
526                         Assert.IsNotNull ((uint?) new XAttribute (c), "c:uint?:null");
527                         Assert.AreEqual (123u, ((uint?) new XAttribute (c)).Value, "c:uint?:value");
528                         // LAMESPEC: see XmlConvertTests.ToUInt32().
529                         //AssertThrows<FormatException> (() => { uint? z = (uint?) new XAttribute (d); }, "d:uint?");
530                         Assert.IsNotNull ((uint?) new XAttribute (o), "o:uint?:null");
531                         Assert.AreEqual (0u, ((uint?) new XAttribute (o)).Value, "o:uint?:value");
532                         Assert.IsNotNull ((uint?) new XAttribute (l), "l:uint?:null");
533                         Assert.AreEqual (1u, ((uint?) new XAttribute (l)).Value, "l:uint?:value");
534                         AssertThrows<FormatException> (() => { uint? z = (uint?) new XAttribute (I); }, "I:uint?");
535                         AssertThrows<FormatException> (() => { uint? z = (uint?) new XAttribute (i); }, "i:uint?");
536                         AssertThrows<FormatException> (() => { uint? z = (uint?) new XAttribute (M); }, "M:uint?");
537                         AssertThrows<FormatException> (() => { uint? z = (uint?) new XAttribute (m); }, "m:uint?");
538                         AssertThrows<FormatException> (() => { uint? z = (uint?) new XAttribute (n); }, "n:uint?");
539                         Assert.IsNotNull ((ulong?) new XAttribute (a), "a:ulong?:null");
540                         Assert.AreEqual (7UL, ((ulong?) new XAttribute (a)).Value, "a:ulong?:value");
541                         Assert.IsNotNull ((ulong?) new XAttribute (b), "b:ulong?:null");
542                         Assert.AreEqual (42UL, ((ulong?) new XAttribute (b)).Value, "b:ulong?:value");
543                         Assert.IsNotNull ((ulong?) new XAttribute (c), "c:ulong?:null");
544                         Assert.AreEqual (123UL, ((ulong?) new XAttribute (c)).Value, "c:ulong?:value");
545                         // LAMESPEC: see XmlConvertTests.ToUInt64().
546                         //AssertThrows<FormatException> (() => { ulong? z = (ulong?) new XAttribute (d); }, "d:ulong?");
547                         Assert.IsNotNull ((ulong?) new XAttribute (o), "o:ulong?:null");
548                         Assert.AreEqual (0UL, ((ulong?) new XAttribute (o)).Value, "o:ulong?:value");
549                         Assert.IsNotNull ((ulong?) new XAttribute (l), "l:ulong?:null");
550                         Assert.AreEqual (1UL, ((ulong?) new XAttribute (l)).Value, "l:ulong?:value");
551                         AssertThrows<FormatException> (() => { ulong? z = (ulong?) new XAttribute (I); }, "I:ulong?");
552                         AssertThrows<FormatException> (() => { ulong? z = (ulong?) new XAttribute (i); }, "i:ulong?");
553                         AssertThrows<FormatException> (() => { ulong? z = (ulong?) new XAttribute (M); }, "M:ulong?");
554                         AssertThrows<FormatException> (() => { ulong? z = (ulong?) new XAttribute (m); }, "m:ulong?");
555                         AssertThrows<FormatException> (() => { ulong? z = (ulong?) new XAttribute (n); }, "n:ulong?");
556                         AssertThrows<FormatException> (() => { TimeSpan? z = (TimeSpan?) new XAttribute (a); }, "a:TimeSpan?");
557                         AssertThrows<FormatException> (() => { TimeSpan? z = (TimeSpan?) new XAttribute (b); }, "b:TimeSpan?");
558                         AssertThrows<FormatException> (() => { TimeSpan? z = (TimeSpan?) new XAttribute (c); }, "c:TimeSpan?");
559                         AssertThrows<FormatException> (() => { TimeSpan? z = (TimeSpan?) new XAttribute (d); }, "d:TimeSpan?");
560                         AssertThrows<FormatException> (() => { TimeSpan? z = (TimeSpan?) new XAttribute (o); }, "o:TimeSpan?");
561                         AssertThrows<FormatException> (() => { TimeSpan? z = (TimeSpan?) new XAttribute (l); }, "l:TimeSpan?");
562                         AssertThrows<FormatException> (() => { TimeSpan? z = (TimeSpan?) new XAttribute (I); }, "I:TimeSpan?");
563                         AssertThrows<FormatException> (() => { TimeSpan? z = (TimeSpan?) new XAttribute (i); }, "i:TimeSpan?");
564                         AssertThrows<FormatException> (() => { TimeSpan? z = (TimeSpan?) new XAttribute (M); }, "M:TimeSpan?");
565                         AssertThrows<FormatException> (() => { TimeSpan? z = (TimeSpan?) new XAttribute (m); }, "m:TimeSpan?");
566                         AssertThrows<FormatException> (() => { TimeSpan? z = (TimeSpan?) new XAttribute (n); }, "n:TimeSpan?");
567                         Assert.AreEqual ("7", (string) new XAttribute (a), "a:string");
568                         Assert.AreEqual ("  42 ", (string) new XAttribute (b), "b:string");
569                         Assert.AreEqual (" \n\r   123 \t  ", (string) new XAttribute (c), "c:string");
570                         Assert.AreEqual ("-101", (string) new XAttribute (d), "d:string");
571                         Assert.AreEqual ("0", (string) new XAttribute (o), "o:string");
572                         Assert.AreEqual ("1", (string) new XAttribute (l), "l:string");
573                         Assert.AreEqual ("\t    INF    ", (string) new XAttribute (I), "I:string");
574                         Assert.AreEqual ("Infinity", (string) new XAttribute (i), "i:string");
575                         Assert.AreEqual ("-INF", (string) new XAttribute (M), "M:string");
576                         Assert.AreEqual (" -Infinity  ", (string) new XAttribute (m), "m:string");
577                         Assert.AreEqual ("NaN", (string) new XAttribute (n), "n:string");
578                         AssertThrows<FormatException> (() => { bool z = (bool) new XAttribute (a); }, "a:bool");
579                         AssertThrows<FormatException> (() => { bool z = (bool) new XAttribute (b); }, "b:bool");
580                         AssertThrows<FormatException> (() => { bool z = (bool) new XAttribute (c); }, "c:bool");
581                         AssertThrows<FormatException> (() => { bool z = (bool) new XAttribute (d); }, "d:bool");
582                         Assert.AreEqual (false, (bool) new XAttribute (o), "o:bool");
583                         Assert.AreEqual (true, (bool) new XAttribute (l), "l:bool");
584                         AssertThrows<FormatException> (() => { bool z = (bool) new XAttribute (I); }, "I:bool");
585                         AssertThrows<FormatException> (() => { bool z = (bool) new XAttribute (i); }, "i:bool");
586                         AssertThrows<FormatException> (() => { bool z = (bool) new XAttribute (M); }, "M:bool");
587                         AssertThrows<FormatException> (() => { bool z = (bool) new XAttribute (m); }, "m:bool");
588                         AssertThrows<FormatException> (() => { bool z = (bool) new XAttribute (n); }, "n:bool");
589                         AssertThrows<FormatException> (() => { DateTime z = (DateTime) new XAttribute (a); }, "a:DateTime");
590                         AssertThrows<FormatException> (() => { DateTime z = (DateTime) new XAttribute (b); }, "b:DateTime");
591                         AssertThrows<FormatException> (() => { DateTime z = (DateTime) new XAttribute (c); }, "c:DateTime");
592                         AssertThrows<FormatException> (() => { DateTime z = (DateTime) new XAttribute (d); }, "d:DateTime");
593                         AssertThrows<FormatException> (() => { DateTime z = (DateTime) new XAttribute (o); }, "o:DateTime");
594                         AssertThrows<FormatException> (() => { DateTime z = (DateTime) new XAttribute (l); }, "l:DateTime");
595                         AssertThrows<FormatException> (() => { DateTime z = (DateTime) new XAttribute (I); }, "I:DateTime");
596                         AssertThrows<FormatException> (() => { DateTime z = (DateTime) new XAttribute (i); }, "i:DateTime");
597                         AssertThrows<FormatException> (() => { DateTime z = (DateTime) new XAttribute (M); }, "M:DateTime");
598                         AssertThrows<FormatException> (() => { DateTime z = (DateTime) new XAttribute (m); }, "m:DateTime");
599                         AssertThrows<FormatException> (() => { DateTime z = (DateTime) new XAttribute (n); }, "n:DateTime");
600                         AssertThrows<FormatException> (() => { DateTimeOffset z = (DateTimeOffset) new XAttribute (a); }, "a:DateTimeOffset");
601                         AssertThrows<FormatException> (() => { DateTimeOffset z = (DateTimeOffset) new XAttribute (b); }, "b:DateTimeOffset");
602                         AssertThrows<FormatException> (() => { DateTimeOffset z = (DateTimeOffset) new XAttribute (c); }, "c:DateTimeOffset");
603                         AssertThrows<FormatException> (() => { DateTimeOffset z = (DateTimeOffset) new XAttribute (d); }, "d:DateTimeOffset");
604                         AssertThrows<FormatException> (() => { DateTimeOffset z = (DateTimeOffset) new XAttribute (o); }, "o:DateTimeOffset");
605                         AssertThrows<FormatException> (() => { DateTimeOffset z = (DateTimeOffset) new XAttribute (l); }, "l:DateTimeOffset");
606                         AssertThrows<FormatException> (() => { DateTimeOffset z = (DateTimeOffset) new XAttribute (I); }, "I:DateTimeOffset");
607                         AssertThrows<FormatException> (() => { DateTimeOffset z = (DateTimeOffset) new XAttribute (i); }, "i:DateTimeOffset");
608                         AssertThrows<FormatException> (() => { DateTimeOffset z = (DateTimeOffset) new XAttribute (M); }, "M:DateTimeOffset");
609                         AssertThrows<FormatException> (() => { DateTimeOffset z = (DateTimeOffset) new XAttribute (m); }, "m:DateTimeOffset");
610                         AssertThrows<FormatException> (() => { DateTimeOffset z = (DateTimeOffset) new XAttribute (n); }, "n:DateTimeOffset");
611                         Assert.AreEqual (7m, (decimal) new XAttribute (a), "a:decimal");
612                         Assert.AreEqual (42m, (decimal) new XAttribute (b), "b:decimal");
613                         Assert.AreEqual (123m, (decimal) new XAttribute (c), "c:decimal");
614                         Assert.AreEqual (-101m, (decimal) new XAttribute (d), "d:decimal");
615                         Assert.AreEqual (0m, (decimal) new XAttribute (o), "o:decimal");
616                         Assert.AreEqual (1m, (decimal) new XAttribute (l), "l:decimal");
617                         AssertThrows<FormatException> (() => { decimal z = (decimal) new XAttribute (I); }, "I:decimal");
618                         AssertThrows<FormatException> (() => { decimal z = (decimal) new XAttribute (i); }, "i:decimal");
619                         AssertThrows<FormatException> (() => { decimal z = (decimal) new XAttribute (M); }, "M:decimal");
620                         AssertThrows<FormatException> (() => { decimal z = (decimal) new XAttribute (m); }, "m:decimal");
621                         AssertThrows<FormatException> (() => { decimal z = (decimal) new XAttribute (n); }, "n:decimal");
622                         Assert.AreEqual (7d, (double) new XAttribute (a), "a:double");
623                         Assert.AreEqual (42d, (double) new XAttribute (b), "b:double");
624                         Assert.AreEqual (123d, (double) new XAttribute (c), "c:double");
625                         Assert.AreEqual (-101d, (double) new XAttribute (d), "d:double");
626                         Assert.AreEqual (0d, (double) new XAttribute (o), "o:double");
627                         Assert.AreEqual (1d, (double) new XAttribute (l), "l:double");
628                         Assert.AreEqual (double.PositiveInfinity, (double) new XAttribute (I), "I:double");
629                         Assert.AreEqual (double.PositiveInfinity, (double) new XAttribute (i), "i:double");
630                         Assert.AreEqual (double.NegativeInfinity, (double) new XAttribute (M), "M:double");
631                         Assert.AreEqual (double.NegativeInfinity, (double) new XAttribute (m), "m:double");
632                         Assert.IsNaN (((double) new XAttribute (n)), "n:double");
633                         Assert.AreEqual (7f, (float) new XAttribute (a), "a:float");
634                         Assert.AreEqual (42f, (float) new XAttribute (b), "b:float");
635                         Assert.AreEqual (123f, (float) new XAttribute (c), "c:float");
636                         Assert.AreEqual (-101f, (float) new XAttribute (d), "d:float");
637                         Assert.AreEqual (0f, (float) new XAttribute (o), "o:float");
638                         Assert.AreEqual (1f, (float) new XAttribute (l), "l:float");
639                         Assert.AreEqual (float.PositiveInfinity, (float) new XAttribute (I), "I:float");
640                         Assert.AreEqual (float.PositiveInfinity, (float) new XAttribute (i), "i:float");
641                         Assert.AreEqual (float.NegativeInfinity, (float) new XAttribute (M), "M:float");
642                         Assert.AreEqual (float.NegativeInfinity, (float) new XAttribute (m), "m:float");
643                         Assert.IsNaN (((float) new XAttribute (n)), "n:float");
644                         AssertThrows<FormatException> (() => { Guid z = (Guid) new XAttribute (a); }, "a:Guid");
645                         AssertThrows<FormatException> (() => { Guid z = (Guid) new XAttribute (b); }, "b:Guid");
646                         AssertThrows<FormatException> (() => { Guid z = (Guid) new XAttribute (c); }, "c:Guid");
647                         AssertThrows<FormatException> (() => { Guid z = (Guid) new XAttribute (d); }, "d:Guid");
648                         AssertThrows<FormatException> (() => { Guid z = (Guid) new XAttribute (o); }, "o:Guid");
649                         AssertThrows<FormatException> (() => { Guid z = (Guid) new XAttribute (l); }, "l:Guid");
650                         AssertThrows<FormatException> (() => { Guid z = (Guid) new XAttribute (I); }, "I:Guid");
651                         AssertThrows<FormatException> (() => { Guid z = (Guid) new XAttribute (i); }, "i:Guid");
652                         AssertThrows<FormatException> (() => { Guid z = (Guid) new XAttribute (M); }, "M:Guid");
653                         AssertThrows<FormatException> (() => { Guid z = (Guid) new XAttribute (m); }, "m:Guid");
654                         AssertThrows<FormatException> (() => { Guid z = (Guid) new XAttribute (n); }, "n:Guid");
655                         Assert.AreEqual (7, (int) new XAttribute (a), "a:int");
656                         Assert.AreEqual (42, (int) new XAttribute (b), "b:int");
657                         Assert.AreEqual (123, (int) new XAttribute (c), "c:int");
658                         Assert.AreEqual (-101, (int) new XAttribute (d), "d:int");
659                         Assert.AreEqual (0, (int) new XAttribute (o), "o:int");
660                         Assert.AreEqual (1, (int) new XAttribute (l), "l:int");
661                         AssertThrows<FormatException> (() => { int z = (int) new XAttribute (I); }, "I:int");
662                         AssertThrows<FormatException> (() => { int z = (int) new XAttribute (i); }, "i:int");
663                         AssertThrows<FormatException> (() => { int z = (int) new XAttribute (M); }, "M:int");
664                         AssertThrows<FormatException> (() => { int z = (int) new XAttribute (m); }, "m:int");
665                         AssertThrows<FormatException> (() => { int z = (int) new XAttribute (n); }, "n:int");
666                         Assert.AreEqual (7L, (long) new XAttribute (a), "a:long");
667                         Assert.AreEqual (42L, (long) new XAttribute (b), "b:long");
668                         Assert.AreEqual (123L, (long) new XAttribute (c), "c:long");
669                         Assert.AreEqual (-101L, (long) new XAttribute (d), "d:long");
670                         Assert.AreEqual (0L, (long) new XAttribute (o), "o:long");
671                         Assert.AreEqual (1L, (long) new XAttribute (l), "l:long");
672                         AssertThrows<FormatException> (() => { long z = (long) new XAttribute (I); }, "I:long");
673                         AssertThrows<FormatException> (() => { long z = (long) new XAttribute (i); }, "i:long");
674                         AssertThrows<FormatException> (() => { long z = (long) new XAttribute (M); }, "M:long");
675                         AssertThrows<FormatException> (() => { long z = (long) new XAttribute (m); }, "m:long");
676                         AssertThrows<FormatException> (() => { long z = (long) new XAttribute (n); }, "n:long");
677                         Assert.AreEqual (7u, (uint) new XAttribute (a), "a:uint");
678                         Assert.AreEqual (42u, (uint) new XAttribute (b), "b:uint");
679                         Assert.AreEqual (123u, (uint) new XAttribute (c), "c:uint");
680                         // LAMESPEC: see XmlConvertTests.ToUInt32().
681                         //AssertThrows<FormatException> (() => { uint z = (uint) new XAttribute (d); }, "d:uint");
682                         Assert.AreEqual (0u, (uint) new XAttribute (o), "o:uint");
683                         Assert.AreEqual (1u, (uint) new XAttribute (l), "l:uint");
684                         AssertThrows<FormatException> (() => { uint z = (uint) new XAttribute (I); }, "I:uint");
685                         AssertThrows<FormatException> (() => { uint z = (uint) new XAttribute (i); }, "i:uint");
686                         AssertThrows<FormatException> (() => { uint z = (uint) new XAttribute (M); }, "M:uint");
687                         AssertThrows<FormatException> (() => { uint z = (uint) new XAttribute (m); }, "m:uint");
688                         AssertThrows<FormatException> (() => { uint z = (uint) new XAttribute (n); }, "n:uint");
689                         Assert.AreEqual (7UL, (ulong) new XAttribute (a), "a:ulong");
690                         Assert.AreEqual (42UL, (ulong) new XAttribute (b), "b:ulong");
691                         Assert.AreEqual (123UL, (ulong) new XAttribute (c), "c:ulong");
692                         // LAMESPEC: see XmlConvertTests.ToUInt64().
693                         //AssertThrows<FormatException> (() => { ulong z = (ulong) new XAttribute (d); }, "d:ulong");
694                         Assert.AreEqual (0UL, (ulong) new XAttribute (o), "o:ulong");
695                         Assert.AreEqual (1UL, (ulong) new XAttribute (l), "l:ulong");
696                         AssertThrows<FormatException> (() => { ulong z = (ulong) new XAttribute (I); }, "I:ulong");
697                         AssertThrows<FormatException> (() => { ulong z = (ulong) new XAttribute (i); }, "i:ulong");
698                         AssertThrows<FormatException> (() => { ulong z = (ulong) new XAttribute (M); }, "M:ulong");
699                         AssertThrows<FormatException> (() => { ulong z = (ulong) new XAttribute (m); }, "m:ulong");
700                         AssertThrows<FormatException> (() => { ulong z = (ulong) new XAttribute (n); }, "n:ulong");
701                         AssertThrows<FormatException> (() => { TimeSpan z = (TimeSpan) new XAttribute (a); }, "a:TimeSpan");
702                         AssertThrows<FormatException> (() => { TimeSpan z = (TimeSpan) new XAttribute (b); }, "b:TimeSpan");
703                         AssertThrows<FormatException> (() => { TimeSpan z = (TimeSpan) new XAttribute (c); }, "c:TimeSpan");
704                         AssertThrows<FormatException> (() => { TimeSpan z = (TimeSpan) new XAttribute (d); }, "d:TimeSpan");
705                         AssertThrows<FormatException> (() => { TimeSpan z = (TimeSpan) new XAttribute (o); }, "o:TimeSpan");
706                         AssertThrows<FormatException> (() => { TimeSpan z = (TimeSpan) new XAttribute (l); }, "l:TimeSpan");
707                         AssertThrows<FormatException> (() => { TimeSpan z = (TimeSpan) new XAttribute (I); }, "I:TimeSpan");
708                         AssertThrows<FormatException> (() => { TimeSpan z = (TimeSpan) new XAttribute (i); }, "i:TimeSpan");
709                         AssertThrows<FormatException> (() => { TimeSpan z = (TimeSpan) new XAttribute (M); }, "M:TimeSpan");
710                         AssertThrows<FormatException> (() => { TimeSpan z = (TimeSpan) new XAttribute (m); }, "m:TimeSpan");
711                         AssertThrows<FormatException> (() => { TimeSpan z = (TimeSpan) new XAttribute (n); }, "n:TimeSpan");
712
713                         // Perform some round-trip tests with numbers
714                         XAttribute x;
715                         const decimal @decimal = -41051609414188012238960097189m;
716                         const double @double = 8.5506609919892972E+307d;
717                         const float @float = -1.70151961E+37f;
718                         const int @int = -1051251773;
719                         const long @long = 4596767133891939716L;
720                         const uint @uint = 4106628142u;
721                         const ulong @ulong = 10713797297298255927UL;
722                         x = new XAttribute ("x", @decimal);
723                         Assert.IsNotNull ((decimal?) new XAttribute (x), "x:decimal?:null");
724                         Assert.AreEqual (@decimal, ((decimal?) new XAttribute (x)).Value, "x:decimal?:value");
725                         Assert.AreEqual (@decimal, (decimal) new XAttribute (x), "x:decimal");
726                         x = new XAttribute ("x", @double);
727                         Assert.IsNotNull ((double?) new XAttribute (x), "x:double?:null");
728                         Assert.AreEqual (@double, ((double?) new XAttribute (x)).Value, "x:double?:value");
729                         Assert.AreEqual (@double, (double) new XAttribute (x), "x:double");
730                         x = new XAttribute ("x", @float);
731                         Assert.IsNotNull ((float?) new XAttribute (x), "x:float?:null");
732                         Assert.AreEqual (@float, ((float?) new XAttribute (x)).Value, "x:float?:value");
733                         Assert.AreEqual (@float, (float) new XAttribute (x), "x:float");
734                         x = new XAttribute ("x", @int);
735                         Assert.IsNotNull ((int?) new XAttribute (x), "x:int?:null");
736                         Assert.AreEqual (@int, ((int?) new XAttribute (x)).Value, "x:int?:value");
737                         Assert.AreEqual (@int, (int) new XAttribute (x), "x:int");
738                         x = new XAttribute ("x", @long);
739                         Assert.IsNotNull ((long?) new XAttribute (x), "x:long?:null");
740                         Assert.AreEqual (@long, ((long?) new XAttribute (x)).Value, "x:long?:value");
741                         Assert.AreEqual (@long, (long) new XAttribute (x), "x:long");
742                         x = new XAttribute ("x", @uint);
743                         Assert.IsNotNull ((uint?) new XAttribute (x), "x:uint?:null");
744                         Assert.AreEqual (@uint, ((uint?) new XAttribute (x)).Value, "x:uint?:value");
745                         Assert.AreEqual (@uint, (uint) new XAttribute (x), "x:uint");
746                         x = new XAttribute ("x", @ulong);
747                         Assert.IsNotNull ((ulong?) new XAttribute (x), "x:ulong?:null");
748                         Assert.AreEqual (@ulong, ((ulong?) new XAttribute (x)).Value, "x:ulong?:value");
749                         Assert.AreEqual (@ulong, (ulong) new XAttribute (x), "x:ulong");
750                         x = new XAttribute ("x", double.NaN);
751                         Assert.IsNotNull ((double?) new XAttribute (x), "NaN:double?:null");
752                         Assert.AreEqual (double.NaN, ((double?) new XAttribute (x)).Value, "NaN:double?:value");
753                         Assert.AreEqual (double.NaN, (double) new XAttribute (x), "NaN:double");
754                         x = new XAttribute ("x", float.NaN);
755                         Assert.IsNotNull ((float?) new XAttribute (x), "NaN:float?:null");
756                         Assert.AreEqual (float.NaN, ((float?) new XAttribute (x)).Value, "NaN:float?:value");
757                         Assert.AreEqual (float.NaN, (float) new XAttribute (x), "NaN:float");
758                         x = new XAttribute ("x", double.PositiveInfinity);
759                         Assert.IsNotNull ((double?) new XAttribute (x), "+Inf:double?:null");
760                         Assert.AreEqual (double.PositiveInfinity, ((double?) new XAttribute (x)).Value, "+Inf:double?:value");
761                         Assert.AreEqual (double.PositiveInfinity, (double) new XAttribute (x), "+Inf:double");
762                         x = new XAttribute ("x", float.PositiveInfinity);
763                         Assert.IsNotNull ((float?) new XAttribute (x), "+Inf:float?:null");
764                         Assert.AreEqual (float.PositiveInfinity, ((float?) new XAttribute (x)).Value, "+Inf:float?:value");
765                         Assert.AreEqual (float.PositiveInfinity, (float) new XAttribute (x), "+Inf:float");
766                         x = new XAttribute ("x", double.NegativeInfinity);
767                         Assert.IsNotNull ((double?) new XAttribute (x), "-Inf:double?:null");
768                         Assert.AreEqual (double.NegativeInfinity, ((double?) new XAttribute (x)).Value, "-Inf:double?:value");
769                         Assert.AreEqual (double.NegativeInfinity, (double) new XAttribute (x), "-Inf:double");
770                         x = new XAttribute ("x", float.NegativeInfinity);
771                         Assert.IsNotNull ((float?) new XAttribute (x), "-Inf:float?:null");
772                         Assert.AreEqual (float.NegativeInfinity, ((float?) new XAttribute (x)).Value, "-Inf:float?:value");
773                         Assert.AreEqual (float.NegativeInfinity, (float) new XAttribute (x), "-Inf:float");
774
775                         // Perform overflow tests with numbers
776                         AssertThrows<OverflowException> (() => { decimal z = (decimal) new XAttribute ("z", "91051609414188012238960097189"); }, "z:decimal");
777                         AssertThrows<OverflowException> (() => { decimal? z = (decimal?) new XAttribute ("z", "91051609414188012238960097189"); }, "z:decimal?");
778                         AssertThrows<OverflowException> (() => { double z = (double) new XAttribute ("z", "8.5506609919892972E+654"); }, "z:double");
779                         AssertThrows<OverflowException> (() => { double? z = (double?) new XAttribute ("z", "8.5506609919892972E+654"); }, "z:double?");
780                         AssertThrows<OverflowException> (() => { float z = (float) new XAttribute ("z", @double); }, "z:float");
781                         AssertThrows<OverflowException> (() => { float? z = (float?) new XAttribute ("z", @double); }, "z:float?");
782                         AssertThrows<OverflowException> (() => { int z = (int) new XAttribute ("z", @long); }, "z:int");
783                         AssertThrows<OverflowException> (() => { int? z = (int?) new XAttribute ("z", @long); }, "z:int?");
784                         AssertThrows<OverflowException> (() => { long z = (long) new XAttribute ("z", @decimal); }, "z:long");
785                         AssertThrows<OverflowException> (() => { long? z = (long?) new XAttribute ("z", @decimal); }, "z:long?");
786                         AssertThrows<OverflowException> (() => { uint z = (uint) new XAttribute ("z", @ulong); }, "z:uint");
787                         AssertThrows<OverflowException> (() => { uint? z = (uint?) new XAttribute ("z", @ulong); }, "z:uint?");
788                         AssertThrows<OverflowException> (() => { ulong z = (ulong) new XAttribute ("z", -@decimal); }, "z:ulong");
789                         AssertThrows<OverflowException> (() => { ulong? z = (ulong?) new XAttribute ("z", -@decimal); }, "z:ulong?");
790                 }
791
792                 [Test]
793                 public void CastExtremes ()
794                 {
795                         // Test extremes/constants where round-trips should work in specific ways
796                         Assert.AreEqual (decimal.MaxValue, (decimal) new XAttribute ("k", decimal.MaxValue), "MaxValue:decimal");
797                         Assert.AreEqual (decimal.MinValue, (decimal) new XAttribute ("k", decimal.MinValue), "MinValue:decimal");
798                         Assert.AreEqual (decimal.MinusOne, (decimal) new XAttribute ("k", decimal.MinusOne), "MinusOne:decimal");
799                         Assert.AreEqual (decimal.One, (decimal) new XAttribute ("k", decimal.One), "One:decimal");
800                         Assert.AreEqual (decimal.Zero, (decimal) new XAttribute ("k", decimal.Zero), "Zero:decimal");
801                         Assert.AreEqual (double.MaxValue, (double) new XAttribute ("k", double.MaxValue), "MaxValue:double");
802                         Assert.AreEqual (double.MinValue, (double) new XAttribute ("k", double.MinValue), "MinValue:double");
803                         Assert.AreEqual (double.Epsilon, (double) new XAttribute ("k", double.Epsilon), "Epsilon:double");
804                         Assert.AreEqual (double.NaN, (double) new XAttribute ("k", double.NaN), "NaN:double");
805                         Assert.AreEqual (double.NegativeInfinity, (double) new XAttribute ("k", double.NegativeInfinity), "-Inf:double");
806                         Assert.AreEqual (double.PositiveInfinity, (double) new XAttribute ("k", double.PositiveInfinity), "+Inf:double");
807                         Assert.AreEqual (float.MaxValue, (float) new XAttribute ("k", float.MaxValue), "MaxValue:float");
808                         Assert.AreEqual (float.MinValue, (float) new XAttribute ("k", float.MinValue), "MinValue:float");
809                         Assert.AreEqual (float.Epsilon, (float) new XAttribute ("k", float.Epsilon), "Epsilon:float");
810                         Assert.AreEqual (float.NaN, (float) new XAttribute ("k", float.NaN), "NaN:float");
811                         Assert.AreEqual (float.NegativeInfinity, (float) new XAttribute ("k", float.NegativeInfinity), "-Inf:float");
812                         Assert.AreEqual (float.PositiveInfinity, (float) new XAttribute ("k", float.PositiveInfinity), "+Inf:float");
813                         Assert.AreEqual (int.MaxValue, (int) new XAttribute ("k", int.MaxValue), "MaxValue:int");
814                         Assert.AreEqual (int.MinValue, (int) new XAttribute ("k", int.MinValue), "MinValue:int");
815                         Assert.AreEqual (long.MaxValue, (long) new XAttribute ("k", long.MaxValue), "MaxValue:long");
816                         Assert.AreEqual (long.MinValue, (long) new XAttribute ("k", long.MinValue), "MinValue:long");
817                         Assert.AreEqual (uint.MaxValue, (uint) new XAttribute ("k", uint.MaxValue), "MaxValue:uint");
818                         Assert.AreEqual (uint.MinValue, (uint) new XAttribute ("k", uint.MinValue), "MinValue:uint");
819                         Assert.AreEqual (ulong.MaxValue, (ulong) new XAttribute ("k", ulong.MaxValue), "MaxValue:ulong");
820                         Assert.AreEqual (ulong.MinValue, (ulong) new XAttribute ("k", ulong.MinValue), "MinValue:ulong");
821                         Assert.AreEqual (decimal.MaxValue, (decimal?) new XAttribute ("k", decimal.MaxValue), "MaxValue:decimal?");
822                         Assert.AreEqual (decimal.MinValue, (decimal?) new XAttribute ("k", decimal.MinValue), "MinValue:decimal?");
823                         Assert.AreEqual (decimal.MinusOne, (decimal?) new XAttribute ("k", decimal.MinusOne), "MinusOne:decimal?");
824                         Assert.AreEqual (decimal.One, (decimal?) new XAttribute ("k", decimal.One), "One:decimal?");
825                         Assert.AreEqual (decimal.Zero, (decimal?) new XAttribute ("k", decimal.Zero), "Zero:decimal?");
826                         Assert.AreEqual (double.MaxValue, (double?) new XAttribute ("k", double.MaxValue), "MaxValue:double?");
827                         Assert.AreEqual (double.MinValue, (double?) new XAttribute ("k", double.MinValue), "MinValue:double?");
828                         Assert.AreEqual (double.Epsilon, (double?) new XAttribute ("k", double.Epsilon), "Epsilon:double?");
829                         Assert.AreEqual (double.NaN, (double?) new XAttribute ("k", double.NaN), "NaN:double?");
830                         Assert.AreEqual (double.NegativeInfinity, (double?) new XAttribute ("k", double.NegativeInfinity), "-Inf:double?");
831                         Assert.AreEqual (double.PositiveInfinity, (double?) new XAttribute ("k", double.PositiveInfinity), "+Inf:double?");
832                         Assert.AreEqual (float.MaxValue, (float?) new XAttribute ("k", float.MaxValue), "MaxValue:float?");
833                         Assert.AreEqual (float.MinValue, (float?) new XAttribute ("k", float.MinValue), "MinValue:float?");
834                         Assert.AreEqual (float.Epsilon, (float?) new XAttribute ("k", float.Epsilon), "Epsilon:float?");
835                         Assert.AreEqual (float.NaN, (float?) new XAttribute ("k", float.NaN), "NaN:float?");
836                         Assert.AreEqual (float.NegativeInfinity, (float?) new XAttribute ("k", float.NegativeInfinity), "-Inf:float?");
837                         Assert.AreEqual (float.PositiveInfinity, (float?) new XAttribute ("k", float.PositiveInfinity), "+Inf:float?");
838                         Assert.AreEqual (int.MaxValue, (int?) new XAttribute ("k", int.MaxValue), "MaxValue:int?");
839                         Assert.AreEqual (int.MinValue, (int?) new XAttribute ("k", int.MinValue), "MinValue:int?");
840                         Assert.AreEqual (long.MaxValue, (long?) new XAttribute ("k", long.MaxValue), "MaxValue:long?");
841                         Assert.AreEqual (long.MinValue, (long?) new XAttribute ("k", long.MinValue), "MinValue:long?");
842                         Assert.AreEqual (uint.MaxValue, (uint?) new XAttribute ("k", uint.MaxValue), "MaxValue:uint?");
843                         Assert.AreEqual (uint.MinValue, (uint?) new XAttribute ("k", uint.MinValue), "MinValue:uint?");
844                         Assert.AreEqual (ulong.MaxValue, (ulong?) new XAttribute ("k", ulong.MaxValue), "MaxValue:ulong?");
845                         Assert.AreEqual (ulong.MinValue, (ulong?) new XAttribute ("k", ulong.MinValue), "MinValue:ulong?");
846                         Assert.AreEqual (DateTime.MaxValue, (DateTime) new XAttribute ("k", DateTime.MaxValue), "MaxValue:DateTime");
847                         Assert.AreEqual (DateTime.MinValue, (DateTime) new XAttribute ("k", DateTime.MinValue), "MinValue:DateTime");
848                         Assert.AreEqual (DateTime.MaxValue, (DateTime?) new XAttribute ("k", DateTime.MaxValue), "MaxValue:DateTime?");
849                         Assert.AreEqual (DateTime.MinValue, (DateTime?) new XAttribute ("k", DateTime.MinValue), "MinValue:DateTime?");
850                         Assert.AreEqual (DateTimeOffset.MaxValue, (DateTimeOffset) new XAttribute ("k", DateTimeOffset.MaxValue), "MaxValue:DateTimeOffset");
851                         Assert.AreEqual (DateTimeOffset.MinValue, (DateTimeOffset) new XAttribute ("k", DateTimeOffset.MinValue), "MinValue:DateTimeOffset");
852                         Assert.AreEqual (DateTimeOffset.MaxValue, (DateTimeOffset?) new XAttribute ("k", DateTimeOffset.MaxValue), "MaxValue:DateTimeOffset?");
853                         Assert.AreEqual (DateTimeOffset.MinValue, (DateTimeOffset?) new XAttribute ("k", DateTimeOffset.MinValue), "MinValue:DateTimeOffset?");
854                         Assert.AreEqual (TimeSpan.MaxValue, (TimeSpan) new XAttribute ("k", TimeSpan.MaxValue), "MaxValue:TimeSpan");
855                         Assert.AreEqual (TimeSpan.MinValue, (TimeSpan) new XAttribute ("k", TimeSpan.MinValue), "MinValue:TimeSpan");
856                         Assert.AreEqual (TimeSpan.MaxValue, (TimeSpan?) new XAttribute ("k", TimeSpan.MaxValue), "MaxValue:TimeSpan?");
857                         Assert.AreEqual (TimeSpan.MinValue, (TimeSpan?) new XAttribute ("k", TimeSpan.MinValue), "MinValue:TimeSpan?");
858                 }
859
860                 [Test]
861                 public void CastBooleans ()
862                 {
863                         Assert.IsNotNull ((bool?) new XAttribute ("fq", "false"), "#1a");
864                         Assert.AreEqual (false, ((bool?) new XAttribute ("fq", "false")).Value, "#1b");
865                         Assert.IsNotNull ((bool?) new XAttribute ("tq", "true"), "#2a");
866                         Assert.AreEqual (true, ((bool?) new XAttribute ("tq", "true")).Value, "#2b");
867                         Assert.IsNotNull ((bool?) new XAttribute ("Fq", "False"), "#3a");
868                         Assert.AreEqual (false, ((bool?) new XAttribute ("Fq", "False")).Value, "#3b");
869                         Assert.IsNotNull ((bool?) new XAttribute ("Tq", "True"), "#4a");
870                         Assert.AreEqual (true, ((bool?) new XAttribute ("Tq", "True")).Value, "#4b");
871                         Assert.IsNotNull ((bool?) new XAttribute ("Fs", "   False \t \r "), "#5a");
872                         Assert.AreEqual (false, ((bool?) new XAttribute ("Fs", "   False \t \r ")).Value, "#5b");
873                         Assert.IsNotNull ((bool?) new XAttribute ("Ts", " \t True  \n  "), "#6a");
874                         Assert.AreEqual (true, ((bool?) new XAttribute ("Ts", " \t True  \n  ")).Value, "#6b");
875                         Assert.AreEqual (false, (bool) new XAttribute ("f", "false"), "#7");
876                         Assert.AreEqual (true, (bool) new XAttribute ("t", "true"), "#8");
877                         Assert.AreEqual (false, (bool) new XAttribute ("F", "False"), "#9");
878                         Assert.AreEqual (true, (bool) new XAttribute ("T", "True"), "#10");
879                         Assert.AreEqual (false, (bool)new XAttribute ("fs", " false  "), "#11");
880                         Assert.AreEqual (true, (bool)new XAttribute ("ts", "  true "), "#12");
881                         Assert.IsNotNull ((bool?) new XAttribute ("x", true), "#13a");
882                         Assert.IsTrue (((bool?) new XAttribute ("x", true)).Value, "#13b");
883                         Assert.IsTrue ((bool) new XAttribute ("x", true), "#13c");
884                         Assert.IsNotNull ((bool?) new XAttribute ("x", false), "#14a");
885                         Assert.IsFalse (((bool?) new XAttribute ("x", false)).Value, "#14b");
886                         Assert.IsFalse ((bool) new XAttribute ("x", false), "#14c");
887                         Assert.IsTrue ((bool) new XAttribute ("x", bool.TrueString), "#15a");
888                         Assert.IsFalse ((bool) new XAttribute ("x", bool.FalseString), "#15b");
889                 }
890
891                 [Test]
892                 public void CastGuids ()
893                 {
894                         Guid rb = new Guid (new byte[16] { 0x9A, 0xBF, 0xCE, 0x7E, 0x07, 0x29, 0x9C, 0x43, 0x80, 0x7D, 0x48, 0x20, 0xB9, 0x19, 0xEA, 0x57 });
895                         Guid rd = new Guid (new byte[16] { 0x21, 0x5B, 0x57, 0x26, 0xCD, 0x14, 0x5E, 0x44, 0x8F, 0xFA, 0xE2, 0xBC, 0x24, 0x7B, 0x2E, 0xC9 });
896                         Guid rn = new Guid (new byte[16] { 0xF9, 0x46, 0x41, 0xA8, 0xA5, 0x03, 0xF1, 0x4A, 0xAD, 0x97, 0x7B, 0xC7, 0x79, 0x57, 0x2B, 0x79 });
897                         Guid rp = new Guid (new byte[16] { 0x51, 0x6B, 0x8A, 0x17, 0xEF, 0x11, 0xFB, 0x48, 0x83, 0xBD, 0x57, 0xB4, 0x99, 0xF9, 0xC1, 0xE6 });
898                         Guid rz = Guid.Empty;
899                         Guid rx = Guid.NewGuid ();
900
901                         XAttribute b = new XAttribute ("b", "{7ECEBF9A-2907-439c-807D-4820B919EA57}");
902                         XAttribute d = new XAttribute ("d", "  26575b21-14cd-445e-8ffa-e2bc247b2ec9");
903                         XAttribute n = new XAttribute ("n", "  a84146f903A54af1ad977bC779572b79  \t ");
904                         XAttribute p = new XAttribute ("p", " \t \n (178a6b51-11ef-48fb-83bd-57b499f9c1e6) ");
905                         XAttribute z = new XAttribute ("z", "00000000-0000-0000-0000-000000000000\r\n");
906                         XAttribute x = new XAttribute ("x", rx);
907
908                         Assert.IsNotNull ((Guid?) new XAttribute (b), "#1a");
909                         Assert.AreEqual (rb, ((Guid?) new XAttribute (b)).Value, "#1b");
910                         Assert.AreEqual (rb, (Guid) new XAttribute (b), "#1c");
911                         Assert.AreEqual (rb, (Guid) new XAttribute ("r", rb), "#1d");
912                         Assert.IsNotNull ((Guid?) new XAttribute ("r", rb), "#1e");
913                         Assert.AreEqual (rb, ((Guid?) new XAttribute ("r", rb)).Value, "#1f");
914
915                         Assert.IsNotNull ((Guid?) new XAttribute (d), "#2a");
916                         Assert.AreEqual (rd, ((Guid?) new XAttribute (d)).Value, "#2b");
917                         Assert.AreEqual (rd, (Guid) new XAttribute (d), "#2c");
918                         Assert.AreEqual (rd, (Guid) new XAttribute ("r", rd), "#2d");
919                         Assert.IsNotNull ((Guid?) new XAttribute ("r", rd), "#2e");
920                         Assert.AreEqual (rd, ((Guid?) new XAttribute ("r", rd)).Value, "#2f");
921
922                         Assert.IsNotNull ((Guid?) new XAttribute (n), "#3a");
923                         Assert.AreEqual (rn, ((Guid?) new XAttribute (n)).Value, "#3b");
924                         Assert.AreEqual (rn, (Guid) new XAttribute (n), "#3c");
925                         Assert.AreEqual (rn, (Guid) new XAttribute ("r", rn), "#3d");
926                         Assert.IsNotNull ((Guid?) new XAttribute ("r", rn), "#3e");
927                         Assert.AreEqual (rn, ((Guid?) new XAttribute ("r", rn)).Value, "#3f");
928
929                         Assert.IsNotNull ((Guid?) new XAttribute (p), "#4a");
930                         Assert.AreEqual (rp, ((Guid?) new XAttribute (p)).Value, "#4b");
931                         Assert.AreEqual (rp, (Guid) new XAttribute (p), "#4c");
932                         Assert.AreEqual (rp, (Guid) new XAttribute ("r", rp), "#4d");
933                         Assert.IsNotNull ((Guid?) new XAttribute ("r", rp), "#4e");
934                         Assert.AreEqual (rp, ((Guid?) new XAttribute ("r", rp)).Value, "#4f");
935
936                         Assert.IsNotNull ((Guid?) new XAttribute (z), "#5a");
937                         Assert.AreEqual (rz, ((Guid?) new XAttribute (z)).Value, "#5b");
938                         Assert.AreEqual (rz, (Guid) new XAttribute (z), "#5c");
939
940                         Assert.IsNotNull ((Guid?) new XAttribute (x), "#6a");
941                         Assert.AreEqual (rx, ((Guid?) new XAttribute (x)).Value, "#6b");
942                         Assert.AreEqual (rx, (Guid) new XAttribute (x), "#6c");
943                 }
944
945                 [Test]
946                 public void CastDateTimes ()
947                 {
948                         const long weirdTicks = 8070L;  // Examples of problematic fractions of seconds on Mono 2.6.1: xxx.8796082, xxx.7332000, xxx.0050300, xxx.5678437, xxx.0008070, xxx.0769000 and xxx.2978530 (about 1 in 8 of all possible fractions seem to fail)
949                         DateTime ra = new DateTime (1987, 1, 23, 21, 45, 36, 89, DateTimeKind.Unspecified);
950                         DateTime rb = new DateTime (2001, 2, 3, 4, 5, 6, 789, DateTimeKind.Local);
951                         DateTime rc = new DateTime (2010, 1, 2, 0, 0, 0, 0, DateTimeKind.Utc) + TimeSpan.FromTicks (weirdTicks);
952                         DateTime rd = new DateTime (1956, 11, 2, 0, 34, 0);
953                         DateTime re = new DateTime (DateTime.Today.Ticks + 619917654321L);
954                         DateTime rx = DateTime.Now;
955                         DateTime rz = DateTime.UtcNow;
956
957                         XAttribute a = new XAttribute ("a", "1987-01-23T21:45:36.089");
958                         XAttribute b = new XAttribute ("b", " \n 2001-02-03T04:05:06.789" + rb.ToString ("zzz") + "  \r   ");
959                         XAttribute c = new XAttribute ("c", "2010-01-02T00:00:00." + weirdTicks.ToString ("d7").TrimEnd ('0') + "Z");
960                         XAttribute d = new XAttribute ("d", "  Nov 2, 1956  12:34 AM \r\n   \t");
961                         XAttribute e = new XAttribute ("e", " \t 17:13:11.7654321 ");
962                         XAttribute x = new XAttribute ("x", rx);
963                         XAttribute z = new XAttribute ("z", rz);
964
965                         Assert.IsNotNull ((DateTime?) new XAttribute (a), "#1a");
966                         Assert.AreEqual (ra, ((DateTime?) new XAttribute (a)).Value, "#1b");
967                         Assert.AreEqual (ra, (DateTime) new XAttribute (a), "#1c");
968                         Assert.AreEqual (ra, (DateTime) new XAttribute ("r", ra), "#1d");
969                         Assert.IsNotNull ((DateTime?) new XAttribute ("r", ra), "#1e");
970                         Assert.AreEqual (ra, ((DateTime?) new XAttribute ("r", ra)).Value, "#1f");
971
972                         Assert.IsNotNull ((DateTime?) new XAttribute (b), "#2a");
973                         Assert.AreEqual (rb, ((DateTime?) new XAttribute (b)).Value, "#2b");
974                         Assert.AreEqual (rb, (DateTime) new XAttribute (b), "#2c");
975                         Assert.AreEqual (rb, (DateTime) new XAttribute ("r", rb), "#2d");
976                         Assert.IsNotNull ((DateTime?) new XAttribute ("r", rb), "#2e");
977                         Assert.AreEqual (rb, ((DateTime?) new XAttribute ("r", rb)).Value, "#2f");
978
979                         Assert.AreEqual (10000000L, TimeSpan.TicksPerSecond, "#3a");  // Should be same on all platforms (sanity check for next logical step)
980                         Assert.AreEqual (weirdTicks, rc.Ticks % TimeSpan.TicksPerSecond, "#3b");  // Prerequisite: No ticks lost in raw data
981                         Assert.IsNotNull ((DateTime?) new XAttribute (c), "#3c");
982                         Assert.AreEqual (weirdTicks, ((DateTime?) new XAttribute (c)).Value.Ticks % TimeSpan.TicksPerSecond, "#3d");  // Did casting lose any ticks belonging to fractional seconds?
983                         Assert.AreEqual (rc, ((DateTime?) new XAttribute (c)).Value, "#3e");
984                         Assert.AreEqual (weirdTicks, ((DateTime) new XAttribute (c)).Ticks % TimeSpan.TicksPerSecond, "#3f");
985                         Assert.AreEqual (rc, (DateTime) new XAttribute (c), "#3g");
986                         Assert.AreEqual (rc, (DateTime) new XAttribute ("r", rc), "#3h");
987                         Assert.IsNotNull ((DateTime?) new XAttribute ("r", rc), "#3i");
988                         Assert.AreEqual (rc, ((DateTime?) new XAttribute ("r", rc)).Value, "#3j");
989
990                         Assert.IsNotNull ((DateTime?) new XAttribute (d), "#4a");
991                         Assert.AreEqual (rd, ((DateTime?) new XAttribute (d)).Value, "#4b");
992                         Assert.AreEqual (rd, (DateTime) new XAttribute (d), "#4c");
993                         Assert.AreEqual (rd, (DateTime) new XAttribute ("r", rd), "#4d");
994                         Assert.IsNotNull ((DateTime?) new XAttribute ("r", rd), "#4e");
995                         Assert.AreEqual (rd, ((DateTime?) new XAttribute ("r", rd)).Value, "#4f");
996
997                         Assert.IsNotNull ((DateTime?) new XAttribute (e), "#5a");
998                         Assert.AreEqual (re, ((DateTime?) new XAttribute (e)).Value, "#5b");
999                         Assert.AreEqual (re, (DateTime) new XAttribute (e), "#5c");
1000                         Assert.AreEqual (re, (DateTime) new XAttribute ("r", re), "#5d");
1001                         Assert.IsNotNull ((DateTime?) new XAttribute ("r", re), "#5e");
1002                         Assert.AreEqual (re, ((DateTime?) new XAttribute ("r", re)).Value, "#5f");
1003
1004                         Assert.IsNotNull ((DateTime?) new XAttribute (x), "#6a");
1005                         Assert.AreEqual (rx, ((DateTime?) new XAttribute (x)).Value, "#6b");
1006                         Assert.AreEqual (rx, (DateTime) new XAttribute (x), "#6c");
1007
1008                         Assert.IsNotNull ((DateTime?) new XAttribute (z), "#7a");
1009                         Assert.AreEqual (rz, ((DateTime?) new XAttribute (z)).Value, "#7b");
1010                         Assert.AreEqual (rz, (DateTime) new XAttribute (z), "#7c");
1011                 }
1012
1013                 [Test]
1014                 public void CastDateTimeOffsets ()
1015                 {
1016                         DateTimeOffset ra = new DateTimeOffset (1987, 1, 23, 21, 45, 36, 89, TimeSpan.FromHours (+13.75));  // e.g., Chatham Islands (daylight-savings time)
1017                         DateTimeOffset rb = new DateTimeOffset (2001, 2, 3, 4, 5, 6, 789, DateTimeOffset.Now.Offset);  // Local time
1018                         DateTimeOffset rc = new DateTimeOffset (2010, 1, 2, 0, 0, 0, 0, TimeSpan.Zero);  // UTC, and midnight
1019                         DateTimeOffset rd = new DateTimeOffset (1956, 11, 2, 12, 34, 10, TimeSpan.FromHours (-3.5));
1020                         DateTimeOffset re = new DateTimeOffset (630646468231147764, TimeSpan.FromHours (2));  // UTC+2, and with full resolution
1021                         DateTimeOffset rf = new DateTimeOffset (643392740967552000, TimeSpan.Zero);  // UTC, and with a potentially problematic fractional second that might lose a tick on Mono 2.6.1
1022                         DateTimeOffset rx = DateTimeOffset.Now;
1023                         DateTimeOffset rz = DateTimeOffset.UtcNow;
1024
1025                         XAttribute a = new XAttribute ("a", "1987-01-23T21:45:36.089+13:45");
1026                         XAttribute b = new XAttribute ("b", "2001-02-03T04:05:06.789" + DateTimeOffset.Now.ToString ("zzz"));
1027                         XAttribute c = new XAttribute ("c", "   2010-01-02T00:00:00Z \t");
1028                         XAttribute d = new XAttribute ("d", "  Nov 2, 1956  12:34:10 PM   -3:30 \r\n   \t");
1029                         XAttribute e = new XAttribute ("e", "1999-06-10T21:27:03.1147764+02:00");
1030                         XAttribute f = new XAttribute ("f", "2039-10-31T12:34:56.7552+00:00");
1031                         XAttribute x = new XAttribute ("x", rx);
1032                         XAttribute z = new XAttribute ("z", rz);
1033
1034                         Assert.IsNotNull ((DateTimeOffset?) new XAttribute (a), "#1a");
1035                         Assert.AreEqual (ra, ((DateTimeOffset?) new XAttribute (a)).Value, "#1b");
1036                         Assert.AreEqual (ra, (DateTimeOffset) new XAttribute (a), "#1c");
1037                         Assert.AreEqual (ra, (DateTimeOffset) new XAttribute ("r", ra), "#1d");
1038                         Assert.IsNotNull ((DateTimeOffset?) new XAttribute ("r", ra), "#1e");
1039                         Assert.AreEqual (ra, ((DateTimeOffset?) new XAttribute ("r", ra)).Value, "#1f");
1040
1041                         Assert.IsNotNull ((DateTimeOffset?) new XAttribute (b), "#2a");
1042                         Assert.AreEqual (rb, ((DateTimeOffset?) new XAttribute (b)).Value, "#2b");
1043                         Assert.AreEqual (rb, (DateTimeOffset) new XAttribute (b), "#2c");
1044                         Assert.AreEqual (rb, (DateTimeOffset) new XAttribute ("r", rb), "#2d");
1045                         Assert.IsNotNull ((DateTimeOffset?) new XAttribute ("r", rb), "#2e");
1046                         Assert.AreEqual (rb, ((DateTimeOffset?) new XAttribute ("r", rb)).Value, "#2f");
1047
1048                         Assert.IsNotNull ((DateTimeOffset?) new XAttribute (c), "#3a");
1049                         Assert.AreEqual (rc, ((DateTimeOffset?) new XAttribute (c)).Value, "#3b");
1050                         Assert.AreEqual (rc, (DateTimeOffset) new XAttribute (c), "#3c");
1051                         Assert.AreEqual (rc, (DateTimeOffset) new XAttribute ("r", rc), "#3d");
1052                         Assert.IsNotNull ((DateTimeOffset?) new XAttribute ("r", rc), "#3e");
1053                         Assert.AreEqual (rc, ((DateTimeOffset?) new XAttribute ("r", rc)).Value, "#3f");
1054
1055                         AssertThrows<FormatException> (() => { DateTimeOffset? r = (DateTimeOffset?) new XAttribute (d); }, "#4a");
1056                         AssertThrows<FormatException> (() => { DateTimeOffset r = (DateTimeOffset) new XAttribute (d); }, "#4b");
1057                         Assert.AreEqual (rd, DateTimeOffset.Parse (d.Value), "#4c");  // Sanity check: Okay for standalone DateTimeOffset but not as XML as in above
1058
1059                         Assert.IsNotNull ((DateTimeOffset?) new XAttribute (e), "#5a");
1060                         Assert.AreEqual (re, ((DateTimeOffset?) new XAttribute (e)).Value, "#5b");
1061                         Assert.AreEqual (re, (DateTimeOffset) new XAttribute (e), "#5c");
1062                         Assert.AreEqual (re, (DateTimeOffset) new XAttribute ("r", re), "#5d");
1063                         Assert.IsNotNull ((DateTimeOffset?) new XAttribute ("r", re), "#5e");
1064                         Assert.AreEqual (re, ((DateTimeOffset?) new XAttribute ("r", re)).Value, "#5f");
1065
1066                         Assert.IsNotNull ((DateTimeOffset?) new XAttribute (f), "#6a");
1067                         Assert.AreEqual (rf, ((DateTimeOffset?) new XAttribute (f)).Value, "#6b");
1068                         Assert.AreEqual (rf, (DateTimeOffset) new XAttribute (f), "#6c");
1069                         Assert.AreEqual (rf, (DateTimeOffset) new XAttribute ("r", rf), "#6d");
1070                         Assert.IsNotNull ((DateTimeOffset?) new XAttribute ("r", rf), "#6e");
1071                         Assert.AreEqual (rf, ((DateTimeOffset?) new XAttribute ("r", rf)).Value, "#6f");
1072
1073                         Assert.IsNotNull ((DateTimeOffset?) new XAttribute (x), "#7a");
1074                         Assert.AreEqual (rx, ((DateTimeOffset?) new XAttribute (x)).Value, "#7b");
1075                         Assert.AreEqual (rx, (DateTimeOffset) new XAttribute (x), "#7c");
1076
1077                         Assert.IsNotNull ((DateTimeOffset?) new XAttribute (z), "#8a");
1078                         Assert.AreEqual (rz, ((DateTimeOffset?) new XAttribute (z)).Value, "#8b");
1079                         Assert.AreEqual (rz, (DateTimeOffset) new XAttribute (z), "#8c");
1080                 }
1081
1082                 [Test]
1083                 public void CastTimeSpans ()
1084                 {
1085                         TimeSpan ra = new TimeSpan (23, 21, 45, 36, 89);
1086                         TimeSpan rb = -new TimeSpan (3, 4, 5, 6, 789);
1087                         TimeSpan rc = new TimeSpan (2, 0, 0, 0, 0);
1088                         TimeSpan rd = new TimeSpan (26798453L);  // in ticks, using full resolution and longer than a second
1089                         TimeSpan re = new TimeSpan (2710L);  // in ticks, a sub-millisecond interval
1090                         TimeSpan rx = new TimeSpan (0, 3, 8, 29, 734);
1091                         TimeSpan rz = TimeSpan.Zero;
1092
1093                         XAttribute a = new XAttribute ("a", "P23DT21H45M36.089S");
1094                         XAttribute b = new XAttribute ("b", "-P3DT4H5M6.789S");
1095                         XAttribute c = new XAttribute ("c", " \r\n   \tP2D  ");
1096                         XAttribute d = new XAttribute ("d", "PT2.6798453S");
1097                         XAttribute e = new XAttribute ("e", "PT0.000271S");
1098                         XAttribute x = new XAttribute ("x", rx);
1099                         XAttribute z = new XAttribute ("z", rz);
1100
1101                         Assert.IsNotNull ((TimeSpan?) new XAttribute (a), "#1a");
1102                         Assert.AreEqual (ra, ((TimeSpan?) new XAttribute (a)).Value, "#1b");
1103                         Assert.AreEqual (ra, (TimeSpan) new XAttribute (a), "#1c");
1104                         Assert.AreEqual (ra, (TimeSpan) new XAttribute ("r", ra), "#1d");
1105                         Assert.IsNotNull ((TimeSpan?) new XAttribute ("r", ra), "#1e");
1106                         Assert.AreEqual (ra, ((TimeSpan?) new XAttribute ("r", ra)).Value, "#1f");
1107
1108                         Assert.IsNotNull ((TimeSpan?) new XAttribute (b), "#2a");
1109                         Assert.AreEqual (rb, ((TimeSpan?) new XAttribute (b)).Value, "#2b");
1110                         Assert.AreEqual (rb, (TimeSpan) new XAttribute (b), "#2c");
1111                         Assert.AreEqual (rb, (TimeSpan) new XAttribute ("r", rb), "#2d");
1112                         Assert.IsNotNull ((TimeSpan?) new XAttribute ("r", rb), "#2e");
1113                         Assert.AreEqual (rb, ((TimeSpan?) new XAttribute ("r", rb)).Value, "#2f");
1114
1115                         Assert.IsNotNull ((TimeSpan?) new XAttribute (c), "#3a");
1116                         Assert.AreEqual (rc, ((TimeSpan?) new XAttribute (c)).Value, "#3b");
1117                         Assert.AreEqual (rc, (TimeSpan) new XAttribute (c), "#3c");
1118                         Assert.AreEqual (rc, (TimeSpan) new XAttribute ("r", rc), "#3d");
1119                         Assert.IsNotNull ((TimeSpan?) new XAttribute ("r", rc), "#3e");
1120                         Assert.AreEqual (rc, ((TimeSpan?) new XAttribute ("r", rc)).Value, "#3f");
1121
1122                         Assert.IsNotNull ((TimeSpan?) new XAttribute (d), "#4a");
1123                         Assert.AreEqual (rd, ((TimeSpan?) new XAttribute (d)).Value, "#4b");
1124                         Assert.AreEqual (rd, (TimeSpan) new XAttribute (d), "#4c");
1125                         Assert.AreEqual (rd, (TimeSpan) new XAttribute ("r", rd), "#4d");
1126                         Assert.IsNotNull ((TimeSpan?) new XAttribute ("r", rd), "#4e");
1127                         Assert.AreEqual (rd, ((TimeSpan?) new XAttribute ("r", rd)).Value, "#4f");
1128
1129                         Assert.IsNotNull ((TimeSpan?) new XAttribute (e), "#5a");
1130                         Assert.AreEqual (re, ((TimeSpan?) new XAttribute (e)).Value, "#5b");
1131                         Assert.AreEqual (re, (TimeSpan) new XAttribute (e), "#5c");
1132                         Assert.AreEqual (re, (TimeSpan) new XAttribute ("r", re), "#5d");
1133                         Assert.IsNotNull ((TimeSpan?) new XAttribute ("r", re), "#5e");
1134                         Assert.AreEqual (re, ((TimeSpan?) new XAttribute ("r", re)).Value, "#5f");
1135
1136                         Assert.IsNotNull ((TimeSpan?) new XAttribute (x), "#6a");
1137                         Assert.AreEqual (rx, ((TimeSpan?) new XAttribute (x)).Value, "#6b");
1138                         Assert.AreEqual (rx, (TimeSpan) new XAttribute (x), "#6c");
1139
1140                         Assert.IsNotNull ((TimeSpan?) new XAttribute (z), "#7a");
1141                         Assert.AreEqual (rz, ((TimeSpan?) new XAttribute (z)).Value, "#7b");
1142                         Assert.AreEqual (rz, (TimeSpan) new XAttribute (z), "#7c");
1143                 }
1144 #pragma warning restore 219
1145         }
1146 }