[Mono-bugs] [Bug 343869] XPathNavigator.ValueAs() throws NotImplementedException

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Tue Feb 17 09:46:10 EST 2009


https://bugzilla.novell.com/show_bug.cgi?id=343869

User robert.sevcik at gmail.com added comment
https://bugzilla.novell.com/show_bug.cgi?id=343869#c8





--- Comment #8 from Robert Sevcik <robert.sevcik at gmail.com>  2009-02-17 07:46:10 MST ---
Okay, it seems it has not been included in 1.2.6+dfsg (ubuntu 8.04)

I came up with an ugly workaround in my method if anyone's interested. 

        protected virtual ResultT Convert<ResultT>(XPathNavigator nav)

        {

            Type resultType = typeof(ResultT);



            ConstructorInfo ctor = null;

            if(resultType.IsClass) ctor = resultType.GetConstructor(new Type[]
{ typeof(XPathNavigator) });



            ResultT result;



            if (ctor != null)

                result = (ResultT)ctor.Invoke(new object[] { nav.Clone() });

            else if (resultType.Equals(typeof(XPathNavigator)))

                result = (ResultT)(object)nav.Clone();

            else
            {
                try
                {
                    // not implemented in mono 1.2.6
https://bugzilla.novell.com/show_bug.cgi?id=343869

                    result = (ResultT)nav.ValueAs(resultType);
                }
                catch(NotImplementedException x)
                {
                    switch(resultType.FullName)
                    {
                    case "System.String":  result = (ResultT) (object)
nav.ToString();     break;
                    case "System.Boolean": result = (ResultT) (object)
nav.ValueAsBoolean; break;
                    case "System.Int32":   result = (ResultT) (object)
nav.ValueAsInt;     break;
                    case "System.Int64":   result = (ResultT) (object)
nav.ValueAsLong;    break;
                    case "System.Double":  result = (ResultT) (object)
nav.ValueAsDouble;  break;
                    default: throw new
NotImplementedException(String.Format("Conversion to {0} is not implemented.",
resultType.FullName), x); 
                    }

                }
            }

            return result;

        }

-- 
Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.


More information about the mono-bugs mailing list