Пример #1
0
 public override JObject ToJson(DateTime obj, ConvertorSet convertorSet)
 {
     return(new JObject
     {
         { ConstString.Value, obj.ToString("o") }
     });
 }
 public override JObject ToJson(string obj, ConvertorSet convertorSet)
 {
     return(new JObject
     {
         { ConstString.Value, obj }
     });
 }
Пример #3
0
 public override JObject ToJson(IIndex <string> obj, ConvertorSet convertorSet)
 {
     return(new JObject
     {
         { ConstString.Values, new JArray(obj.Keys.ToList()) }
     });
 }
        public override JObject ToJson(IDictionary obj, ConvertorSet convertorSet)
        {
            var dict = new Dictionary <string, object>();

            foreach (string key in obj.Keys.Cast <string>())
            {
                object value = obj[key];
                dict.Add(key, value);
            }
            return(ToJson(dict, convertorSet));
        }
        public override IDictionary FromJson(JObject jobj, ConvertorSet convertorSet)
        {
            var result = new Dictionary <string, object>();

            foreach (KeyValuePair <string, JToken> pair in (JObject)jobj[ConstString.Values])
            {
                string  key   = pair.Key;
                JObject value = pair.Value as JObject;
                result[key] = convertorSet.FromJson(value);
            }
            return(result);
        }
        public override JObject ToJson(IEnumerable obj, ConvertorSet convertorSet)
        {
            var items = new JArray();

            foreach (object o in obj)
            {
                items.Add(convertorSet.ToJson(o));
            }

            return(new JObject
            {
                { ConstString.Values, items }
            });
        }
        public JObject ToJson(Dictionary <string, object> obj, ConvertorSet convertorSet)
        {
            var items = new JObject();

            foreach (KeyValuePair <string, object> pair in obj)
            {
                string key   = pair.Key;
                object value = pair.Value;
                items[key] = convertorSet.ToJson(value);
            }
            return(new JObject
            {
                { ConstString.Values, items }
            });
        }
        public override JObject ToJson(Array obj, ConvertorSet convertorSet)
        {
            int nDimensions = obj.Rank;

            int[] shape = new int[nDimensions];
            for (int i = 0; i < nDimensions; ++i)
            {
                shape[i] = obj.GetLength(i);
            }
            double[] items = obj.Cast <double>().ToArray();
            return(new JObject
            {
                { ConstString.Shape, new JArray(shape) },
                { ConstString.Values, new JArray(items) }
            });
        }
        public override Array FromJson(JObject jobj, ConvertorSet convertorSet)
        {
            int[]    shape  = jobj[ConstString.Shape].ToObject <int[]>();
            double[] values = jobj[ConstString.Values].ToObject <double[]>();
            var      arr    = Array.CreateInstance(typeof(double), shape);

            int[] index = new int[shape.Length];
            for (int i = 0; i < values.Length; ++i)
            {
                arr.SetValue(values[i], index);
                if (!Multidimensional.IncIndex(index, shape))
                {
                    break;
                }
            }
            return(arr);
        }
Пример #10
0
        public override IFrame FromJson(JObject jobj, ConvertorSet convertorSet)
        {
            object index   = convertorSet.FromJson((JObject)jobj[ConstString.Index]);
            object columns = convertorSet.FromJson((JObject)jobj[ConstString.Columns]);

            object[] data = jobj[ConstString.Data].ToObject <object[]>();

            Type             indexType  = index.GetType().GetGenericArguments()[0];
            Type             columnType = columns.GetType().GetGenericArguments()[0];
            Frame <int, int> foo;

            return(null);
            //var rows = new List<KeyValuePair<int, Series<int, object>>>();
            //foreach (var row in index)
            //{
            //    IIndex<int>
            //    rows.Add(KeyValuePair.Create());
            //}

            //var frame = Frame.FromRows(rows);
            //return frame;
        }
 public override object ObjectFromJson(JObject jobj, ConvertorSet convertorSet) => FromJson(jobj, convertorSet);
 public abstract T FromJson(JObject jobj, ConvertorSet convertorSet);
 public override JObject ToJson(object obj, ConvertorSet convertorSet) => obj is T?ToJson((T)obj, convertorSet) : null;
 public abstract JObject ToJson(T obj, ConvertorSet convertorSet);
Пример #15
0
        public override DateTime FromJson(JObject jobj, ConvertorSet convertorSet)
        {
            string dateString = jobj.GetValue(ConstString.Value).Value <string>();

            return(DateTime.Parse(dateString));
        }
 public override string FromJson(JObject jobj, ConvertorSet convertorSet)
 {
     return(jobj.GetValue(ConstString.Value).Value <string>());
 }
 public override IEnumerable FromJson(JObject jobj, ConvertorSet convertorSet)
 {
     return((from token in (JArray)jobj[ConstString.Values] select token as JObject into value select convertorSet.FromJson(value)).ToList());
 }
Пример #18
0
 public override IIndex <string> FromJson(JObject jobj, ConvertorSet convertorSet)
 {
     string[] values = jobj[ConstString.Values].ToObject <string[]>();
     return(Index.Create(values));
 }
Пример #19
0
        public override JObject ToJson(IFrame obj, ConvertorSet convertorSet)
        {
            dynamic frame = obj;

            return(ToJson2(frame, convertorSet));
        }
Пример #20
0
        private static JObject ToJson2 <TRowKey, TColumnKey>(Frame <TRowKey, TColumnKey> frame, ConvertorSet convertorSet)
        {
            var           index   = convertorSet.ToJson(frame.RowIndex);
            var           columns = convertorSet.ToJson(frame.ColumnIndex);
            List <object> data    = new List <object>();

            for (int i = 0; i < frame.RowCount; ++i)
            {
                for (int j = 0; j < frame.ColumnCount; ++j)
                {
                    data.Add(frame.GetColumnAt <object>(j).GetAt(i));
                }
            }
            var dataArray = new JArray(data);

            return(new JObject
            {
                { ConstString.Index, index },
                { ConstString.Columns, columns },
                { ConstString.Data, dataArray }
            });
        }