|
|
От: |
V.Petrovski
|
|
| Дата: | 06.04.04 08:15 | ||
| Оценка: | |||
String — System.String (XPath)
Boolean — System.Boolean (XPath)
Number — System.Double (XPath)
Result Tree Fragment — System.Xml.XPath.XPathNavigator (XSLT)
Node Set — System.Xml.XPath.XPathNodeIterator (XPath)
if(returnedType == XPathResultType.Any) {
// If function is untyped get returned type from real result
returnedType = XsltCompileContext.GetXPathType(result.GetType());
}private void InvokeFunction(XPathNavigator qy) {
IXsltContextFunction function = this.Function;
// calculate arguments:
Debug.Assert(_ArgArray != null && _ArgArray.Length == _ArgList.Count);
for(int i = _ArgList.Count - 1; 0 <= i; i --) {
IQuery arg = (IQuery) _ArgList[i];
if (arg.ReturnType() == XPathResultType.NodeSet) {
_ArgArray[i] = new XPathQueryIterator(arg, qy.Clone());
}
else {
_ArgArray[i] = arg.getValue(qy, null);
}
}
try {
object result = function.Invoke(_XsltContext, _ArgArray, qy);
if(result == null) {
_ResultQuery = new OperandQuery( String.Empty, XPathResultType.String );
}
else {
XPathResultType returnedType = function.ReturnType;
if(returnedType == XPathResultType.Any) {
// If function is untyped get returned type from real result
returnedType = XsltCompileContext.GetXPathType(result.GetType());
}
switch (returnedType) {
case XPathResultType.String :
// trick. As soon XPathResultType.Navigator will be distinct type rid of from it.
//_ResultQuery = new OperandQuery( result, XPathResultType.String );
if(result is XPathNavigator) {
_ResultQuery = new NavigatorQuery((XPathNavigator)result);
}
else {
_ResultQuery = new OperandQuery( result, XPathResultType.String );
}
break;
case XPathResultType.Boolean :
_ResultQuery = new OperandQuery( result, XPathResultType.Boolean );
break;
case XPathResultType.Number :
_ResultQuery = new OperandQuery( XmlConvert.ToXPathDouble( result ), XPathResultType.Number );
break;
case XPathResultType.NodeSet :
if (result is ResetableIterator) {
_ResultQuery = new XmlIteratorQuery((ResetableIterator)result);
}
else {
Debug.Assert(false, "Unexpected type of XPathNodeIterator");
throw new NotSupportedException(Res.GetString(Res.XmlUnsupportedType, result.GetType().FullName));
}
break;
// case XPathResultType.Navigator :
// _ResultQuery = new NavigatorQuery((XPathNavigator)result);
// break;
default :
_ResultQuery = new OperandQuery( result.ToString(), XPathResultType.String );
break;
}
}
}
catch(Exception ex) {
string qname = _Prefix != string.Empty ? _Prefix + ":" + _Name : _Name;
throw new XsltException(Res.Xslt_FunctionFailed, new string[] {qname}, ex);
}
}