首页 新闻 会员 周边

WCF困惑的问题。为什么继承的时候我不加DataContract也能用

0
悬赏园豆:140 [已关闭问题]

   有次不小心忘记加DataContract和DataMember,居然发现可以生成代理类。非常奇怪,后来发现原来是实体类的基类中加了DataContract。但是我们知道DataContract只不应用于继承类中的。

不多说 ,看代码

看服务端的数据实体 :

    [DataContract]
    public class BaseType
    {
        [DataMember]
        public Guid Id { get; set; }
    }

    public class CompositeType:BaseType
    {
        bool boolValue = true;
        string stringValue = "Hello ";

        public bool BoolValue
        {
            get { return boolValue; }
            set { boolValue = value; }
        }

        public string StringValue
        {
            get { return stringValue; }
            set { stringValue = value; }
        }
    }

客户端得到的:

  public partial class CompositeType : WebApplicationForJS.ServiceReference1.BaseType {
       
        [System.Runtime.Serialization.OptionalFieldAttribute()]
        private bool BoolValueField;
       
        [System.Runtime.Serialization.OptionalFieldAttribute()]
        private string StringValueField;
       
        [System.Runtime.Serialization.DataMemberAttribute()]
        public bool BoolValue {
            get {
                return this.BoolValueField;
            }
            set {
        &am

Mr.Wrong居然被人用了的主页 Mr.Wrong居然被人用了 | 菜鸟二级 | 园豆:205
提问于:2009-03-28 11:52
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册