Exemplo n.º 1
0
            public object Translate(ScriptRunnerResult result, JsonOperationContext context, JsBlittableBridge.IResultModifier modifier = null, BlittableJsonDocumentBuilder.UsageMode usageMode = BlittableJsonDocumentBuilder.UsageMode.None)
            {
                var val = result.RawJsValue;

                if (val.IsString())
                {
                    return(val.AsString());
                }
                if (val.IsBoolean())
                {
                    return(val.AsBoolean());
                }
                if (val.IsObject())
                {
                    return(result.TranslateToObject(context, modifier, usageMode));
                }
                if (val.IsNumber())
                {
                    return(val.AsNumber());
                }
                if (val.IsNull() || val.IsUndefined())
                {
                    return(null);
                }
                if (val.IsArray())
                {
                    throw new InvalidOperationException("Returning arrays from scripts is not supported, only objects or primitves");
                }
                throw new NotSupportedException("Unable to translate " + val.Type);
            }
Exemplo n.º 2
0
 private string GetDebugValue(JsValue obj, bool recursive)
 {
     if (obj.IsString())
     {
         var debugValue = obj.ToString();
         return(recursive ? '"' + debugValue + '"' : debugValue);
     }
     if (obj.IsArray())
     {
         var sb      = new StringBuilder("[");
         var array   = obj.AsArray();
         var jsValue = (int)array.Get("length").AsNumber();
         for (var i = 0; i < jsValue; i++)
         {
             if (i != 0)
             {
                 sb.Append(",");
             }
             sb.Append(GetDebugValue(array.Get(i.ToString()), true));
         }
         sb.Append("]");
         return(sb.ToString());
     }
     if (obj.IsObject())
     {
         var result = new ScriptRunnerResult(this, obj);
         using (var jsonObj = result.TranslateToObject(_jsonCtx))
         {
             return(jsonObj.ToString());
         }
     }
     if (obj.IsBoolean())
     {
         return(obj.AsBoolean().ToString());
     }
     if (obj.IsNumber())
     {
         return(obj.AsNumber().ToString(CultureInfo.InvariantCulture));
     }
     if (obj.IsNull())
     {
         return("null");
     }
     if (obj.IsUndefined())
     {
         return("undefined");
     }
     return(obj.ToString());
 }