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 virtual void check(Parse cell, TypeAdapter a)
        {
            string text = cell.text();

            if (text == "")
            {
                try {
                    info(cell, a.ToString(a.get()));
                }
                catch (Exception) {
                    info(cell, "error");
                }
            }
            else if (a == null)
            {
                ignore(cell);
            }
            else if (text == "error")
            {
                try {
                    wrong(cell, a.ToString(a.get()));
                }
                catch (MethodAccessException e) {
                    exception(cell, e);
                }
                catch (Exception) {
                    right(cell);
                }
            }
            else
            {
                try {
                    object result = a.get();
                    if (a.equals(a.parse(text), result))
                    {
                        right(cell);
                    }
                    else
                    {
                        wrong(cell, a.ToString(a.get()));
                    }
                }
                catch (Exception e) {
                    exception(cell, e);
                }
            }
        }
Exemplo n.º 3
0
        protected virtual Hashtable eSort(ArrayList list, int col)
        {
            TypeAdapter a      = columnBindings[col];
            Hashtable   result = new Hashtable();

            foreach (Parse row in list)
            {
                Parse cell = row.parts.at(col);
                try {
                    object key = a.parse(cell.text());
                    bin(result, key, row);
                }
                catch (Exception e) {
                    exception(cell, e);
                    for (Parse rest = cell.more; rest != null; rest = rest.more)
                    {
                        ignore(rest);
                    }
                }
            }
            return(result);
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
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.º 6
0
 public virtual void check(Parse cell, TypeAdapter a)
 {
     string text = cell.text();
     if (text == "") {
         try {
             info(cell, a.ToString(a.get()));
         }
         catch (Exception) {
             info(cell, "error");
         }
     }
     else if (a == null) {
         ignore(cell);
     }
     else if (text == "error") {
         try {
             wrong(cell, a.ToString(a.get()));
         }
         catch (MethodAccessException e) {
             exception (cell, e);
         }
         catch (Exception) {
             right(cell);
         }
     }
     else {
         try {
             object result = a.get();
             if (a.equals(a.parse(text), result)) {
                 right(cell);
             }
             else {
                 wrong(cell, a.ToString(a.get()));
             }
         }
         catch (Exception e) {
             exception(cell, e);
         }
     }
 }