public void VisitProperty <TSourceProperty, TSourceValue>(TSourceProperty srcProperty, ref TSourceContainer srcContainer, ref ChangeTracker propertyChangeTracker)
                where TSourceProperty : IProperty <TSourceContainer, TSourceValue>
            {
                var srcValue = srcProperty.GetValue(ref srcContainer);

                if (TypeConversion.TryConvert <TSourceValue, TDestinationValue>(srcValue, out var dstValue))
                {
                    if (CustomEquality.Equals(dstValue, DstProperty.GetValue(ref DstContainer)))
                    {
                        return;
                    }

                    DstProperty.SetValue(ref DstContainer, dstValue);
                    propertyChangeTracker.IncrementVersion <TDestinationProperty, TDestinationContainer, TDestinationValue>(DstProperty, ref DstContainer);
                    return;
                }

                if (DstProperty.IsContainer)
                {
                    var changeTracker = new ChangeTracker(propertyChangeTracker.VersionStorage);

                    dstValue = DstProperty.GetValue(ref DstContainer);

                    PropertyContainer.Transfer(ref dstValue, ref srcValue, ref changeTracker);

                    DstProperty.SetValue(ref DstContainer, dstValue);

                    if (changeTracker.IsChanged())
                    {
                        propertyChangeTracker.IncrementVersion <TDestinationProperty, TDestinationContainer, TDestinationValue>(DstProperty, ref DstContainer);
                    }
                }
            }
                public void VisitProperty <TDestinationElementProperty, TDestinationElement>(TDestinationElementProperty dstElementProperty, ref TDestinationContainer dstContainer, ref ChangeTracker propertyChangeTracker)
                    where TDestinationElementProperty : ICollectionElementProperty <TDestinationContainer, TDestinationElement>
                {
                    if (TypeConversion.TryConvert <TSourceElement, TDestinationElement>(SrcElementValue, out var dstElementValue))
                    {
                        if (CustomEquality.Equals(dstElementValue, dstElementProperty.GetValue(ref dstContainer)))
                        {
                            return;
                        }

                        dstElementProperty.SetValue(ref dstContainer, dstElementValue);
                        propertyChangeTracker.IncrementVersion <TDestinationElementProperty, TDestinationContainer, TDestinationElement>(dstElementProperty, ref dstContainer);
                        return;
                    }

                    if (dstElementProperty.IsContainer)
                    {
                        var changeTracker = new ChangeTracker(propertyChangeTracker.VersionStorage);

                        dstElementValue = dstElementProperty.GetValue(ref dstContainer);

                        PropertyContainer.Transfer(ref dstElementValue, ref SrcElementValue, ref changeTracker);

                        dstElementProperty.SetValue(ref dstContainer, dstElementValue);

                        if (changeTracker.IsChanged())
                        {
                            propertyChangeTracker.IncrementVersion <TDestinationElementProperty, TDestinationContainer, TDestinationElement>(dstElementProperty, ref dstContainer);
                        }
                    }
                }
        public VisitStatus VisitProperty <TProperty, TContainer, TValue>(TProperty property, ref TContainer container, ref ChangeTracker changeTracker)
            where TProperty : IProperty <TContainer, TValue>
        {
            // Give users a chance to filter based on the data.
            if (IsExcluded <TProperty, TContainer, TValue>(property, ref container))
            {
                return(VisitStatus.Handled);
            }

            var value = property.GetValue(ref container);
            var valueChangeTracker = new ChangeTracker(changeTracker.VersionStorage);

            var status = property.IsContainer
                ? TryVisitContainerWithAdapters(property, ref container, ref value, ref valueChangeTracker)
                : TryVisitValueWithAdapters(property, ref container, ref value, ref valueChangeTracker);

            if (property.IsReadOnly)
            {
                return(status);
            }

            property.SetValue(ref container, value);

            if (valueChangeTracker.IsChanged())
            {
                changeTracker.IncrementVersion <TProperty, TContainer, TValue>(property, ref container);
            }

            return(status);
        }
Exemple #4
0
            public void VisitProperty <TProperty, TDestinationValue>(TProperty property, ref TContainer container, ref ChangeTracker changeTracker)
                where TProperty : IProperty <TContainer, TDestinationValue>
            {
                if (!TypeConversion.TryConvert <TSourceValue, TDestinationValue>(SrcValue, out var dstValue))
                {
                    Result = k_ResultErrorConvert;
                    return;
                }

                if (CustomEquality.Equals(dstValue, property.GetValue(ref container)))
                {
                    return;
                }

                property.SetValue(ref container, dstValue);
                changeTracker.IncrementVersion <TProperty, TContainer, TDestinationValue>(property, ref container);
            }
        internal VisitStatus TryVisitCollectionWithAdapters <TProperty, TContainer, TValue>(TProperty property, ref TContainer container, ref TValue value, ref ChangeTracker changeTracker)
            where TProperty : ICollectionProperty <TContainer, TValue>
        {
            VisitStatus status;

            if (null != m_Adapters)
            {
                for (var i = 0; i < m_Adapters.Count; i++)
                {
                    if ((status = m_Adapters[i].TryVisitCollection(this, property, ref container, ref value, ref changeTracker)) != VisitStatus.Unhandled)
                    {
                        return(status);
                    }
                }
            }

            if ((status = BeginCollection(property, ref container, ref value, ref changeTracker)) != VisitStatus.Unhandled)
            {
                if (status == VisitStatus.Handled)
                {
                    for (int i = 0, count = property.GetCount(ref container); i < count; i++)
                    {
                        var callback             = new VisitCollectionElementCallback <TContainer>(this);
                        var elementChangeTracker = new ChangeTracker(changeTracker.VersionStorage);

                        property.GetPropertyAtIndex(ref container, i, ref elementChangeTracker, ref callback);

                        if (elementChangeTracker.IsChanged())
                        {
                            changeTracker.IncrementVersion <TProperty, TContainer, TValue>(property, ref container);
                        }
                    }
                }

                EndCollection(property, ref container, ref value, ref changeTracker);
            }

            return(status);
        }