示例#1
0
        /************************************************************************/
        public static IList <T> ToList <T>(this DataTable table, bool dispose = true) where T : new()
        {
            DataSourceList dataSource = DataSourceList.Create(table);

            IList <T> list = dataSource.ToList <T>();

            if (dispose)
            {
                table.Dispose();
            }

            return(list);
        }
示例#2
0
        public void Mondo_Common_IDataObjectSource_ToList()
        {
            string         xml    = "<Data><Car><Make>Aston Martin</Make><Model>DB9</Model><Year>1965</Year><Color>Blue</Color></Car><Car><Make>Audi</Make><Model>A4</Model><Year>1973</Year><Color>Green</Color></Car></Data>";
            XmlDocument    xmlDoc = XmlDoc.LoadXml(xml);
            DataSourceList ds     = DataSourceList.Create(xmlDoc);

            IList <TestClass2> list = ds.ToList <TestClass2>();
            TestClass2         obj  = list[0];

            Assert.AreEqual("Aston Martin", obj.Make);
            Assert.AreEqual("DB9", obj.Model);
            Assert.AreEqual(1965, obj.Year);
            Assert.AreEqual("Blue", obj.Color);
            Assert.AreEqual(false, obj.NumDoors.HasValue);

            obj = list[1];

            Assert.AreEqual("Audi", obj.Make);
            Assert.AreEqual("A4", obj.Model);
            Assert.AreEqual(1973, obj.Year);
            Assert.AreEqual("Green", obj.Color);
            Assert.AreEqual(false, obj.NumDoors.HasValue);
        }