/// <summary>
        /// 简单类型为键值对
        /// </summary>
        /// <param name="name">名称</param>
        /// <param name="value">值</param>
        /// <param name="options">选项</param>
        /// <exception cref="ArgumentNullException"></exception>
        /// <returns></returns>
        private KeyValuePair <string, string> FormatAsSimple(string name, object value, FormatOptions options)
        {
            if (string.IsNullOrEmpty(name) == true)
            {
                throw new ArgumentNullException(nameof(name));
            }

            if (options.UseCamelCase == true)
            {
                name = FormatOptions.CamelCase(name);
            }

            if (value == null)
            {
                return(new KeyValuePair <string, string>(name, null));
            }

            var isDateTime = value is DateTime;

            if (isDateTime == false)
            {
                return(new KeyValuePair <string, string>(name, value.ToString()));
            }

            // 时间格式转换
            var dateTime = ((DateTime)value).ToString(options.DateTimeFormat, DateTimeFormatInfo.InvariantInfo);

            return(new KeyValuePair <string, string>(name, dateTime));
        }
示例#2
0
            /// <summary>
            /// <summary>
            /// 创建属性
            /// </summary>
            /// <param name="member"></param>
            /// <param name="memberSerialization"></param>
            /// <returns></returns>
            protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization)
            {
                var property   = base.CreateProperty(member, memberSerialization);
                var descriptor = PropertyDescriptor.GetDescriptor(member);

                property.PropertyName = descriptor.AliasName;
                if (this.useCamelCase == true)
                {
                    property.PropertyName = FormatOptions.CamelCase(property.PropertyName);
                }

                if (property.Converter != null)
                {
                    property.Converter = descriptor.DateTimeConverter;
                }

                property.Ignored = descriptor.IsIgnoreSerialized;
                return(property);
            }