コード例 #1
0
        public void Customer2()
        {
            var record = new[]
            {
                new KeyValuePair <string, object>("Id", 1),
                new KeyValuePair <string, object>("Name", "Rafa"),
                new KeyValuePair <string, object>("Type", null),
                new KeyValuePair <string, object>("Type2", 1),
                new KeyValuePair <string, object>("Dir1_Street", "Frida Kahlo"),
                new KeyValuePair <string, object>("Dir1_Personal_Phone", "555 555"),
                new KeyValuePair <string, object>("Dir1_Personal_Cellphone", "01 23 45"),
                new KeyValuePair <string, object>("Date", new DateTime(2000, 02, 03)),
                new KeyValuePair <string, object>("NullStr", DBNull.Value),
            };

            var reader = new DicDataReader(new[] { record });
            var mapper = DbMapper.CreateReader <DicDataReader, Customer2>(reader);

            var items = mapper(reader);
            var curr  = items.First();

            Assert.AreEqual(1, curr.Id);
            Assert.AreEqual("Rafa", curr.Name);
            Assert.AreEqual("Frida Kahlo", curr.Dir1.Street);
            Assert.AreEqual("555 555", curr.Dir1.Personal.Phone);
            Assert.AreEqual("01 23 45", curr.Dir1.Personal.Cellphone);
            Assert.AreEqual(new DateTime(2000, 02, 03), curr.Date);
            Assert.AreEqual(null, curr.Type);
            Assert.AreEqual(CustomerType.Other, curr.Type2);
            Assert.AreEqual(null, curr.NullStr);
        }
コード例 #2
0
        public void SingleObjectTest()
        {
            var record = new[]
            {
                new KeyValuePair <string, object>("Value", 1),
            };

            var reader = new DicDataReader(new[] { record });
            var mapper = DbMapper.CreateReader <DicDataReader, object>(reader);

            var items = mapper(reader);
            var ret   = items.First();

            Assert.AreEqual(1, ret);
        }
コード例 #3
0
        public void ObjectTest()
        {
            var record = new[]
            {
                new KeyValuePair <string, object>("Value", 1),
                new KeyValuePair <string, object>("Description", "Rafa"),
                new KeyValuePair <string, object>("IsNull", null),
                new KeyValuePair <string, object>("DbNull", DBNull.Value),
            };

            var reader = new DicDataReader(new[] { record });
            var mapper = DbMapper.CreateReader <DicDataReader, ObjTest>(reader);

            var items = mapper(reader);
            var ret   = items.First();

            Assert.AreEqual(1, ret.Value);
            Assert.AreEqual("Rafa", ret.Description);
            Assert.AreEqual(null, ret.IsNull);
            Assert.AreEqual(null, ret.DbNull);
        }
コード例 #4
0
        public void SimpleILTest()
        {
            var records = new[]
            {
                new []
                {
                    new KeyValuePair <string, object>("Id", 1),
                    new KeyValuePair <string, object>("Name", "Rafa"),
                    new KeyValuePair <string, object>("Age", 25),
                },
                new []
                {
                    new KeyValuePair <string, object>("Id", 2),
                    new KeyValuePair <string, object>("Name", "Ale"),
                    new KeyValuePair <string, object>("Age", null),
                },
            };
            var reader  = new DicDataReader(records);
            var t       = typeof(Customer1);
            var rt      = typeof(DicDataReader);
            var mapping = new CtorMapping(
                t.GetConstructor(new Type[0]),
                new ValueMapping[0],
                new Dictionary <PropertyInfo, ValueMapping>
            {
                { t.GetProperty("Id"), new SingularMapping(typeof(int), 0) },
                { t.GetProperty("Name"), new SingularMapping(typeof(string), 1) },
                { t.GetProperty("Age"), new SingularMapping(typeof(int?), 2) }
            }
                );

            var method = Sql2Sql.Mapper.ILCtors.ILCtorLogic.GenerateReaderMethod <DicDataReader, Customer1>(mapping);
            var comp   = method.Compile();

            var call = comp(reader);
        }