Exemplo n.º 1
0
        public override void doCell(Parse cell, int column)
        {
            TypeAdapter a = columnBindings[column];

            try {
                string text = cell.text();
                if (text == "")
                {
                    check(cell, a);
                }
                else if (a == null)
                {
                    ignore(cell);
                }
                else if (a.field != null)
                {
                    a.set(a.parse(text));
                }
                else if (a.method != null)
                {
                    check(cell, a);
                }
            }
            catch (Exception e) {
                exception(cell, e);
            }
        }
Exemplo n.º 2
0
        public void TestTypeAdapter()
        {
            TypeAdapterTarget target    = new TypeAdapterTarget();
            TypeAdapter       adapter   = TypeAdapter.on(target, typeof(int));
            object            parsedInt = adapter.parse("123");

            Assert.AreEqual(123, (int)parsedInt, "int");
            Assert.IsTrue(adapter.equals(parsedInt, 123), "int should be equal");

            adapter = TypeAdapter.on(target, typeof(float));
            Assert.AreEqual(12.3, (float)adapter.parse("12.3"), .00001, "float");

            adapter = TypeAdapter.on(target, typeof(long));
            Assert.AreEqual(123L, (long)adapter.parse("123"), "long");

            adapter = TypeAdapter.on(target, typeof(string));
            Assert.AreEqual("123", (string)adapter.parse("123"), "string");

            adapter = TypeAdapter.on(target, typeof(string[]));
            AssertArraysEqual(new object[] { "1", "2", "3" }, (object[])adapter.parse("1,2,3"), "string[]");
            Assert.AreEqual("1,2,3", adapter.ToString(new string[] { "1", "2", "3" }));

            adapter = TypeAdapter.on(target, typeof(int[]));
            AssertArraysEqual(new object[] { 1, 2, 3 }, (object[])adapter.parse("1,2,3"), "int[]");
            Assert.AreEqual("1,2,3", adapter.ToString(new int[] { 1, 2, 3 }));

            MethodInfo twoPi = typeof(TypeAdapterTarget).GetMethod("twoPi");

            adapter = TypeAdapter.on(target, twoPi);
            Assert.AreEqual(2 * Math.PI, adapter.get(), "twoPi");

            FieldInfo pi = target.GetType().GetField("pi");

            adapter = TypeAdapter.on(target, pi);
            adapter.set(3);
            Assert.AreEqual(3, target.pi, .00001, "pi");
            Assert.AreEqual(3, (double)adapter.get(), .00001, "adapted pi");
        }
Exemplo n.º 3
0
        public void testTypeAdapter()
        {
            TestFixture f = new TestFixture();
            TypeAdapter a = TypeAdapter.on(f, f.GetType().GetField("sampleInt"));

            a.set(a.parse("123456"));
            Assert.AreEqual(123456, f.sampleInt);
            Assert.AreEqual("-234567", a.parse("-234567").ToString());
            a = TypeAdapter.on(f, f.GetType().GetMethod("pi", new Type[] {}));
            Assert.AreEqual(3.14159, (double)a.get(), 0.00001);
            a = TypeAdapter.on(f, f.GetType().GetField("ch"));
            a.set(a.parse("a"));
            Assert.AreEqual('a', f.ch);
            a = TypeAdapter.on(f, f.GetType().GetField("name"));
            a.set(a.parse("xyzzy"));
            Assert.AreEqual("xyzzy", f.name);
            a = TypeAdapter.on(f, f.GetType().GetField("sampleFloat"));
            a.set(a.parse("6.02e23"));
            Assert.AreEqual(6.02e23, f.sampleFloat, 1e17);
            //      a = TypeAdapter.on(f, f.GetType().GetField("sampleArray"));
            //      a.set(a.parse("1,2,3"));
            //      Assert.AreEqual(1, f.sampleArray[0]);
            //      Assert.AreEqual(2, f.sampleArray[1]);
            //      Assert.AreEqual(3, f.sampleArray[2]);
            //      Assert.AreEqual("1,2,3", f.sampleArray.ToString());
            //      Assert.AreEqual(new int[] {1, 2, 3}, f.sampleArray);
            //      a = TypeAdapter.on(f, f.GetType().GetField("sampleDate"));
            //      DateTime date = new DateTime(1949,4,26);
            //      a.set(a.parse(DateFormat.getDateInstance().format(date)));
            //      Assert.AreEqual(date, f.sampleDate);
            a = TypeAdapter.on(f, f.GetType().GetField("sampleByte"));
            a.set(a.parse("123"));
            Assert.AreEqual((byte)123, f.sampleByte);
            a = TypeAdapter.on(f, f.GetType().GetField("sampleShort"));
            a.set(a.parse("12345"));
            Assert.AreEqual((short)12345, f.sampleShort);
        }