public static bool TryDuplicateObject(RubyContext /*!*/ context, object obj, bool cloneSemantics, out object copy) { // Ruby value types can't be cloned if (RubyUtils.IsRubyValueType(obj)) { copy = null; return(false); } IDuplicable clonable = obj as IDuplicable; if (clonable != null) { copy = clonable.Duplicate(context, cloneSemantics); } else { // .NET classes and library clases that doesn't implement IDuplicable: copy = RubySites.Allocate(context.GetClassOf(obj)); context.CopyInstanceData(obj, copy, cloneSemantics); } // TODO: optimize _InitializeCopySharedSite.Target(_InitializeCopySharedSite, context, copy, obj); if (cloneSemantics) { context.FreezeObjectBy(copy, obj); } return(true); }
public static bool TryDuplicateObject(RubyContext/*!*/ context, object obj, bool cloneSemantics, out object copy) { // Ruby value types can't be cloned if (RubyUtils.IsRubyValueType(obj)) { copy = null; return false; } IDuplicable clonable = obj as IDuplicable; if (clonable != null) { copy = clonable.Duplicate(context, cloneSemantics); } else { // .NET classes and library clases that doesn't implement IDuplicable: copy = RubySites.Allocate(context.GetClassOf(obj)); context.CopyInstanceData(obj, copy, cloneSemantics); } // TODO: optimize _InitializeCopySharedSite.Target(_InitializeCopySharedSite, context, copy, obj); if (cloneSemantics) { context.FreezeObjectBy(copy, obj); } return true; }