示例#1
0
        static object DecodeValue(object value, Type targetType)
        {
            if (value == null)
            {
                return(null);
            }

            if (JsonBuilder.IsSupported(value))
            {
                value = ConvertValue(value, targetType);
            }

            // use a registered decoder
            if (value != null && !targetType.IsAssignableFrom(value.GetType()))
            {
                Decoder decoder = GetDecoder(targetType);
                value = decoder(targetType, value);
            }

            if (value != null && targetType.IsAssignableFrom(value.GetType()))
            {
                return(value);
            }
            else
            {
                Console.WriteLine("couldn't decode: " + targetType);
                return(null);
            }
        }
示例#2
0
 public static void EncodeValue(object value, JsonBuilder builder)
 {
     if (JsonBuilder.IsSupported(value))
     {
         builder.AppendValue(value);
     }
     else
     {
         Encoder encoder = GetEncoder(value.GetType());
         if (encoder != null)
         {
             encoder(value, builder);
         }
         else
         {
             Console.WriteLine("encoder for " + value.GetType() + " not found");
         }
     }
 }