Esempio n. 1
0
        /// <inheritdoc />
        public override object ReadJson(
            JsonReader reader,
            Type objectType,
            object existingValue,
            JsonSerializer serializer)
        {
            switch ((int)reader.TokenType - 7)
            {
            case 0:
                if (!StrictPrimitiveConverter.IsInteger(objectType))
                {
                    throw new InvalidCastException();
                }
                return(this.defaultSerializer.Deserialize(reader, objectType));

            case 1:
                if (!StrictPrimitiveConverter.IsFloat(objectType))
                {
                    throw new InvalidCastException();
                }
                return(this.defaultSerializer.Deserialize(reader, objectType));

            case 2:
            case 4:
                if (!StrictPrimitiveConverter.IsString(objectType))
                {
                    throw new InvalidCastException();
                }
                return(this.defaultSerializer.Deserialize(reader, objectType));

            case 3:
                if (!StrictPrimitiveConverter.IsBool(objectType))
                {
                    throw new InvalidCastException();
                }
                return(this.defaultSerializer.Deserialize(reader, objectType));

            default:
                throw new InvalidOperationException();
            }
        }
Esempio n. 2
0
 /// <inheritdoc />
 public override bool CanConvert(Type objectType)
 {
     return(StrictPrimitiveConverter.IsFloat(objectType) || StrictPrimitiveConverter.IsBool(objectType) || StrictPrimitiveConverter.IsInteger(objectType) || StrictPrimitiveConverter.IsString(objectType));
 }