Esempio n. 1
0
        object IDuplicable.Duplicate(RubyContext /*!*/ context, bool copySingletonMembers)
        {
            var result = Copy();

            context.CopyInstanceData(this, result, copySingletonMembers);
            return(result);
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
 // Proc doesn't have "initialize_copy", it's entirely initialized in dup:
 object IDuplicable.Duplicate(RubyContext/*!*/ context, bool copySingletonMembers) {
     var result = Copy();
     context.CopyInstanceData(this, result, copySingletonMembers);
     return result;
 }
Esempio n. 4
0
 /// <summary>
 /// Creates an empty copy of this instance, taint and instance variables.
 /// </summary>
 public MutableString /*!*/ Duplicate(RubyContext /*!*/ context, bool copySingletonMembers, MutableString /*!*/ result)
 {
     context.CopyInstanceData(this, result, false, false, copySingletonMembers);
     return(result);
 }
Esempio n. 5
0
        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;
        }