Csharp: DefaultValueAttribute Class, attributedefault

Source: Internet
Author: User

Csharp: DefaultValueAttribute Class, attributedefault

    public class CalendarEvent    {        public int id { get; set; }        public string title { get; set; }                public string description { get; set; }        [DefaultValue(typeof(DateTime), DateTime.Now.ToString("yyyy-MM-dd HH:mm"))]        public DateTime start { get; set; }        [DefaultValue(typeof(DateTime),DateTime.Now.ToString("yyyy-MM-dd HH:mm"))]        public DateTime end { get; set; }        [DefaultValue(typeof(bool), "false")]        public bool allDay { get; set; }        [DefaultValue(typeof(bool), "false")]        public bool overlap { get; set; }        [DefaultValue(typeof(string), "background-color")]        public string rendering { get; set; } //border-color,background-color         [DefaultValue(typeof(string), "#FFFFFF")]        public string color { get; set; } //        [DefaultValue(typeof(string), "#FFFFFF")]        public string backgroundColor { get; set; }        [DefaultValue(typeof(string), "#FFFFFF")]        public string textColor { get; set; }        [DefaultValue(typeof(string),"#FFFFFF")]        public string borderColor { get; set; }        [DefaultValue(typeof(int),"0")]        public int typeid { get; set; }        [DefaultValue(typeof(DateTime), DateTime.Now.ToString("yyyy-MM-dd HH:mm"))]        public DateTime adddate { get; set; }        //private DateTime? dateCreated = null;        //public DateTime DateCreated        //{        //    get        //    {        //        return this.dateCreated.HasValue        //           ? this.dateCreated.Value        //           : DateTime.Now;        //    }        //    set { this.dateCreated = value; }        //}        public DateTime DateCreated        {            get            {                return (this.dateCreated == default(DateTime))                   ? this.dateCreated = DateTime.Now                   : this.dateCreated;            }            set { this.dateCreated = value; }        }        private DateTime dateCreated = default(DateTime);        private bool myVal = false;        [DefaultValue(false)]        public bool MyProperty        {            get            {                return myVal;            }            set            {                myVal = value;            }        }    }

Http://stackoverflow.com/questions/691035/setting-the-default-value-of-a-datetime-property-to-datetime-now-inside-the-syst

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.