简体   繁体   中英

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? 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.

There is an explanation for the behaviour you're getting here

I'm not sure about way's to solve this issue

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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