当前位置: 动力学知识库 > 问答 > 编程问答 >

c# - Conditionally prevent an object from being serialized to XML at runtime

问题描述:

How could logic be implemented to conditionally prevent an object from being serialized? For example, if the list below is serialized to XML, only 500 of the MyType instances should show up in the result. Whether or not an instance of MyType should be serialized is only known at runtime.

List<MyType> custom_types = new List<MyType>( 1000 );

网友答案:

Filter the list using linq prior to serialization;

serialize(custom_types.where(t = > t.Prop = value).ToList());

分享给朋友:
您可能感兴趣的文章:
随机阅读: