public void AppendXml(XDoc doc) { doc.Start("param").Attr("name", Name).Attr("type", DekiScriptLiteral.AsScriptTypeName(ScriptType)); if (Default.IsNil) { doc.Attr("optional", Optional ? "true" : null); } else { doc.Attr("default", Default.ToString()); } doc.Value(Hint); doc.End(); }
//--- Methods --- public XDoc ToXml(XUri uri) { XDoc result = new XDoc("function"); result.Attr("transform", Transform); if (IsProperty) { result.Attr("usage", "property"); } result.Elem("name", Name); result.Elem("uri", uri); result.Elem("description", Description); if (Access != DreamAccess.Public) { result.Elem("access", Access.ToString().ToLowerInvariant()); } foreach (DekiScriptParameter param in Parameters) { param.AppendXml(result); } result.Start("return").Attr("type", DekiScriptLiteral.AsScriptTypeName(ReturnType)).End(); return(result); }
private DekiScriptLiteral InvokeHelper(DekiScriptRuntime runtime, DekiScriptList args) { // convert passed in arguments object[] arguments = new object[Parameters.Length]; int i = 0; try { for (; i < Parameters.Length; ++i) { var value = args[i].NativeValue; // check if we need to convert the value if ((value != null) && (Parameters[i].NativeType != typeof(object))) { // check for the special case where we cast from XML to STR if ((value is XDoc) && (Parameters[i].NativeType == typeof(string))) { XDoc xml = (XDoc)value; if (xml.HasName("html")) { value = xml["body[not(@target)]"].Contents; } else { value = xml.ToString(); } } else { // rely on the default type conversion rules value = SysUtil.ChangeType(value, Parameters[i].NativeType); } } arguments[i] = value; } } catch { throw new ArgumentException(string.Format("could not convert parameter '{0}' (index {1}) from {2} to {3}", Parameters[i].Name, i, args[i].ScriptTypeName, DekiScriptLiteral.AsScriptTypeName(Parameters[i].ScriptType))); } // invoke method var result = _invoke(runtime, arguments); // check if result is a URI if (result is XUri) { // normalize URI if possible DreamContext context = DreamContext.CurrentOrNull; if (context != null) { result = context.AsPublicUri((XUri)result); } } var literal = DekiScriptLiteral.FromNativeValue(result); try { return(literal.Convert(ReturnType)); } catch (DekiScriptInvalidCastException) { throw new DekiScriptInvalidReturnCastException(Location.None, literal.ScriptType, ReturnType); } }