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); } } }
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"); }
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); } } }