public void GenerateType_Interface() { ProxyGenerator proxy = new ProxyGenerator("XLY.Framework.UnitTest", "XLY.Framework.UnitTest.ConfigInfo"); proxy.InheritInterface <IA>(); var type = proxy.GenerateType(); IA obj = Activator.CreateInstance(type) as IA; Assert.IsNotNull(obj); obj.Name = "xiaoming"; var vname = System.Utility.Helper.Reflection.GetObjectValue(obj, "Name"); Assert.IsTrue(vname == "xiaoming"); obj.Birthdy = DateTime.Now; obj.Died = new DateTime(1986, 11, 15); Assert.IsTrue(obj.Died == new DateTime(1986, 11, 15)); //---console Console.WriteLine("Name:" + obj.Name); Console.WriteLine("Code:" + obj.Code); Console.WriteLine("Age:" + obj.Age); Console.WriteLine("Birthdy:" + TypeExtension.ToDateTimeString(obj.Birthdy)); Console.WriteLine("Died:" + TypeExtension.ToDateTimeString(obj.Died)); }
public void GenerateType_Interface_Set() { ProxyGenerator proxy = new ProxyGenerator("Test", "TestClass"); proxy.InheritInterface <IGS>(); var type = proxy.GenerateType(); var obj = type.CreateInstance() as IGS; dynamic dobj = obj; dobj.Birthday = DateTime.Now; Console.WriteLine("dobj.Birthday:" + TypeExtension.ToDateTimeString(dobj.Birthday)); dobj.Age = 122; Console.WriteLine(dobj.Age); }
public void GenerateType_Interface_Get() { ProxyGenerator proxy = new ProxyGenerator("Test", "TestClass"); proxy.InheritInterface <IGS>(); var type = proxy.GenerateType(); var obj = type.CreateInstance() as IGS; Assert.IsNotNull(obj); Assert.IsNull(obj.Name); obj.Birthday = DateTime.Now; Console.WriteLine("dobj.Birthday:" + TypeExtension.ToDateTimeString(obj.Birthday)); dynamic dobj = obj; dobj.Name = "123;"; }
public void GenerateType_ConfigInfo() { ProxyGenerator proxy = new ProxyGenerator("XLY.Framework.UnitTest", "XLY.Framework.UnitTest.ConfigInfo"); proxy.AppendProperty("Name", typeof(string)); proxy.AppendProperty("Code", typeof(EnumEncodingType)); proxy.AppendProperty("Age", typeof(int)); proxy.AppendProperty("Birthdy", typeof(DateTime)); proxy.AppendProperty("Died", typeof(DateTime?)); var type = proxy.GenerateType(); var obj = Activator.CreateInstance(type); System.Utility.Helper.Reflection.SettingObjectValue(obj, "Name", "xiaoming"); var vname = System.Utility.Helper.Reflection.GetObjectValue(obj, "Name"); Assert.IsTrue(vname == "xiaoming"); System.Utility.Helper.Reflection.SettingObjectValue(obj, "Code", EnumEncodingType.GB2312); dynamic dobj = obj; Assert.IsTrue(dobj.Code == EnumEncodingType.GB2312); dobj.Age = 33; var vage = System.Utility.Helper.Reflection.GetObjectValue(dobj, "Age"); Assert.IsTrue(vage == 33); var now = DateTime.Now; dobj.Birthdy = now; Assert.IsTrue(dobj.Birthdy == now); //died System.Utility.Helper.Reflection.SettingObjectValue(obj, "Died", new DateTime(1986, 11, 15)); var vdied = (DateTime)System.Utility.Helper.Reflection.GetObjectValue(obj, "Died"); Assert.IsTrue(vdied == new DateTime(1986, 11, 15)); //---console Console.WriteLine("Name:" + dobj.Name); Console.WriteLine("Code:" + dobj.Code); Console.WriteLine("Age:" + dobj.Age); Console.WriteLine("Birthdy:" + TypeExtension.ToDateTimeString(dobj.Birthdy)); Console.WriteLine("Died:" + TypeExtension.ToDateTimeString(dobj.Died)); }