public static object Clone(object instance) { if (instance == null) { return(null); } else { var type = instance.GetType(); if (type.IsSimpleType()) { return(instance); } else if (type == typeof(object)) { return(new object()); } else { var func = CloneMapping.GetValue(type); if (func == default) { func = ObjectCloneBuilder.Create(type); _methodCache[type] = func; CloneMapping = _methodCache.HashTree(); } return(func(instance)); } } }
public unsafe static object Clone(object instance) { if (instance == null) { return(null); } else { var type = instance.GetType(); if (type.IsSimpleType()) { return(instance); } else if (type == typeof(object)) { return(new object()); } else { var func = CloneMapping.GetValue(type); if (func == default) { func = ObjectCloneBuilder.Create(type); _methodCache[type] = func; int[] code = new int[_methodCache.Count]; int i = 0; foreach (var item in _methodCache) { code[i] = item.Value.GetHashCode(); i++; } CloneMapping = _methodCache.HashTree(DyanamicCacheDirection.KeyToValue); } return(func(instance)); } } }