public object Invoke(XsltContext xsltContext, object[] args, XPathNavigator docContext) { OPathXsltContext opathXsltContext = (OPathXsltContext)xsltContext; IDictionary <string, OPathCustomFunction> customFunctions = opathXsltContext.CustomFunctions; string customFunctionKey = GetCustomFunctionKey(this.Prefix, this.Name); OPathCustomFunction customFunction; if (customFunctions.TryGetValue(customFunctionKey, out customFunction)) { OPathCustomTypeConverter customTypeConverter = opathXsltContext.CustomTypeConverter; object result = customFunction(args); object convertedResult = customTypeConverter(result); return(convertedResult); } else { throw new OPathException("Could not resolve the custom function " + customFunctionKey); } }
public OPathXsltContext(IDictionary <string, object> variables, IDictionary <string, OPathCustomFunction> customFunctions, OPathCustomTypeConverter customTypeConverter) { if (variables == null) { this.Variables = new Dictionary <string, object>(); } else { this.Variables = variables; } this.CustomFunctions = customFunctions; this.CustomTypeConverter = customTypeConverter; }
public object Evaluate(XsltContext xsltContext) { OPathXsltContext opathXsltContext = (OPathXsltContext)xsltContext; IDictionary <string, object> variables = opathXsltContext.Variables; OPathCustomTypeConverter customTypeConverter = opathXsltContext.CustomTypeConverter; object value; if (!variables.TryGetValue(this.Name, out value)) { throw new OPathException( string.Format("Variable {0} was not found in the OPathXsltContext.", this.Name)); } object convertedValue = customTypeConverter(value); return(convertedValue); }
/// <summary> /// Register the custom type converter specified, overriding any previous converter for that type. /// </summary> /// <param name="customType">Type of the custom.</param> /// <param name="customTypeConverter">The custom type converter.</param> public void RegisterCustomTypeConverter(Type customType, OPathCustomTypeConverter customTypeConverter) { m_CustomerTypeConverters[customType] = customTypeConverter; }