Пример #1
0
 /**
  * @ 构造方法第四次重载
  * @ propNames 属性名列表
  * @ filter 过滤操作
  * @ charOption 对属性名的操作
  * @ specifyString 指定字符串
  * */
 public LimitPropertyContractResolver(JsonFilterOption filter, string[] props, JsonCharOption charOption, string specifyString, JsonLowerUpper lowerUpper = JsonLowerUpper.Normal)
 {
     this.filter        = filter;
     this.props         = props;
     this.charOption    = charOption;
     this.specifyString = specifyString;
     this.lowerUpper    = lowerUpper;
 }
Пример #2
0
        public static T FromJson <T>(this string value, JsonCharOption charOption, string specifyString, JsonLowerUpper lowerUpper = JsonLowerUpper.Normal)
        {
            if (value.IsNullOrEmpty())
            {
                return(default(T));
            }

            JsonSerializerSettings settings = new JsonSerializerSettings();

            settings.ContractResolver = new LimitPropertyContractResolver(charOption, specifyString, lowerUpper);
            IList <JsonConverter> converts = settings.Converters;

            converts.Add(new BooleanConverter());
            converts.Add(new DateTimeConverter());
            T obj = JsonConvert.DeserializeObject <T>(value, settings);

            return(obj);
        }
Пример #3
0
        /**
         * @ 序列化对象字符串
         * */
        public static string ObjToJson(this object value, JsonFilterOption filter, string[] props, JsonCharOption charOption, string specifyString, JsonLowerUpper lowerUpper = JsonLowerUpper.Lower)
        {
            if (value == null)
            {
                return(string.Empty);
            }
            JsonSerializerSettings settings = new JsonSerializerSettings();

            settings.ContractResolver = new LimitPropertyContractResolver(filter, props, charOption, specifyString, lowerUpper);
            IList <JsonConverter> converts = settings.Converters;

            converts.Add(new BooleanConverter());
            converts.Add(new DateTimeConverter());
            string jsonString = JsonConvert.SerializeObject(value, settings);

            return(jsonString);
        }
Пример #4
0
 public static string ObjToJson(this object value, JsonCharOption charOption, string specifyString, JsonLowerUpper lowerUpper = JsonLowerUpper.Lower)
 {
     return(ObjToJson(value, JsonFilterOption.Normal, null, charOption, specifyString, lowerUpper));
 }
Пример #5
0
 /**
  * @ 构造方法第二次重载
  * @ charOption 对属性名的操作
  * @ specifyString 指定字符串
  * */
 public LimitPropertyContractResolver(JsonCharOption charOption, string specifyString, JsonLowerUpper lowerUpper = JsonLowerUpper.Normal)
 {
     this.charOption    = charOption;
     this.specifyString = specifyString;
     this.lowerUpper    = lowerUpper;
 }