Converting the Result of a .NET Extension Function
This section explains how the value returned by a .NET extension function is converted to an XPath value.
The result type of the method is converted to an XPath value as follows.
-
If the method returns void, the XPath value is an empty sequence.
-
If the method returns null, the XPath value is an empty sequence.
-
If the method is a constructor, the XPath value is of type "wrapped .NET object". The only way of using this is by passing it to another external function, or by converting it to one of the standard XPath data types as described above.
-
If the returned value is an XdmValue or one of its subclasses such as XdmNode or XdmAtomicValue, then it is used unchanged, after unwrapping. (These types are defined in the
Saxon.Api
namespace.) Note that if the method constructs a newXdmNode
and returns it, then it must be built using the name pool that is in use by the transformation or query, which means in practice that it must be built using a DocumentBuilder derived from the sameSaxon.Api.Processor
. -
If the returned value is a .NET bool, the XPath result is a boolean.
-
If the returned value is a .NET double, the XPath result is a double.
-
If the returned value is a .NET float, the XPath result is a float.
-
If the returned value is a .NET Int64, Int32, or Int16, or one of their object wrapper equivalents, the XPath result is an integer.
-
If the returned value is a .NET string, the XPath result is a string.
-
If the returned value is an instance of the Saxon class net.sf.saxon.om.NodeInfo (a node in a Saxon tree), the XPath value will be a sequence containing a single node.
-
If the returned value is an instance of the Saxon class net.sf.saxon.om.Sequence, the returned value is used unchanged.
-
If the returned value is is an instance of the Saxon class net.sf.saxon.om.SequenceIterator (an iterator over a sequence), the XPath value will be the sequence represented by this iterator. It is essential that this iterator properly implements the method
getAnother()
which returns a new iterator over the same sequence of nodes or values, positioned at the start of the sequence. -
If the returned value is an instance of the .NET interface
System.Collections.IEnumerable
, or if it is an array, the XPath value will be the sequence represented by the contents of this collection or array. The members of the list or array will each be converted to an XPath value, as if each member was supplied from a separate function call. An error is reported if the result contains a list or array nested within another list or array. The contents of the list or array are copied immediately on return from the function, so the original collection or array object itself may be safely re-used. -
If the result is any other .NET object (including null), it is returned as a "wrapped .NET object".