コード例 #1
0
ファイル: Program.cs プロジェクト: lanicon/DynamicObjects
        private static void ImportTableCsvFile()
        {
            IDynamicTable table = new DynamicTable(DynamicTableType.Expandable);

            //pre define columns
            table.PreDefineColumns(
                new List <IDynamicTableColumn>()
            {
                new DynamicTableColumn <string>("FirstName"),
                new DynamicTableColumn <string>("LastName"),
                new DynamicTableColumn <int>("Age"),
                new DynamicTableColumn <string>("Street")
            });

            //import
            using (StreamReader reader = new StreamReader("test.csv"))
            {
                table.FromCsv(ReadFile(reader));
            }

            foreach (dynamic actualRow in table.Rows)
            {
                Console.WriteLine(
                    string.Format("{0} {1} is {2} years old.",
                                  actualRow.FirstName,
                                  actualRow.LastName,
                                  actualRow.Age));
            }
        }
コード例 #2
0
        public void UseTable_PreDefinedColumns_Expandeable()
        {
            IDynamicTable table = new DynamicTable(DynamicTableType.Expandable);
            dynamic       row;

            //set columns
            table.PreDefineColumns(
                new List <IDynamicTableColumn>()
            {
                new DynamicTableColumn <string>("FirstName", ""),
                new DynamicTableColumn <string>("LastName"),
                new DynamicTableColumn <int>("Age", -1)
            });

            //add values
            row           = new ExpandoObject();
            row.FirstName = "Hans";
            row.LastName  = "Mueller";
            row.Age       = 30;
            table.AddRow(row);

            row          = new ExpandoObject();
            row.LastName = "Meier";
            row.Street   = "Main street";
            table.AddRow(row);

            //compare
            Assert.AreEqual(2, table.Rows.Count);
            Assert.AreEqual(4, table.Columns.Count);

            row = table.Rows[0];
            Assert.AreEqual("Hans", row.FirstName);
            Assert.AreEqual("Mueller", row.LastName);
            Assert.AreEqual(30, row.Age);
            Assert.AreEqual(null, row.Street);

            row = table.Rows[1];
            Assert.AreEqual("", row.FirstName);
            Assert.AreEqual("Meier", row.LastName);
            Assert.AreEqual(-1, row.Age);
            Assert.AreEqual("Main street", row.Street);
        }
コード例 #3
0
        public void UseTable_PreDefinedColumns_WellFormet()
        {
            IDynamicTable table = new DynamicTable(DynamicTableType.WellFormed);
            dynamic       row;

            //set columns
            table.PreDefineColumns(
                new List <IDynamicTableColumn>()
            {
                new DynamicTableColumn <string>("FirstName"),
                new DynamicTableColumn <string>("LastName"),
                new DynamicTableColumn <int>("Age", 100)
            });

            //add values
            row           = new ExpandoObject();
            row.FirstName = "Hans";
            row.LastName  = "Mueller";
            row.Age       = 30;
            table.AddRow(row);

            row           = new ExpandoObject();
            row.FirstName = "Sarah";
            row.LastName  = "Meier";
            row.Age       = 50;
            table.AddRow(row);

            //compare
            Assert.AreEqual(2, table.Rows.Count);
            Assert.AreEqual(3, table.Columns.Count);

            row = table.Rows[0];
            Assert.AreEqual("Hans", row.FirstName);
            Assert.AreEqual("Mueller", row.LastName);
            Assert.AreEqual(30, row.Age);

            row = table.Rows[1];
            Assert.AreEqual("Sarah", row.FirstName);
            Assert.AreEqual("Meier", row.LastName);
            Assert.AreEqual(50, row.Age);
        }