Beispiel #1
0
 public ArrayStartState(BjSJsonReader reader, Action <BjSJsonArray> onDone)
 {
     _reader           = reader;
     _onDone           = onDone;
     _curr             = new BjSJsonArray();
     _waitForSeperator = false;
 }
Beispiel #2
0
        private static BjSJsonArray ToJsonArray(IEnumerable array)
        {
            BjSJsonArray result = new BjSJsonArray();

            foreach (object obj in array)
            {
                result.Add(ToJsonValue(obj));
            }

            return(result);
        }
Beispiel #3
0
        private static IList FromJsonArrayToList(Type elementType, BjSJsonArray array)
        {
            IList result = Activator.CreateInstance(typeof(List <>).MakeGenericType(elementType)) as IList;

            foreach (object o in array)
            {
                result.Add(FromJsonValue(o, elementType));
            }

            return(result);
        }
Beispiel #4
0
        private static Array FromJsonArrayToArray(Type elementType, BjSJsonArray array)
        {
            Array result = Array.CreateInstance(elementType, array.Count);

            for (int i = 0; i < result.Length; i++)
            {
                result.SetValue(FromJsonValue(array[i], elementType), i);
            }

            return(result);
        }
Beispiel #5
0
        private static BjSJsonArray ToJsonObject(IDictionary dict)
        {
            BjSJsonArray result = new BjSJsonArray();

            IDictionaryEnumerator enu = dict.GetEnumerator();

            while (enu.MoveNext())
            {
                result.Add(new BjSJsonArray(ToJsonValue(enu.Key), ToJsonValue(enu.Value)));
            }

            return(result);
        }
Beispiel #6
0
        private static IDictionary FromJsonArrayToDictionary(Type[] dictTypes, BjSJsonArray array)
        {
            IDictionary result = Activator.CreateInstance(typeof(Dictionary <,>).MakeGenericType(dictTypes[0], dictTypes[1])) as IDictionary;

            BjSJsonArray kvp;

            foreach (object o in array)
            {
                if (!(o is BjSJsonArray) || (o as BjSJsonArray).Count < 2)
                {
                    continue;
                }
                kvp = o as BjSJsonArray;
                if (!JsonTypeEquals(dictTypes[0], kvp[0].GetType()))
                {
                    continue;
                }
                result.Add(FromJsonValue(kvp[0], dictTypes[0]), FromJsonValue(kvp[1], dictTypes[1]));
            }

            return(result);
        }