Search code examples
c#.netwcfdatacontractdatamember

Can I expose a DataMember of a class that is not a DataContract?


Can I do something like this:

public abstract class DeletableEntity
{
    [DataMember]
    public bool Delete { get; set; }
}

[DataContract]
public class MyClass : DeletableEntity
{
    [DataMember]
    public int ID { get; set; }
}

I really only need DeletableEntity so others can inherit from it, so it doesn't need to go over WCF, can I send its Delete member with my MyClass without having to send the DeletableEntity as well?


Solution

  • No that should not be possible. From your requirements it would be simpler to use interfaces. Also, as an advise please consider using Known Types. This is not really directly related to you problem but it will allow you to use 'polymorphism' over wcf. More details can be obtained here: http://msdn.microsoft.com/en-us/magazine/gg598929.aspx