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

            context.CopyInstanceData(this, result, copySingletonMembers);
            return(result);
        }
Ejemplo 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);
        }
Ejemplo 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;
 }
Ejemplo 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);
 }
Ejemplo 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;
        }