public void TestApply() { var obj1 = new { Test = "XXX" }; var obj2 = new { Value = 15.5m }; DynamicObject viewData1 = new DynamicObject(obj1); DynamicObject viewData2 = new DynamicObject(obj2); DynamicObject viewData = new DynamicObject(); viewData.Apply(viewData1); viewData.Apply(viewData2); object value; Type type; Assert.AreEqual("XXX", viewData["Test"]); Assert.AreEqual(15.5m, viewData["Value"]); Assert.IsTrue(viewData.TryGetValue("Test", out value, out type)); Assert.IsInstanceOfType(typeof(string), value); Assert.AreEqual(typeof(string), type); Assert.AreEqual("XXX", value); Assert.IsTrue(viewData.TryGetValue("Value", out value, out type)); Assert.IsInstanceOfType(typeof(decimal), value); Assert.AreEqual(typeof(decimal), type); Assert.AreEqual(15.5m, value); Assert.IsFalse(viewData.TryGetValue("Test2", out value, out type)); Assert.IsFalse(viewData.TryGetValue("Value2", out value, out type)); }
public void TestApply() { var obj1 = new { Test = "XXX" }; var obj2 = new { Value = 15.5m }; DynamicObject viewData1 = new DynamicObject(obj1); DynamicObject viewData2 = new DynamicObject(obj2); DynamicObject viewData = new DynamicObject(); viewData.Apply(viewData1); viewData.Apply(viewData2); object value; Type type; Assert.AreEqual("XXX", viewData["Test"]); Assert.AreEqual(15.5m, viewData["Value"]); Assert.IsTrue(viewData.TryGetValue("Test", out value, out type)); Assert.IsInstanceOfType(value, typeof(string)); Assert.AreEqual(typeof(string), type); Assert.AreEqual("XXX", value); Assert.IsTrue(viewData.TryGetValue("Value", out value, out type)); Assert.IsInstanceOfType(value, typeof(decimal)); Assert.AreEqual(typeof(decimal), type); Assert.AreEqual(15.5m, value); Assert.IsFalse(viewData.TryGetValue("Test2", out value, out type)); Assert.IsFalse(viewData.TryGetValue("Value2", out value, out type)); }
public void DynObject() { DynamicObject dynObj = new DynamicObject(); dynObj.Apply(new DataClass(5)); CSharpContext context = new CSharpContext(dynObj); Assert.AreEqual(2, _parser.Evaluate <int>("Method0()", context)); Assert.AreEqual(21, _parser.Evaluate <int>("Method0() + Method1(5) + Method2(Int1,4)", context)); }
public void DynObject() { DynamicObject dynObj = new DynamicObject(); dynObj.Apply(new DataClass(5)); CSharpContext context = new CSharpContext(dynObj); Assert.AreEqual(2, _parser.Evaluate<int>("Method0()",context)); Assert.AreEqual(21, _parser.Evaluate<int>("Method0() + Method1(5) + Method2(Int1,4)", context)); }