日期:2014-05-17 浏览次数:20945 次
public class oddsRecoder : ICloneable, IDisposable { private bool bool_0; private string _guid = string.Empty; public IDictionary<string, IDictionary<string, IDictionary<string, string>>> dictionary = new Dictionary<string, IDictionary<string, IDictionary<string, string>>>(); private IDictionary<string, dic_PlayData> DataCollection = new Dictionary<string, dic_PlayData>(); public object Clone() { try { MemoryStream serializationStream = new MemoryStream(); BinaryFormatter formatter = new BinaryFormatter(); formatter.Serialize(serializationStream, this); serializationStream.Position = 0L; Thread.GetDomain().AssemblyResolve += new ResolveEventHandler(this.m0000ca); object obj2 = formatter.Deserialize(serializationStream); Thread.GetDomain().AssemblyResolve -= new ResolveEventHandler(this.m0000ca); return obj2; } catch (Exception ex) { Console.Write(ex.Message); Log.a(ex, 1000); } return null; } public void Dispose() { this.m000075(true); GC.SuppressFinalize(this); }
static List<FieldInfo> GetSettableFields(Type t) { return t.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance).ToList(); } //暂时只能支持简单类的克隆,也就是类的内部只有基础类型。 static Func<object, object> CreateCloneMethod(Type type) { var fields = GetSettableFields(type); var dm = new DynamicMethod(string.Format("Clone{0}", Guid.NewGuid()), typeof(object), new[] { typeof(object) }, true); var il = dm.GetILGenerator(); il.DeclareLocal(type); il.DeclareLocal(type); il.Emit(OpCodes.Newobj, type.GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, Type.EmptyTypes, null)); il.Emit(OpCodes.Dup); il.Emit(OpCodes.Stloc_