ServiceStack.Text:强制序列化未使用DataMember属性修饰的属性 [英] ServiceStack.Text: Forcing serialization of a property not decorated with DataMember attribute

查看:89
本文介绍了ServiceStack.Text:强制序列化未使用DataMember属性修饰的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下课程(简体).

I have the following class (simplified).

[DataContract]
public class ServiceResponse
{
    public int Sequence { get; set; }

    [DataMember]
    public ServiceResponseStatus Status { get; set; }
}

我正在使用ServiceStack序列化对象以进行日志记录,然后让DataContractSerializer完成其余工作.正如预期的那样,ServiceStack不会序列化Sequence,因为它没有用DataMember属性修饰.

I'm using ServiceStack to serialize objects for logging purposes, and letting DataContractSerializer do the rest. ServiceStack, as expected, will not serialize Sequence as it is not decorated with a DataMember attribute.

是否有一种方法可以强制ServiceStack序列化此属性?

Is there a way to force ServiceStack to serialize this property?

Marc Gravell对这个类似问题的答案不具有DataMember属性的DataContract序列化似乎表明一种不同的方法,但我想我会问.

Marc Gravell's answer to this similar question DataContract Serialization without DataMember Attribute seems to suggest a different approach, but I thought I'd ask.

推荐答案

使用DataContract/DataMember属性装饰类是专门用于选择要序列化的属性.如果要序列化所有属性,请删除所有属性.

Decorating your classes with DataContract/DataMember attributes is specifically used for opting in which properties you want serialized. If you want all properties serialized remove all the attributes.

请参阅此答案,以忽略Servicestack序列化程序中的属性的其他方式.

See this answer for other ways to ignore properties in Servicestack serializers.

这篇关于ServiceStack.Text:强制序列化未使用DataMember属性修饰的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆