以C#动态ExpandoObjects名称开头的句点? [英] Periods in the name of c# dynamic ExpandoObjects?

查看:110
本文介绍了以C#动态ExpandoObjects名称开头的句点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

也许这是一个愚蠢的问题,但是我正在开发一个项目,希望我生成一些如下所示的JSON :

Maybe this is a silly question, but I'm working on a project that wants me to generate some JSON that looks like this:

{'action.type':'post', 'application':APP_ID}

在C#中,我试图使用"post"的值创建此"action.type"属性.我该怎么做?这是我典型地创建诸如以下内容的方式:

In C#, I'm trying to create this "action.type" attribute, with the value of "post". How would I do that? Here's how I've typlically been creating stuff like:

dynamic ActionSpec = new ExpandoObject();
ActionSpec.SomeParam = "something";
ActionSpec.id = 12345;

我无法使用"ActionSpec.action.type",因为那样将不会输出所需的"action.type". 这有意义吗? 谢谢!

I can't go "ActionSpec.action.type", because that will not output the desired "action.type". Does this make sense? Thanks!

推荐答案

您可以尝试通过字典填充它:

You could try populating it via the dictionary:

IDictionary<string, object> expandoDictionary = ActionSpec;
expandoDictionary["action.type"] = "post";

但是,如果它拒绝将其作为无效标识符,我将不会感到惊讶.

However, I wouldn't be at all surprised if it rejected that as an invalid identifier.

这篇关于以C#动态ExpandoObjects名称开头的句点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆