質問

I have the following class (simplified).

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

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

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.

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

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.

役に立ちましたか?

解決

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.

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

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top