Пример #1
0
        public static DateTime?DateTimeParse(IDeserializerReader reader, JsonDeserializeSetting setting, string name)
        {
            IConvertMethodProvider <DateTime> customMethodProvider = CustomSerializationProvider.QueryCustomDatetimeFormat(setting.DateTimeFormat) as IConvertMethodProvider <DateTime>;

            if (customMethodProvider == null)
            {
                return(DateTimeMethodProvider.Default.Parse(reader, setting, reader.Read(name), true));
            }

            return(customMethodProvider.Parse(reader, setting, reader.Read(name), true));
        }
        public static void Write(ISerializerWriter writer, JsonSerializeSetting setting, DateTime source)
        {
            if (DateTimeFormat.Default.Equals(setting.DateTimeFormat))
            {
                ISO8601StyleDateMethodProvider.Default.Write(writer, setting, source);
                return;
            }

            if (DateTimeFormat.ChineseStyle.Equals(setting.DateTimeFormat))
            {
                ChineseStyleDateMethodProvider.Default.Write(writer, setting, source);
                return;
            }

            if (DateTimeFormat.ISO8601Style.Equals(setting.DateTimeFormat))
            {
                ISO8601StyleDateMethodProvider.Default.Write(writer, setting, source);
                return;
            }

            if (DateTimeFormat.MicrosoftStyle.Equals(setting.DateTimeFormat))
            {
                MicrosoftStyleDateMethodProvider.Default.Write(writer, setting, source);
                return;
            }

            if (DateTimeFormat.RFC1123Style.Equals(setting.DateTimeFormat))
            {
                RFC1123StyleDateMethodProvider.Default.Write(writer, setting, source);
                return;
            }

            IConvertMethodProvider <DateTime> customMethodProvider = CustomSerializationProvider.QueryCustomDatetimeFormat(setting.DateTimeFormat) as IConvertMethodProvider <DateTime>;

            if (customMethodProvider == null)
            {
                throw new ArgumentException("format is not defined");
            }

            customMethodProvider.Write(writer, setting, source);
        }