动态创建匿名类型?
我想创建一个可以动态设置属性名称的匿名类型。它不必是匿名类型。我想要实现的就是动态设置任何对象属性名称。它可以是 ExpandoObject,但字典对我不起作用。
您有什么建议?
I wanna create an anonymous type that I can set the property name dynamically. it doesn't have to be an anonymous type. All I want to achieve is set any objects property names dynamically. It can be ExpandoObject, but dictionary will not work for me.
What are your suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只有
ExpandoObject
可以具有动态属性。编辑:
以下是扩展对象用法的示例(来自其MSDN 描述):
Only
ExpandoObject
can have dynamic properties.Edit:
Here is an example of Expand Object usage (from its MSDN description):
您可以将
ExpandoObject
转换为字典并以这种方式填充它,然后您设置的键将显示为 ExpandoObject 上的属性名称...You can cast
ExpandoObject
to a dictionary and populate it that way, then the keys that you set will appear as property names on the ExpandoObject...