开发者

Serializing XML to objects

开发者 https://www.devze.com 2023-02-24 16:40 出处:网络
To map our relation data to objects, we return XML data and deserialize to objects. In order to use this approach, the objects being deserialized needed to have a public default constructor.

To map our relation data to objects, we return XML data and deserialize to objects. In order to use this approach, the objects being deserialized needed to have a public default constructor.

What I used to do which was more work was return a dataset and write code to populate my objects manually through constructors. I consider this a better approach because I could always count on the object being properly initialized because it was creating using a constructor. However, I am tempted to use object deserialization because it is faster to develop because there is less code.

Can anyone suggest of an approach that would allow me to deserialize objects but give me a little mo开发者_StackOverflow社区re safety other than total switching gears and looking to use some ORM tool like Entity Framework, LINQ, etc?

Just thinking aloud, be gentle.


My recommendations would be to roll your own based on, or on top of, a Micro-ORM such as Dapper dot net or PetaPoco.

Dapper could be adapted to deserialize using a constructor - however I would not pull such a patch into it.

This will allow you to avoid tons of boiler plate code and is small enough to follow and maintain.

0

精彩评论

暂无评论...
验证码 换一张
取 消