标签:des com class blog http code div img java style javascript
原理:
在实体类变更前对其进行备份,调用Newtonsoft.Json下的序列化方法将其存储成json格式,并在需要时调用反序列化方法,转化成实体类
public static class TestEntityChange { //实体备份方法,在实体为修改前进行备份 public static void EntityCopy<T>(this T t, Guid relid) { var test = new TestPropertyChangeLog(); test.Relid = relid; test.Data = JsonConvert.SerializeObject(t); test.Create(); } //将Json格式的数据转化成相应的实体 public static T GetEntityCopy<T>(Guid relid) { var entity = TestPropertyChangeLog.GetAll().Find(x => x.Relid == relid); T a = (T)JsonConvert.DeserializeObject(entity.Data, typeof(T)); return a; } }
在页面调用GetEntityCopy方法:
TestA a = TestEntityChange.GetEntityCopy<TestA>(new Guid(EntityId));
对实体字段是否修改未作判断,待扩展!
标签:des com class blog http code div img java style javascript
原文地址:http://www.cnblogs.com/seth/p/3695222.html