private IBCopierInternal GetElementCopier(Type currType)
        {
            // check the copiers local cache
            if (!PotentialCopiers.TryGetValue(currType, out IBCopierInternal copier))
            {
                copier = BDeepCopyProvider.GetOrCreate(currType);
                PotentialCopiers.Add(currType, copier);
            }

            return(copier);
        }
        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));
        }
        protected override void Initialize()
        {
            base.Initialize();

            MemberInfos = GetMembers().ToList();

            Constructor = ReflectionUtils.GetParameterlessConstructor(Type);

            MemberCount = MemberInfos.Count;

            Copiers = new List <IBCopierInternal>();
            Getters = new List <Func <object, object> >();
            Setters = new List <Action <object, object> >();

            // custom
            BCopierOverrides = new List <Dictionary <Type, CopierSettingAttribute> >();

            // internal
            InternalBCopierOverrides = new List <List <Tuple <CopierSettingAttribute, IBCopierOverrideInternal> > >();

            for (int i = 0; i < MemberCount; i++)
            {
                MemberInfo curr = MemberInfos[i];
                Getters.Add(MemberGetter(curr));
                Setters.Add(MemberSetter(curr));
                Copiers.Add(BDeepCopyProvider.GetOrCreate(ReflectionUtils.GetMemberType(curr)));

                Dictionary <Type, CopierSettingAttribute> customAttrs = new Dictionary <Type, CopierSettingAttribute>();
                List <Tuple <CopierSettingAttribute, IBCopierOverrideInternal> > internalAttrs = new List <Tuple <CopierSettingAttribute, IBCopierOverrideInternal> >();

                IEnumerable <CopierSettingAttribute> attrsList = curr.GetCustomAttributes <CopierSettingAttribute>(true);

                foreach (CopierSettingAttribute a in attrsList)
                {
                    // check if internal
                    if (BCopierSettings.TypeToCopier.TryGetValue(a.GetType(), out IBCopierOverrideInternal copier))
                    {
                        internalAttrs.Add(new Tuple <CopierSettingAttribute, IBCopierOverrideInternal>(a, copier));
                    }

                    // else add to custom
                    else
                    {
                        customAttrs.Add(a.GetType(), a);
                    }
                }

                BCopierOverrides.Add(customAttrs);
                InternalBCopierOverrides.Add(internalAttrs);
            }
        }
Example #4
0
        protected override void Initialize()
        {
            base.Initialize();

            ListType = Type.GetGenericTypeDefinition();

            ElementType = Type.GenericTypeArguments[0];

            ElementCopier = BDeepCopyProvider.GetOrCreate(ElementType);

            Constructor = GetConstructor(Type);

            // TODO : make separete copier for non-inheritable classes
            //ElementsAreConcrete = ElementType.IsAbstract || ElementType.IsInterface;
        }
Example #5
0
 public static IBCopier GetCopier(Type t)
 {
     return(BDeepCopyProvider.GetOrCreate(t.GetType()));
 }