Browse Source

2007-11-29 Atsushi Enomoto <[email protected]>

	* XPathNavigator.cs : implemented ValueAs().

	* XPathNavigatorTests.cs : added ValueAs() test.


svn path=/trunk/mcs/; revision=90443
Atsushi Eno 18 years ago
parent
commit
2ef590022e

+ 4 - 0
mcs/class/System.XML/System.Xml.XPath/ChangeLog

@@ -1,3 +1,7 @@
+2007-11-29  Atsushi Enomoto <[email protected]>
+
+	* XPathNavigator.cs : implemented ValueAs().
+
 2007-01-30  Atsushi Enomoto <[email protected]>
 
 	* Expression.cs : typo. Close #80669

+ 2 - 2
mcs/class/System.XML/System.Xml.XPath/XPathNavigator.cs

@@ -867,10 +867,10 @@ namespace System.Xml.XPath
 				return null;
 		}
 
-		[MonoTODO]
+		// it is not very effective code but should just work
 		public override object ValueAs (Type type, IXmlNamespaceResolver nsResolver)
 		{
-			throw new NotImplementedException ();
+			return new XmlAtomicValue (Value, XmlSchemaSimpleType.XsString).ValueAs (type, nsResolver);
 		}
 
 		public virtual void WriteSubtree (XmlWriter writer)

+ 4 - 0
mcs/class/System.XML/Test/System.Xml.XPath/ChangeLog

@@ -1,3 +1,7 @@
+2007-11-29  Atsushi Enomoto <[email protected]>
+
+	* XPathNavigatorTests.cs : added ValueAs() test.
+
 2007-01-05  Atsushi Enomoto <[email protected]>
 
 	* XPathNavigatorCommonTests.cs : added test for incorrect namespace

+ 11 - 0
mcs/class/System.XML/Test/System.Xml.XPath/XPathNavigatorTests.cs

@@ -629,6 +629,17 @@ namespace MonoTests.System.Xml
 			AssertEquals ("#1", "x", doc.FirstChild.FirstChild.Prefix);
 			AssertEquals ("#2", "x", doc.FirstChild.FirstChild.Attributes [0].Prefix);
 		}
+
+		[Test]
+		public void ValueAs ()
+		{
+			string xml = "<root>1</root>";
+			XPathNavigator nav = new XPathDocument (XmlReader.Create (new StringReader (xml))).CreateNavigator ();
+			nav.MoveToFirstChild ();
+			nav.MoveToFirstChild ();
+			AssertEquals ("1", nav.ValueAs (typeof (string), null));
+			AssertEquals (1, nav.ValueAs (typeof (int), null));
+		}
 #endif
 	}
 }