Exemplo n.º 1
0
        protected virtual Parse buildCells(object row)
        {
            if (row == null)
            {
                Parse nil = new Parse("td", "null", null, null);
                nil.addToTag(" colspan=" + columnBindings.Length);
                return(nil);
            }
            Parse root = new Parse(null, null, null, null);
            Parse next = root;

            for (int i = 0; i < columnBindings.Length; i++)
            {
                next = next.more = new Parse("td", "&nbsp;", null, null);
                TypeAdapter a = columnBindings[i];
                if (a == null)
                {
                    ignore(next);
                }
                else
                {
                    try {
                        a.target = row;
                        info(next, a.get().ToString());
                    }
                    catch (Exception e) {
                        exception(next, e);
                    }
                }
            }
            return(root.more);
        }
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
        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.º 4
0
        protected virtual Hashtable cSort(ArrayList list, int col)
        {
            TypeAdapter a      = columnBindings[col];
            Hashtable   result = new Hashtable();

            foreach (object row in list)
            {
                try {
                    a.target = row;
                    object key = a.get();
                    bin(result, key, row);
                }
                catch (Exception) {
                    // surplus anything with bad keys, including null
                    surplus.Add(row);
                }
            }
            return(result);
        }
Exemplo n.º 5
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.º 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);
         }
     }
 }