I have two objects, one is in our enterprise level and another in in our service level. The service object is inheriting from the enterprise. Here is a quick example:
[DataContract] public class EnterpriseObject{ [DataMember] int ID{get; set;} string InternalUse{get; set;} } [DataContract] public class ServiceObject: EnterpriseBaseObject{ [DataMember] string Address{get; set;} }
Is it possible to only expose the ServiceObject (with inherited properties from EnterpriseObject) in the serialization? I do not want the client to see the enterprise object listed as an option? As you can see in the example the DataMember attribute is not set for the InternalUser property. Is that the only way to do it? Thanks
You handle inheritance by adding a
[KnownType(typeof(ServiceObject))]toEnterpriseBaseObject– however, theEnterpriseBaseObjectis still part of the contract, and its existance will be public. But only members marked[DataMember]will be published.One option (to remove the inheritance) is to have a separate DTO for serialization purposes, and have a conversion between the DTO version and the actual version – but that makes extra work.