public void TestEntityAlias() { DataObjectModel obj = new DataObjectModel(); obj.Property = "temp"; string s = "TestAlias"; EntityTools <DataObjectModel> .SetValueString(obj, "Prop", false, s); Assert.AreEqual(s, obj.Property); string v = EntityTools <DataObjectModel> .GetValueString(obj, "prop", true); Assert.AreEqual(s, v); }
public void TestString() { DataObjectModel obj = new DataObjectModel(); obj.CreateTime = DateTime.Parse("2010-09-18"); DateTime i = DateTime.Parse("2012-2-1"); EntityTools <DataObjectModel> .SetValueString(obj, "CreateTime", false, "2012-2-1"); Assert.AreEqual(i, obj.CreateTime); string s = EntityTools <DataObjectModel> .GetValueString(obj, "CreateTime", true); Assert.AreEqual(s, obj.CreateTime.ToString()); }
private void GetSet(bool ignoreCase) { var obj = new DataObjectModel(); IDataObject objIDataObject = obj as IDataObject; object glocalInstance = obj; string propertyName = "Name"; var func = (Func <DataObjectModel, string>)Delegate.CreateDelegate(typeof(Func <DataObjectModel, string>), typeof(DataObjectModel).GetMethod("get_Name")); TestCase tester = new TestCase(); tester.Watcher = (i, name, sw) => { Trace.WriteLine(string.Format("{0}:{1}", name, sw.Elapsed)); }; tester.Build("直接调用时", () => { obj.NameField = obj.Name; }); tester.Build("委托调用时", () => { var value = func(obj); }); tester.Build("接口调用时", () => { objIDataObject.SetValue(propertyName, ignoreCase, objIDataObject.GetValue(propertyName, ignoreCase)); }); tester.Build("工具调用时", () => { EntityTools <DataObjectModel> .SetValue(obj, propertyName, ignoreCase, EntityTools <DataObjectModel> .GetValue(obj, propertyName, ignoreCase)); }); tester.Build("字符串工具", () => { EntityTools <DataObjectModel> .SetValueString(obj, propertyName, ignoreCase, EntityTools <DataObjectModel> .GetValueString(obj, propertyName, ignoreCase)); }); tester.Build("虚接口调用", () => { obj.SetEntityValue(propertyName, ignoreCase, obj.GetEntityValue(propertyName, ignoreCase)); }); tester.StepWatcher = i => { Trace.WriteLine(string.Format("执行{0:###,###,###}次的结果: ", i)); }; int times = 10000; tester.Execute(1000 * times); }