예제 #1
0
        public void Test_Default_CloneChange()
        {
            var opt = new FormatOptions();

            Assert.True(opt.CloneChange(null) == opt);
            Assert.True(opt.CloneChange(DateTimeFormats.LocalDateTimeFormat) == opt);
            Assert.True(opt.CloneChange("yyyy") != opt);
        }
예제 #2
0
        public void Test_Default_CloneChange()
        {
            var opt = new FormatOptions()
            {
                DateTimeFormat = "xyz", IgnoreNullProperty = true, UseCamelCase = true
            };

            Assert.True(opt.CloneChange(null) == opt);
            Assert.True(opt.CloneChange("xyz") == opt);

            var yyyy = opt.CloneChange("yyyy");

            Assert.True(yyyy != opt);
            Assert.True(yyyy.DateTimeFormat == "yyyy");
            Assert.True(yyyy.IgnoreNullProperty == opt.IgnoreNullProperty);
            Assert.True(yyyy.UseCamelCase == opt.UseCamelCase);
        }
예제 #3
0
 /// <summary>
 /// 复杂类型转换为键值对
 /// </summary>
 /// <param name="instance">实例</param>
 /// <param name="options">选项</param>
 /// <returns></returns>
 private IEnumerable <KeyValuePair <string, string> > SerializeAsComplex(
     object instance,
     FormatOptions options)
 {
     return
         (from p in PropertyDescriptor.GetProperties(instance.GetType())
          where p.IsSupportGet && p.IgnoreSerialized == false
          let value = p.GetValue(instance)
                      let opt = options.CloneChange(p.DateTimeFormat)
                                select this.SerializeAsSimple(p.AliasName, value, opt));
 }