Пример #1
0
        public FieldSetOperation(IFieldWrapper field, object reference)
        {
            this.field = field;

            referenceValue = field.Get(ref reference);
            type           = GetType(referenceValue);
            isValue        = type == null ? false : type.IsValueType;
            isPure         = type == null || type.IsPure();
            operations     = isPure ? null : InitializationUtility.GetInitializer(type).CreateOperations(referenceValue);
        }
Пример #2
0
        public FieldSetOperation(IFieldWrapper field, object reference)
        {
            this.field = field;

            referenceValue = field.Get(ref reference);
            type = GetType(referenceValue);
            isValue = type == null ? false : type.IsValueType;
            isPure = type == null || type.IsPure();
            operations = isPure ? null : InitializationUtility.GetInitializer(type).CreateOperations(referenceValue);
        }
Пример #3
0
        public void Initialize(ref object instance, HashSet <object> toIgnore)
        {
            if (isPure)
            {
                field.Set(ref instance, referenceValue);
                return;
            }

            var instanceValue = field.Get(ref instance);

            if (GetType(instanceValue) != type)
            {
                field.Set(ref instance, referenceValue);
            }
            else if (isValue || toIgnore.Add(instanceValue))
            {
                for (int i = 0; i < operations.Length; i++)
                {
                    operations[i].Initialize(ref instanceValue, toIgnore);
                }

                field.Set(ref instance, instanceValue);
            }
        }