Ejemplo n.º 1
0
        static IPoolSetter GetSetter(object value, FieldInfo field, HashSet <object> toIgnore)
        {
            if (value == null)
            {
                return(new PoolSetter(field, value));
            }
            else if (toIgnore.Contains(value))
            {
                throw new InitializationCycleException(field);
            }

            var copier = CopyUtility.GetCopier(value.GetType());

            if (copier != null)
            {
                return(new PoolCopierSetter(copier, field, value));
            }
            else if (value is IList)
            {
                return(new PoolArraySetter(field, value.GetType(), GetElementSetters((IList)value, field, toIgnore)));
            }
            else if (field.IsDefined(typeof(InitializeContentAttribute), true))
            {
                if (!(value is ValueType))
                {
                    toIgnore.Add(value);
                }

                return(new PoolContentSetter(field, value.GetType(), GetSetters(value, toIgnore)));
            }
            else
            {
                return(new PoolSetter(field, value));
            }
        }
Ejemplo n.º 2
0
        static IPoolElementSetter GetElementSetter(object element, FieldInfo field, HashSet <object> toIgnore)
        {
            if (element == null)
            {
                return(new PoolElementSetter(element));
            }
            else if (toIgnore.Contains(element))
            {
                throw new InitializationCycleException(field);
            }

            var copier = CopyUtility.GetCopier(element.GetType());

            if (copier != null)
            {
                return(new PoolElementCopierSetter(copier, element));
            }
            else if (field.IsDefined(typeof(InitializeContentAttribute), true))
            {
                if (!(element is ValueType))
                {
                    toIgnore.Add(element);
                }

                return(new PoolElementContentSetter(element.GetType(), GetSetters(element, toIgnore)));
            }
            else
            {
                return(new PoolElementSetter(element));
            }
        }
Ejemplo n.º 3
0
        public static IFieldInitializer GetPoolInitializer(object instance)
        {
            var copier = CopyUtility.GetCopier(instance.GetType());

            if (copier == null)
            {
                return(new FieldInitializer(instance));
            }
            else
            {
                return(new CopierFieldInitializer(copier, instance));
            }
        }