internal async Task <JToken> TryGetVariableValue(MessageId msg_id, int scope_id, string expression, bool only_search_on_this, CancellationToken token) { JToken thisValue = null; var context = GetContext(msg_id); if (context.CallStack == null) { return(null); } if (TryFindVariableValueInCache(context, expression, only_search_on_this, out JToken obj)) { return(obj); } var scope = context.CallStack.FirstOrDefault(s => s.Id == scope_id); var live_vars = scope.Method.GetLiveVarsAt(scope.Location.CliLocation.Offset); //get_this var res = await SendMonoCommand(msg_id, MonoCommands.GetScopeVariables(scope.Id, live_vars.Select(lv => lv.Index).ToArray()), token); var scope_values = res.Value? ["result"]? ["value"]?.Values <JObject> ()?.ToArray(); thisValue = scope_values?.FirstOrDefault(v => v ["name"]?.Value <string> () == "this"); if (!only_search_on_this) { if (thisValue != null && expression == "this") { return(thisValue); } var value = scope_values.SingleOrDefault(sv => sv ["name"]?.Value <string> () == expression); if (value != null) { return(value); } } //search in scope if (thisValue != null) { if (!DotnetObjectId.TryParse(thisValue ["value"] ["objectId"], out var objectId)) { return(null); } res = await SendMonoCommand(msg_id, MonoCommands.GetDetails(objectId), token); scope_values = res.Value? ["result"]? ["value"]?.Values <JObject> ().ToArray(); var foundValue = scope_values.FirstOrDefault(v => v ["name"].Value <string> () == expression); if (foundValue != null) { foundValue["fromThis"] = true; context.LocalsCache[foundValue ["name"].Value <string> ()] = foundValue; return(foundValue); } } return(null); }
async Task <Result> RuntimeGetProperties(MessageId id, DotnetObjectId objectId, JToken args, CancellationToken token) { if (objectId.Scheme == "scope") { return(await GetScopeProperties(id, int.Parse(objectId.Value), token)); } var res = await SendMonoCommand(id, MonoCommands.GetDetails(objectId, args), token); if (res.IsErr) { return(res); } if (objectId.Scheme == "cfo_res") { // Runtime.callFunctionOn result object var value_json_str = res.Value ["result"]?["value"]?["__value_as_json_string__"]?.Value <string> (); if (value_json_str != null) { res = Result.OkFromObject(new { result = JArray.Parse(value_json_str.Replace(@"\""", "\"")) }); } else { res = Result.OkFromObject(new { result = new {} }); } } else { res = Result.Ok(JObject.FromObject(new { result = res.Value ["result"] ["value"] })); } return(res); }