• csharp: DefaultValueAttribute Class


        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 

  • 相关阅读:
    【2020Python修炼记】面向对象编程——绑定方法与非绑定方法
    【2020Python修炼记】面向对象编程——多态性与鸭子类型
    2020Python作业——封装2+继承
    2020Python作业——类与对象2+封装
    【2020Python修炼记】面向对象编程——继承与派生
    P1494 [国家集训队]小Z的袜子
    codeforces600E. Lomsat gelral(dsu on tree)
    这是个O2优化指令
    洛谷P1972 [SDOI2009]HH的项链
    poj3417
  • 原文地址:https://www.cnblogs.com/geovindu/p/6742866.html
Copyright © 2020-2023  润新知