Example #1
0
        private static void PopActiveFields()
        {
            while (ActiveFields.Count > 0)
            {
                ValueData data = ActiveFields.Pop();
                if (data == null)
                {
                    break; // The marker
                }

                ValueAccess field = data.Access;

                object newValue = data.Access.Get(data.Target);
                bool   changed  = !Equals(newValue, data.Value);

                Dictionary <object, ValueChangeRequest> fieldBuffer = BufferedChanges.Assert(field);
                if (fieldBuffer.TryGetValue(data.Target, out ValueChangeRequest cached))
                {
                    if (changed && cached.RequestProcessed)
                    {
                        cached.RequestProcessed = false;
                    }

                    cached.RequestedValue = newValue;
                    field.Set(data.Target, cached.LatestActualValue);
                    continue;
                }

                if (!changed)
                {
                    continue;
                }

                fieldBuffer[data.Target] = new ValueChangeRequest
                {
                    LatestActualValue = data.Value,
                    RequestedValue    = newValue
                };
                field.Set(data.Target, data.Value);
            }
        }
Example #2
0
        private static void OnBeforeExpectedChange(this ValueAccess access, object target)
        {
            object value;

            if (BufferedChanges.ContainsKey(access) &&
                BufferedChanges[access].TryGetValue(target, out ValueChangeRequest cache))
            {
                value = cache.RequestedValue;
                access.Set(target, value);
            }
            else
            {
                value = access.Get(target);
            }

            ActiveFields.Push(new ValueData(access, target, value));
        }