csharp: DefaultValueAttribute Class

2018-06-17 22:47:32来源:未知 阅读 ()

新老客户大回馈,云服务器低至5折

    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 

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:Sturct类型装箱时会遇到的问题

下一篇:《C#高效编程》读书笔记02-用运行时常量(readonly)而不是编译期