Ejemplo n.º 1
0
        internal static byte[] ReadBytes(JsonReader reader, JsonDeserializeHandler handler)
        {
            char c = reader.BeforAnnotation();

            if (c == 'n' && reader.StrCompair("ull"))
            {
                return(null);
            }
            else if (c == '[')
            {
                reader.RollbackChar();
                if (byteArray == null)
                {
                    lock (ObjLock)
                    {
                        if (byteArray == null)
                        {
                            byteArray = BuildFactory.Build <byte[]>(DeserializeBuildTypeEnum.Array, typeof(byte[]));
                        }
                    }
                }
                return(byteArray(reader, handler));
            }
            else
            {
                reader.RollbackChar();
                return(Convert.FromBase64String(PrimitiveResolve.ReadEscapeString(reader, handler)));
            }
        }
Ejemplo n.º 2
0
        internal static StringDictionary ReadStringDictionary(JsonReader reader, JsonDeserializeHandler handler)
        {
            if (reader.ReadNullOrObjLeft())
            {
                return(null);
            }

            StringDictionary nameValueCollection = new StringDictionary();

            int moveNext = 1;

            while (moveNext-- > 0)
            {
                var key = PrimitiveResolve.ReadEscapeString(reader, handler);
                reader.ReadColon();
                var value = PrimitiveResolve.ReadEscapeString(reader, handler);
                nameValueCollection.Add(key, value);
                if (reader.ReadBoolComma())
                {
                    moveNext++;
                }
            }
            reader.ReadObjRight();
            return(nameValueCollection);
        }
Ejemplo n.º 3
0
        internal static ExpandoObject ReadExpandoObject(JsonReader reader, JsonDeserializeHandler handler)
        {
            if (reader.ReadNullOrObjLeft())
            {
                return(null);
            }

            ExpandoObject obj = new ExpandoObject();
            var           dic = (IDictionary <string, object>)obj;

            int moveNext = 1;

            while (moveNext-- > 0)
            {
                var key = PrimitiveResolve.ReadEscapeString(reader, handler);
                reader.ReadColon();
                var value = PrimitiveResolve.ReadObject(reader, handler);
                dic.Add(key, value);
                if (reader.ReadBoolComma())
                {
                    moveNext++;
                }
            }
            reader.ReadObjRight();
            return(obj);
        }
Ejemplo n.º 4
0
 internal static Uri ReadUri(ref JsonReader reader, JsonDeserializeHandler handler)
 {
     char c = reader.BeforAnnotation();
     if (c == 'n' && reader.StrCompair("ull"))
         return null;
     else
     {
         reader.RollbackChar();
         return new Uri(PrimitiveResolve.ReadEscapeString(ref reader,handler));
     }
 }
Ejemplo n.º 5
0
        internal static DataTable ReadDataTable(JsonReader reader, JsonDeserializeHandler handler)
        {
            //[{ \"Id\":1 , \"Name\":\"ss\" }]
            if (reader.ReadNullOrArrayLeft())
            {
                return(null);
            }
            DataTable dt = new DataTable();

            int moveNext = 1;

            while (moveNext-- > 0)
            {
                reader.ReadObjLeft();
                DataRow dr   = dt.NewRow();
                int     move = 1;
                while (move-- > 0)
                {
                    string columnName = PrimitiveResolve.ReadEscapeString(reader, handler);
                    reader.ReadColon();
                    DataColumn column = dt.Columns[columnName];
                    if (column == null)
                    {
                        column = new DataColumn(columnName, typeof(object));
                        dt.Columns.Add(column);
                    }

                    object rowValue = PrimitiveResolve.ReadObject(reader, handler);
                    dr[columnName] = rowValue;

                    if (reader.ReadBoolComma())
                    {
                        move++;
                    }
                }
                dr.EndEdit();
                dt.Rows.Add(dr);

                reader.ReadObjRight();
                if (reader.ReadBoolComma())
                {
                    moveNext++;
                }
            }

            reader.ReadArrayRight();
            return(dt);
        }
Ejemplo n.º 6
0
        internal static NameValueCollection ReadNameValueCollection(ref JsonReader reader, JsonDeserializeHandler handler)
        {
            if (reader.ReadNullOrObjLeft())
                return null;

            NameValueCollection nameValueCollection = new NameValueCollection();

            int moveNext = 1;
            while (moveNext-- > 0)
            {
                var key = PrimitiveResolve.ReadEscapeString(ref reader, handler);
                reader.ReadColon();
                var value = PrimitiveResolve.ReadEscapeString(ref reader, handler);
                nameValueCollection.Add(key, value);
                if (reader.ReadBoolComma())
                    moveNext++;
            }
            reader.ReadObjRight();
            return nameValueCollection;
        }
Ejemplo n.º 7
0
        internal static Exception ReadException(ref JsonReader reader, JsonDeserializeHandler handler)
        {
            if (reader.ReadNullOrObjLeft())
            {
                return(null);
            }
            if (reader.ReadBoolObjRight())
            {
                return(new Exception());
            }

            string source = null, message = null, helpLink = null;

            int  i = 1;
            char c = ' ';

            while (i-- > 0)
            {
                reader.ReadQuotes();
                switch (handler.Option.JsonCharacterReadState)
                {
                case JsonCharacterReadStateEnum.None:
                    c = reader.GetChar();
                    break;

                case JsonCharacterReadStateEnum.InitialUpper:
                    c = char.ToUpper(reader.GetChar());
                    break;

                case JsonCharacterReadStateEnum.InitialLower:
                    c = char.ToLower(reader.GetChar());
                    break;
                }
                switch (c)
                {
                case 'S':
                    c = reader.GetChar();
                    if (c == 'o' && reader.StrCompair("urce\""))
                    {
                        reader.ReadColon();
                        source = PrimitiveResolve.ReadEscapeString(ref reader, handler);
                    }
                    else if (c == 't' && reader.StrCompair("ackTrace\""))
                    {
                        //只读
                        reader.ReadColon();
                        PrimitiveResolve.ReadEscapeString(ref reader, handler);
                    }
                    else
                    {
                        throw new Exception();
                    }
                    break;

                case 'M':
                {
                    if (reader.StrCompair("essage\""))
                    {
                        reader.ReadColon();
                        message = PrimitiveResolve.ReadEscapeString(ref reader, handler);
                    }
                    else
                    {
                        throw new Exception();
                    }
                    break;
                }

                case 'H':
                {
                    if (reader.StrCompair("elpLink\""))
                    {
                        reader.ReadColon();
                        helpLink = PrimitiveResolve.ReadEscapeString(ref reader, handler);
                    }
                    else
                    {
                        throw new Exception();
                    }
                    break;
                }

                default:
                    throw new Exception();
                }
                if (reader.ReadBoolComma())
                {
                    i++;
                }
            }

            var exception = message != null ? new Exception(message) : new Exception();

            exception.Source   = source;
            exception.HelpLink = helpLink;

            return(exception);
        }
Ejemplo n.º 8
0
        internal static Type ReadType(ref JsonReader reader, JsonDeserializeHandler handler)
        {
            var typeName = PrimitiveResolve.ReadEscapeString(ref reader, handler);

            return(typeName != null?Type.GetType(typeName) : null);
        }