コード例 #1
0
 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));
         }
     }
 }
コード例 #2
0
 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));
         }
     }
 }