protected override object ImportFromNumber(ImportContext context, JsonReader reader)
        {
            Debug.Assert(context != null);
            Debug.Assert(reader != null);
            string text = reader.Text;
            long   time;

            try
            {
                time = Convert.ToInt64(text, CultureInfo.InvariantCulture);
            }
            catch (FormatException e)
            {
                throw NumberError(e, text);
            }
            catch (OverflowException e2)
            {
                throw NumberError(e2, text);
            }
            try
            {
                return(ImporterBase.ReadReturning(reader, UnixTime.ToDateTime(time)));
            }
            catch (ArgumentException e3)
            {
                throw NumberError(e3, text);
            }
        }
        protected override object ImportFromNumber(ImportContext context, JsonReader reader)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }
            string text = reader.Text;

            try
            {
                return(ImporterBase.ReadReturning(reader, ConvertFromString(text)));
            }
            catch (FormatException e)
            {
                throw NumberError(e, text);
            }
            catch (OverflowException e2)
            {
                throw NumberError(e2, text);
            }
        }
Beispiel #3
0
 protected override object ImportFromString(ImportContext context, JsonReader reader)
 {
     Debug.Assert(context != null);
     Debug.Assert(reader != null);
     try
     {
         return(ImporterBase.ReadReturning(reader, new Guid(reader.Text.Trim())));
     }
     catch (FormatException ex)
     {
         throw new JsonException(ex.Message, ex);
     }
 }
 protected override object ImportFromString(ImportContext context, JsonReader reader)
 {
     Debug.Assert(context != null);
     Debug.Assert(reader != null);
     try
     {
         return(ImporterBase.ReadReturning(reader, XmlConvert.ToDateTime(reader.Text, XmlDateTimeSerializationMode.Local)));
     }
     catch (FormatException innerException)
     {
         throw new JsonException("Error importing JSON String as System.DateTime.", innerException);
     }
 }
Beispiel #5
0
        protected override object ImportFromArray(ImportContext context, JsonReader reader)
        {
            Debug.Assert(context != null);
            Debug.Assert(reader != null);
            reader.Read();
            MemoryStream memoryStream   = new MemoryStream();
            Type         typeFromHandle = typeof(byte);

            while (reader.TokenClass != JsonTokenClass.EndArray)
            {
                memoryStream.WriteByte((byte)context.Import(typeFromHandle, reader));
            }
            return(ImporterBase.ReadReturning(reader, memoryStream.ToArray()));
        }
        protected override object ImportFromArray(ImportContext context, JsonReader reader)
        {
            Debug.Assert(context != null);
            Debug.Assert(reader != null);
            reader.Read();
            ArrayList arrayList   = new ArrayList();
            Type      elementType = base.OutputType.GetElementType();

            while (reader.TokenClass != JsonTokenClass.EndArray)
            {
                arrayList.Add(context.Import(elementType, reader));
            }
            return(ImporterBase.ReadReturning(reader, arrayList.ToArray(elementType)));
        }
Beispiel #7
0
        protected override object ImportFromObject(ImportContext context, JsonReader reader)
        {
            Debug.Assert(context != null);
            Debug.Assert(reader != null);
            reader.Read();
            object obj = Activator.CreateInstance(base.OutputType);

            while (reader.TokenClass != JsonTokenClass.EndObject)
            {
                string             name = reader.ReadMember();
                PropertyDescriptor propertyDescriptor = _properties.Find(name, ignoreCase: true);
                if (propertyDescriptor != null && !propertyDescriptor.IsReadOnly)
                {
                    propertyDescriptor.SetValue(obj, context.Import(propertyDescriptor.PropertyType, reader));
                }
                else
                {
                    reader.Skip();
                }
            }
            return(ImporterBase.ReadReturning(reader, obj));
        }
        protected override object ImportFromString(ImportContext context, JsonReader reader)
        {
            Debug.Assert(context != null);
            Debug.Assert(reader != null);
            string text = reader.Text.Trim();

            if (text.Length > 0)
            {
                char c = text[0];
                if (char.IsDigit(c) || c == '+' || c == '-')
                {
                    throw Error(text, null);
                }
            }
            try
            {
                return(ImporterBase.ReadReturning(reader, Enum.Parse(base.OutputType, text, ignoreCase: true)));
            }
            catch (ArgumentException e)
            {
                throw Error(text, e);
            }
        }
 protected override object ImportFromString(ImportContext context, JsonReader reader)
 {
     Debug.Assert(context != null);
     Debug.Assert(reader != null);
     return(ImporterBase.ReadReturning(reader, reader.Text));
 }