public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            if (reader.TokenType == JsonToken.String)
            {
                var rawAuto    = (string)reader.Value;
                var colonIndex = rawAuto.IndexOf(':');
                var commaIndex = rawAuto.IndexOf(',');
                if (colonIndex == -1 || commaIndex == -1)
                {
                    return(Fuzziness.Auto);
                }

                var low  = int.Parse(rawAuto.Substring(colonIndex + 1, commaIndex - colonIndex - 1));
                var high = int.Parse(rawAuto.Substring(commaIndex + 1));
                return(Fuzziness.AutoLength(low, high));
            }

            if (reader.TokenType == JsonToken.Integer)
            {
                var editDistance = Convert.ToInt32(reader.Value);
                return(Fuzziness.EditDistance(editDistance));
            }
            if (reader.TokenType == JsonToken.Float)
            {
                var ratio = (reader.Value as double?).GetValueOrDefault(0);
                return(Fuzziness.Ratio(ratio));
            }
            return(null);
        }
示例#2
0
 public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
 {
     if (reader.TokenType == JsonToken.String)
     {
         return(Fuzziness.Auto);
     }
     if (reader.TokenType == JsonToken.Integer)
     {
         var editDistance = Convert.ToInt32(reader.Value);
         return(Fuzziness.EditDistance(editDistance));
     }
     if (reader.TokenType == JsonToken.Float)
     {
         var ratio = (reader.Value as double?).GetValueOrDefault(0);
         return(Fuzziness.Ratio(ratio));
     }
     return(null);
 }