示例#1
0
        public PropertyMap(ReaderMap readerMap, Type type)
        {
            int len = readerMap.Count;

            Count = len;
            var ps = type.GetProperties();

            properties = new PropertyInfo[len];
            for (int i = 0; i < len; i++)
            {
                var readerItem = readerMap[i];
                var tp         = ps.FirstOrDefault(p => p.Name.ToUpper() == readerItem.Name.ToUpper());
                if (tp != null)
                {
                    if (tp.PropertyType.IsAssignableFrom(readerItem.Type))
                    {
                        properties[i] = tp;
                    }
                }
            }
        }
示例#2
0
        public void TestGetSetter()
        {
            List <Book> result = new List <Book>();
            string      sql    = "select * from book";
            //SQLiteCommand command = new SQLiteCommand(sql, conn);
            var factory    = DbProviderFactories.GetFactory("");
            var connection = factory.CreateConnection();

            var command = factory.CreateCommand();

            command.CommandText = sql;
            command.Connection  = connection;
            var reader      = command.ExecuteReader();
            var readerMap   = new ReaderMap(reader);
            var propertyMap = new PropertyMap(readerMap, typeof(Book));

            var func = GetSetter <Book>(reader, propertyMap);

            while (reader.Read())
            {
                Book r = (Book)func(reader);
                result.Add(r);
            }
        }