Exemple #1
0
        public static PropertyT ExeGetClone <T, PropertyT>(T source, MemberInfo info, PropertyT propertySource, string[] excludeNames, CloningFlags flags, IDictionary <Type, Func <object, object> > initializers, Func <Type, object, object> createObjectFun, Action <ResolveArgs> customResolveFun, Dictionary <object, object> clonedObjects)
        {
            if (propertySource == null)
            {
                return(default(PropertyT));
            }
            //if (clonedObjects.ContainsKey(propertySource))
            //{
            //    return (PropertyT)clonedObjects[propertySource];
            //}
            var _excludeNames = GetExcludeName(excludeNames, info?.Name);
            var d             = new ResolveArgs(source, typeof(T), info, propertySource, typeof(PropertyT), _excludeNames, flags, initializers, createObjectFun, customResolveFun, clonedObjects);

            customResolveFun?.Invoke(d);
            if (d.IsResolve)
            {
                //if (!clonedObjects.ContainsKey(propertySource))
                //{
                //    clonedObjects.Add(propertySource, d.NewValue);
                //}
                return((PropertyT)d.NewValue);
            }
            else
            {
                var _type       = typeof(PropertyT);
                var constructor = _type.GetConstructor(new Type[0]);
                if (_type.IsAbstract() || _type.IsInterface() || (!_type.IsValueType() && constructor == null))
                {
                    Helpers.GetThrowInvalidOperationExceptionExpression(_type);
                }
                return(CloneFactory.GetClone(propertySource, _excludeNames, flags, initializers, createObjectFun, customResolveFun, clonedObjects));
            }
        }
 public T GetClone <T>(T source, string[] excludeNames, CloningFlags flags, IDictionary <Type, Func <object, object> > initializers, Func <Type, object, object> createObjectFun, Action <ResolveArgs> customResolveFun)
 {
     return(CloneFactory.GetClone(source, excludeNames, flags, initializers, createObjectFun, customResolveFun, this.clonedObjects));
 }