With a simple class/interface like this
public interface IThing
{
string Name { get; set; }
}
public class Thing : IThing
{
public int Id { get; se
An alternative to [JsonIgnore]
are the [DataContract] and [DataMember] attributes. If you class is tagged with [DataContract]
the serializer will only process properties tagged with the [DataMember]
attribute (JsonIgnore
is an "opt-out" model while DataContract
is "op-in").
[DataContract]
public class Thing : IThing
{
[DataMember]
public int Id { get; set; }
public string Name { get; set; }
}
The limitation of both approaches is that they must be implemented in the class, you cannot add them to the interface definition.