且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

反序列化XML以使用自动生成的属性进行分类

更新时间:2022-11-29 14:06:29

我已经使用ExpandoObject在过去的项目中做到了这一点.

类似的东西:

I have used the ExpandoObject to do exactly this in a past project.

something like:

dynamic personDetails = new ExpandoObject();

var personLookup = (IDictionary<string, object>)personDetails;
personLookup["Name"] = yourXmlValue;



我在这里排除了XLinq,但是您应该了解要点.

然后,您可以传递动态对象,并像常规属性一样对其进行访问:




I''ve excluded the XLinq here, but you should get the gist.

You can then pass the dynamic object around and just access it like regular properties:

i.e.

var name = personDetails.Name;