internal override object Copy(object t, object instance, BCopierContext copierContext, BCopierSettings copierSettings)
        {
            Array casted         = (Array)t;
            Array castedInstance = (Array)instance;

            // cached locals
            object           curr     = null;
            Type             currType = null;
            IBCopierInternal c        = null;
            object           copy     = null;

            for (int i = 0; i < casted.Length; i++)
            {
                curr     = casted.GetValue(i);
                currType = curr.GetType();

                c = GetElementCopier(currType);

                copy = c.Copy(curr, copierContext, copierSettings);

                castedInstance.SetValue(copy, i);
            }

            return(castedInstance);
        }
Exemple #2
0
        internal override object Copy(object t, object instance, BCopierContext copierContext, BCopierSettings copierSettings)
        {
            // TODO : optimize by looking for contructor with capacity first
            // DONE
            IList casted         = (IList)t;
            IList castedInstance = (IList)instance;

            // cached locals
            object           curr     = null;
            Type             currType = null;
            IBCopierInternal c        = null;
            object           copy     = null;

            for (int i = 0; i < casted.Count; i++)
            {
                curr     = casted[i];
                currType = curr.GetType();

                c = GetElementCopier(currType);

                copy = c.Copy(curr, copierContext, copierSettings);

                castedInstance.Add(copy);
            }

            return(castedInstance);
        }
        object IBCopierInternal.Copy(object t, BCopierContext copierContext, BCopierSettings bCopierSettings)
        {
            Type concrete = t.GetType();

            // check the copiers local cache
            if (!PotentialTypeCopiers.TryGetValue(concrete, out IBCopierInternal copier))
            {
                copier = BDeepCopyProvider.GetOrCreate(concrete);
                PotentialTypeCopiers.Add(concrete, copier);
            }

            return(copier.Copy(t, copierContext, bCopierSettings));
        }
        private object Copy(object t, BCopierContext copierContext, BCopierSettings copierSettings)
        {
            if (t == null)
            {
                return(null);
            }

            if (copierContext.TryGetCached(t, out object cached))
            {
                return(cached);
            }

            object emptyCopy = CreateEmptyCopy(t);

            copierContext.Register(t, emptyCopy);

            return(Copy(t, emptyCopy, copierContext, copierSettings));
        }
Exemple #5
0
        internal override object Copy(object t, object instance, BCopierContext copierContext, BCopierSettings copierSettings)
        {
            // TODO : optimize by looking for contructor with capacity first
            // DONE
            IDictionary casted         = (IDictionary)t;
            IDictionary castedInstance = (IDictionary)instance;

            object[] keys = new object[casted.Count];
            object[] vals = new object[casted.Count];

            casted.Keys.CopyTo(keys, 0);
            casted.Values.CopyTo(vals, 0);

            // cached locals
            object           curr     = null;
            IBCopierInternal c        = null;
            Type             currType = null;
            object           copyKey  = null;
            object           copyVal  = null;

            for (int i = 0; i < casted.Count; i++)
            {
                // copy key
                curr     = keys[i];
                currType = curr.GetType();

                c = GetKeyCopier(currType);

                copyKey = c.Copy(curr, copierContext, copierSettings);

                // copy key
                curr     = vals[i];
                currType = curr.GetType();

                c = GetValueCopier(currType);

                copyVal = c.Copy(curr, copierContext, copierSettings);

                castedInstance.Add(copyKey, copyVal);
            }

            return(castedInstance);
        }
        internal override object Copy(object t, object emptyCopy, BCopierContext copierContext, BCopierSettings copierSettings)
        {
            for (int i = 0; i < MemberCount; i++)
            {
                MemberInfo              mem    = MemberInfos[i];
                Func <object, object>   getter = Getters[i];
                Action <object, object> setter = Setters[i];
                IBCopierInternal        copier = Copiers[i];
                Dictionary <Type, CopierSettingAttribute> customOverrides = BCopierOverrides[i];
                List <Tuple <CopierSettingAttribute, IBCopierOverrideInternal> > internalOverrides = InternalBCopierOverrides[i];

                object originalVal = getter.Invoke(t);
                object copy        = null;

                // if we found an internal override
                // then we apply it and go next
                if (TryInternalOverride(internalOverrides, mem, ref originalVal, copier, out copy))
                {
                    setter.Invoke(emptyCopy, copy);
                    continue;
                }

                // if no copier setting we use default
                if (copierSettings == null)
                {
                    copy = copier.Copy(originalVal, copierContext, copierSettings);
                }

                // try to check if we can apply an override
                // if not , then we use the default copy
                else if (!TryCustomOverride(copierSettings, mem, ref originalVal, copier, customOverrides, out copy))
                {
                    copy = copier.Copy(originalVal, copierContext, copierSettings);
                }

                // copy from original and assign to new instance
                setter.Invoke(emptyCopy, copy);
            }

            return(emptyCopy);
        }
Exemple #7
0
 public object Copy(object t, BCopierContext copierContext, BCopierSettings bCopierSettings)
 {
     return(t);
 }
 internal abstract object Copy(object t, object emptyCopy, BCopierContext copierContext, BCopierSettings copierSettings);
 object IBCopierInternal.Copy(object t, BCopierContext copierContext, BCopierSettings copierSettings)
 {
     return(Copy(t, copierContext, copierSettings));
 }