You have a couple of options with how the DataContractSerializer handles serialization:
- Do nothing-- default behavior in .NET 4.0 and later is to send all
public members if NO declarations are made about [DataContract] or
[DataMember].
- Declare DeletableEntity as a [DataContract] and declare the serializable [DataMembers]. Once you say something, WCF assumes you want to say more.
You'll probably want to do #2. Once you do that, add on a [KnownTypes] attribute if you have any WCF methods that take a DeletableEntity and it's derived types. You'll probably just want to use the string version of KnownTypes that passes a static method name. The static method can then use reflection on the assembly to pull out all types that derive from DeletableEntity such that the method catches any new items that are added as you code.
If you want the above, I recommend the following code:
[DataContract]
[KnownType("GetKnownTypes")]
public abstract class DeletableEntity
{
[DataMember]
public bool Delete { get; set; }
public static Type[] GetKnownTypes()
{
return (from type in typeof (DeletableEntity).Assembly.GetTypes()
where typeof (DeletableEntity).IsAssignableFrom(type)
select type).ToArray();
}
}