简体   繁体   English

WCF:DataMember的“IsRequired”属性,DataContract的“IsReference”属性

[英]WCF: “IsRequired” property for DataMember with “IsReference” property for DataContract

Why does WCF does not allow to set the "IsRequired" property for DataMembers when I set the "IsReference" property for the DataMember's DataContract? 当我为DataMember的DataContract设置“IsReference”属性时,为什么WCF不允许为DataMembers设置“IsRequired”属性? And is there a way to solve this problem? 有没有办法解决这个问题?

    [DataContract(IsReference = true)]
    public class MyClass
    {
        private DateTime date;

        [DataMember (IsRequired = true)]
        public DateTime Date
        {
            get { return date; }
            set { date = value; }
        }
    }

This code will create an error because "IsReference" and "IsRequired" are set. 此代码将创建错误,因为已设置“IsReference”和“IsRequired”。

There is an explanation for the behaviour you're getting here 你在这里的行为有一个解释

I'm not sure about way's to solve this issue 我不确定解决这个问题的方法

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM