带数字的 .NET 对象初始值设定项

.NET Object Initializers with numbers

所以我有以下对象初始值设定项。这是一个 API 我也在尝试发送数据。

             Dim request = New With {
             .data = New With {
                .workspace = workspace,
                .name = "Complex task test",
                .notes = "These are task notes",
                .projects = {"1202219487026592"},
                .custom_fields = New With {
                    .21234515112 = "222"
                    }
                }
            }

问题是 custom_fields 需要 GID,这是数字。显然我们不能为此使用数字,所以它会导致问题。

有什么办法解决这个问题吗?另一种声明它并获得相同结果的方法?

使用 Dictionary(Of UInt64, String) 会起作用,假设您希望将 custom_fields 属性 值序列化为 JSON 对象:

Dim request = New With {
    .data = New With {
        .workspace = workspace,
        .name = "Complex task test",
        .notes = "These are task notes",
        .projects = {"1202219487026592"},
        .custom_fields = New Dictionary(Of UInt64, String) From {
            { 21234515112, "222" }
        }
    }
}

Dim serializedJson = JsonConvert.SerializeObject(request)

Fiddle: https://dotnetfiddle.net/NHrNqC