Esempio n. 1
0
        internal void DeferBind(Type valType, object source, object target)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }
            if (target == null)
            {
                throw new ArgumentNullException(nameof(target));
            }
            if (valType.IsDictionary() || valType.IsCollection())
            {
                return;
            }
            if (!_cloneDelegates.ContainsKey(valType))
            {
                _cloneDelegates[valType] = CloningDelegateEmitter.EmitCloneDelegate(valType);
            }

            var tooling = _cloneDelegates[valType];

            if (tooling.Bind != null)
            {
                _lateBoundQueue.Enqueue(new LateBoundEntry()
                {
                    LateBound = tooling.Bind,
                    Source    = source,
                    Target    = target
                });
            }
        }
        private object Clone(Type t, object original)
        {
            if (original == null)
            {
                return(null);
            }
            if (_alreadyCloned.ContainsKey(original))
            {
                return(_alreadyCloned[original]);
            }

            if (original is IDictionary dic)
            {
                return(CloneDictionary(dic));
            }
            if (original is IEnumerable coll)
            {
                return(CloneCollection(coll));
            }
            if (original is ICloneable clon)
            {
                return(clon.Clone());
            }

            if (!_cloneDelegates.ContainsKey(t))
            {
                _cloneDelegates[t] = CloningDelegateEmitter.EmitCloneDelegate(t);
            }

            var del = _cloneDelegates[t];

            return(del.Shallow.DynamicInvoke(original, this));
        }
Esempio n. 3
0
        public object CloneDictionary(IDictionary dic)
        {
            var dicType = dic.GetType();

            if (!_cloneDelegates.ContainsKey(dicType))
            {
                _cloneDelegates[dicType] = CloningDelegateEmitter.EmitDictionaryCloningDelegate(dicType);
            }

            var del    = _cloneDelegates[dicType];
            var clones = CloneDictionaryData(dic);

            return(del.Shallow.DynamicInvoke(clones));
        }
Esempio n. 4
0
        public object CloneCollection(IEnumerable coll)
        {
            var collType = coll.GetType();

            if (!_cloneDelegates.ContainsKey(collType))
            {
                _cloneDelegates[collType] = CloningDelegateEmitter.EmitCollectionCloningDelegate(collType);
            }

            var del    = _cloneDelegates[collType];
            var clones = CloneCollectionData(coll);

            return(del.Shallow.DynamicInvoke(clones));
        }