示例#1
0
 internal static void SwitchTo(bool isSafe)
 {
     DeepClonerCache.ClearCache();
     if (isSafe)
     {
         _instance = new ShallowSafeObjectCloner();
     }
     else
     {
         _instance = _unsafeInstance;
     }
 }
示例#2
0
 private static object GenerateCloner(Type t, bool asObject)
 {
     if (DeepClonerSafeTypes.CanReturnSameObject(t) && asObject && !t.IsValueType())
     {
         return(null);
     }
     if (ShallowObjectCloner.IsSafeVariant())
     {
         return(DeepClonerExprGenerator.GenerateClonerInternal(t, asObject));
     }
     return(DeepClonerMsilGenerator.GenerateClonerInternal(t, asObject));
 }
示例#3
0
 static ShallowObjectCloner()
 {
     _unsafeInstance = GenerateUnsafeCloner();
     _instance       = _unsafeInstance;
     try
     {
         _instance.DoCloneObject(new object());
     }
     catch (Exception)
     {
         _instance = new ShallowSafeObjectCloner();
     }
 }
 public static T CloneObject <T>(T obj)
 {
     if (obj is ValueType)
     {
         if (typeof(T) == obj.GetType())
         {
             return(obj);
         }
         return((T)ShallowObjectCloner.CloneObject(obj));
     }
     if (obj == null)
     {
         return((T)(object)null);
     }
     if (DeepClonerSafeTypes.CanReturnSameObject(obj.GetType()))
     {
         return(obj);
     }
     return((T)ShallowObjectCloner.CloneObject(obj));
 }