dotnet / vscode-csharp

Official C# support for Visual Studio Code
MIT License
2.86k stars 672 forks source link

Debugger's Locals & WATCH windows doesn't show the type of JObject for a dynamic field like other types #1484

Open cateyes99 opened 7 years ago

cateyes99 commented 7 years ago

Environment data

dotnet --info output:

.NET Command Line Tools (1.0.1)

Product Information:
 Version:            1.0.1
 Commit SHA-1 hash:  005db40cd1

Runtime Environment:
 OS Name:     Mac OS X
 OS Version:  10.11
 OS Platform: Darwin
 RID:         osx.10.11-x64
 Base Path:   /usr/local/share/dotnet/sdk/1.0.1

VS Code version: 1.12.1 C# Extension version: 1.8.1

Steps to reproduce

  1. Create the following code as

    
    [HttpPatch("{test2")]
    public async Task<IActionResult> PatchTest(
    [FromBody] JsonPatchDocument<A> patch
    )
    {
    A a = new A {
        Name = "John",
        Dyn = new System.Dynamic.ExpandoObject()
    };
    a.Dyn.oId = "oId123";
    a.Dyn.pId = "pId123";
    
    patch.ApplyTo(a);
    return Ok(a);
    }

public class A { public string Name {get; set;} public dynamic Dyn {get; set;} }

2. Run and debug it, and sent a HTTP request with the below `application/json` body from Postman to it
```json
[
    { "op": "replace", "path": "/Dyn", "value": {
            "aId": "aId123",
            "bId": "bId123"
        }
    }
]
  1. Observe the variable a in the debugger's Locals window. Before patch.ApplyTo(a); it shows the type of a.Dyn as {System.Dynamic.ExpandoObject} which is nice as I wanna know the real type here. image

  2. After patch.ApplyTo(a);, the a.Dyn's value has been replaced by a {Newtonsoft.Json.Linq.JObject} which is created by Microsoft.AspNetCore.JsonPatch.JsonPatchDocument<TModel>, it doesn't show the type of a.Dyn instead shows the value of it, which isn't that convenient as the type info is very important. image

DustinCampbell commented 7 years ago

This is likely by design. IIRC, Visual Studio does the same thing. However, VS also provides a "Dynamic View" that can be expanded for dynamic types.

cateyes99 commented 7 years ago

@DustinCampbell When debugging in VS2017, Before patch.ApplyTo(a); it shows image

After patch.ApplyTo(a); it shows the below. VS2017 does the same thing for showing what in the Value column. But in the Type column, it shows dynamic {Newtonsoft.Json.Linq.JObject} which tells the real type. But what shows in VSCode is only [dynamic]. So maybe Omnisharp can take the same approach in VS2017. image