コード例 #1
0
        private DatasetSchema GetSchema(DataSet ds)
        {
            if (ds == null)
            {
                return(null);
            }

            DatasetSchema m = new DatasetSchema();

            m.Info = new List <string>();
            m.Name = ds.DataSetName;

            foreach (DataTable t in ds.Tables)
            {
                foreach (DataColumn c in t.Columns)
                {
                    m.Info.Add(t.TableName);
                    m.Info.Add(c.ColumnName);
                    m.Info.Add(c.DataType.ToString());
                }
            }
            // FEATURE : serialize relations and constraints here

            return(m);
        }
コード例 #2
0
ファイル: JSON.cs プロジェクト: xiaopohou/Magicodes.Sms
        private DataSet CreateDataset(Dictionary <string, object> reader, Dictionary <string, object> globalTypes)
        {
            DataSet ds = new DataSet();

            ds.EnforceConstraints = false;
            ds.BeginInit();

            // read dataset schema here
            var schema = reader["$schema"];

            if (schema is string)
            {
                TextReader tr = new StringReader((string)schema);
                ds.ReadXmlSchema(tr);
            }
            else
            {
                DatasetSchema ms = (DatasetSchema)ParseDictionary((Dictionary <string, object>)schema, globalTypes, typeof(DatasetSchema), null);
                ds.DataSetName = ms.Name;
                for (int i = 0; i < ms.Info.Count; i += 3)
                {
                    if (ds.Tables.Contains(ms.Info[i]) == false)
                    {
                        ds.Tables.Add(ms.Info[i]);
                    }
                    ds.Tables[ms.Info[i]].Columns.Add(ms.Info[i + 1], Type.GetType(ms.Info[i + 2]));
                }
            }

            foreach (KeyValuePair <string, object> pair in reader)
            {
                if (pair.Key == "$type" || pair.Key == "$schema")
                {
                    continue;
                }

                List <object> rows = (List <object>)pair.Value;
                if (rows == null)
                {
                    continue;
                }

                DataTable dt = ds.Tables[pair.Key];
                ReadDataTable(rows, dt);
            }

            ds.EndInit();

            return(ds);
        }
コード例 #3
0
ファイル: JsonSerializer.cs プロジェクト: fengxianqi/Youbang
        private DatasetSchema GetSchema(DataSet ds)
        {
            if (ds == null) return null;

            DatasetSchema m = new DatasetSchema();
            m.Info = new List<string>();
            m.Name = ds.DataSetName;

            foreach (DataTable t in ds.Tables)
            {
                foreach (DataColumn c in t.Columns)
                {
                    m.Info.Add(t.TableName);
                    m.Info.Add(c.ColumnName);
                    m.Info.Add(c.DataType.ToString());
                }
            }
            // FEATURE : serialize relations and constraints here

            return m;
        }