开发者

How to seralize only some properties in .Net?

This is for a web project so i have several classes that inherit from Web.UI.

I only want to serialize very particular properties (basically, only local properties)

I'm aware of the XMLIgnore property that can be placed on a property to ignore items, but this won't work in my context since that would require modifying a bunch of stuff that i really don't want to modify (and probably can't).

So how d开发者_如何转开发o i tell the xml serializer to ignore everything except for X and Y or tell it to seralize just X and Y?

i could just create my own xml in a string builder or something and if that's the only way, so be it. however i'm looking for a method that will employ the built in XML stuff.

Thanks


For Custom Serialization, you can derive your class from ISerializable Interface and provide Custom Serialization accordingly


Why don't you implement IXmlSerializable?


You could put some hack into it and simply tear stuff out of the XML after it comes back.

It's a terrible idea compared to XMLIgnore, which is the correct solution, but you could certainly pull up the XML, spin through it, and remove whatever you don't want to see.

Sometimes terrible ideas are the best ones.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜