David Thielen wrote:
How can I tell if I can call XPathNavigator.ValueAsBoolean safely - without
throwing an exception. I want to take one course of action if the value can
be interpreted as a boolean.
But I din't want to do it using try/catch - I think having exceptions be
thrown when the code is operating normally is very bad - both from a
performance point of view and because it signifiys an error.
I don't think XPathNavigator provides such functionality. The idea is
that when using ValueAsXXX methods you can be sure about node type, e.g.
because XML is valid.
As a workaround you can use Boolean.TryParse method, which doesn't throw
an exception when values cannot be converted to boolean:
if (Boolean.TryParse(navigator.Value, out myvalue))
//parsed ok
else
//not boolean value
--
Oleg Tkachenko [XML MVP, MCAD]
http://www.xmllab.net http://blog.tkachenko.com