Datatypes: XPath/XQuery to .NET
When a .NET extension function is used within an XPath/XQuery expression, the datatypes of the function's arguments are important for determining which one of multiple .NET methods having the same name is called.
In .NET, the following rules are followed:
•If there is more than one method with the same name in a class, then the methods available for selection are reduced to those that have the same number of arguments as the function call.
•The XPath/XQuery string, number, and boolean datatypes (see list below) are implicitly converted to a corresponding .NET datatype. If the supplied XPath/XQuery type can be converted to more than one .NET type (for example, xs:integer), then that .NET type is selected which is declared for the selected method. For example, if the .NET method being called is fx(double) and the supplied XPath/XQuery datatype is xs:integer, then xs:integer will be converted to .NET's double datatype.
The table below lists the implicit conversions of XPath/XQuery string, number, and boolean types to .NET datatypes.
IntegerValue, decimal, long, integer, short, byte, double, float
FloatValue, float, double
DecimalValue, decimal, double, float
Subtypes of the XML Schema datatypes listed above (and which are used in XPath and XQuery) will also be converted to the .NET type/s corresponding to that subtype's ancestor type.
In some cases, it might not be possible to select the correct .NET method based on the supplied information. For example, consider the following case.
•The supplied argument is an xs:untypedAtomic value of 10 and it is intended for the method mymethod(float).
•However, there is another method in the class which takes an argument of another datatype: mymethod(double).
•Since the method names are the same and the supplied type (xs:untypedAtomic) could be converted correctly to either float or double, it is possible that xs:untypedAtomic is converted to double instead of float.
•Consequently the method selected will not be the required method and might not produce the expected result. To work around this, you can create a user-defined method with a different name and use this method.
Types that are not covered in the list above (for example xs:date) will not be converted and will generate an error.