Ejemplo n.º 1
0
        protected override VisitStatus BeginCollection <TProperty, TContainer, TValue>(
            TProperty property,
            ref TContainer container,
            ref TValue value,
            ref ChangeTracker changeTracker)
        {
            if (typeof(TValue).IsClass && null == value)
            {
                return(VisitStatus.Override);
            }

            var propName = property.GetName();

            Add(propName);
            var path = m_PropertyPathBuilder.ToString();

            if (m_FullPathToElementsMap.TryGetValue(path, out var fullPathElements))
            {
                foreach (var element in fullPathElements)
                {
                    // Special element to track the array size
                    var field = element.Q <IntegerField>("CollectionSize");
                    if (null == field)
                    {
                        continue;
                    }

                    switch (m_Operation)
                    {
                    case BindingRegistration.None:
                        Connectors.SetCollectionSize(field, property.GetCount(ref container));
                        break;

                    case BindingRegistration.Register:
                        // Nothing to register for this.
                        break;

                    case BindingRegistration.Unregister:
                        // Nothing to unregister for this.
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }
                }
            }
            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);
            }
            Remove(propName);
            return(VisitStatus.Override);
        }
Ejemplo n.º 2
0
        public static void GenerateAOTCollectionFunctions <TProperty, TContainer, TValue>()
            where TProperty : ICollectionProperty <TContainer, TValue>
        {
            TProperty     property      = default(TProperty);
            TContainer    container     = default(TContainer);
            TValue        value         = default(TValue);
            ChangeTracker changeTracker = default(ChangeTracker);
            var           getter        = new VisitCollectionElementCallback <TContainer>();

            PropertyVisitor propertyVisitor = new PropertyVisitor();

            propertyVisitor.TryVisitContainerWithAdapters(property, ref container, ref value, ref changeTracker);
            propertyVisitor.TryVisitCollectionWithAdapters(property, ref container, ref value, ref changeTracker);
            propertyVisitor.TryVisitValueWithAdapters(property, ref container, ref value, ref changeTracker);
            PropertyVisitorAdapterExtensions.TryVisitCollection(null, null, property, ref container, ref value, ref changeTracker);
            PropertyVisitorAdapterExtensions.TryVisitContainer(null, null, property, ref container, ref value, ref changeTracker);
            PropertyVisitorAdapterExtensions.TryVisitValue(null, null, property, ref container, ref value, ref changeTracker);

            var arrayProperty = new ArrayProperty <TContainer, TValue>();

            arrayProperty.GetPropertyAtIndex(ref container, 0, ref changeTracker, ref getter);
            var arrayCollectionElementProperty = new ArrayProperty <TContainer, TValue> .CollectionElementProperty();

            arrayCollectionElementProperty.GetValue(ref container);
            arrayCollectionElementProperty.SetValue(ref container, value);
            propertyVisitor.VisitProperty <ArrayProperty <TContainer, TValue> .CollectionElementProperty, TContainer, TValue>(arrayCollectionElementProperty, ref container, ref changeTracker);

            var listProperty = new ListProperty <TContainer, TValue>();

            listProperty.GetPropertyAtIndex(ref container, 0, ref changeTracker, ref getter);
            var listCollectionElementProperty = new ListProperty <TContainer, TValue> .CollectionElementProperty();

            listCollectionElementProperty.GetValue(ref container);
            listCollectionElementProperty.SetValue(ref container, value);
            propertyVisitor.VisitProperty <ListProperty <TContainer, TValue> .CollectionElementProperty, TContainer, TValue>(listCollectionElementProperty, ref container, ref changeTracker);

            Actions.GetCollectionCountGetter <TContainer> getCollectionCountGetter       = new Actions.GetCollectionCountGetter <TContainer>();
            Actions.GetCountFromActualTypeCallback        getCountFromActualTypeCallback = new Actions.GetCountFromActualTypeCallback();
            getCountFromActualTypeCallback.Invoke <TContainer>();
            getCountFromActualTypeCallback.Invoke <TValue>();
            Actions.GetCountAtPathGetter <TContainer> getCountAtPathGetter = new Actions.GetCountAtPathGetter <TContainer>();
            Actions.VisitAtPathCallback visitAtPathCallback = default;
            visitAtPathCallback.Invoke <TContainer>();
            visitAtPathCallback.Invoke <TValue>();
            Actions.SetCountCallback setCountCallback = default;
            setCountCallback.Invoke <TContainer>();
            setCountCallback.Invoke <TValue>();

            Actions.TryGetCount(ref container, new PropertyPath(), 0, ref changeTracker, out var count);
            Actions.TryGetCountImpl(ref container, new PropertyPath(), 0, ref changeTracker, out var otherCount);
            Actions.GetCount(ref container, new PropertyPath(), 0, ref changeTracker);
        }
Ejemplo n.º 3
0
        private static void VisitCollectionElements <TProperty, TContainer, TValue>(IPropertyVisitor visitor, TProperty property, ref TContainer container, ChangeTracker propertyChangeTracker)
            where TProperty : ICollectionProperty <TContainer, TValue>
        {
            for (int i = 0, count = property.GetCount(ref container); i < count; i++)
            {
                var callback = new VisitCollectionElementCallback <TContainer>(visitor, propertyChangeTracker.VersionStorage);

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

                if (callback.IsChanged())
                {
                    propertyChangeTracker.IncrementVersion <TProperty, TContainer, TValue>(property, ref container);
                }
            }
        }
Ejemplo n.º 4
0
        protected override VisitStatus BeginCollection <TProperty, TContainer, TValue>(
            TProperty property,
            ref TContainer container,
            ref TValue value, ref ChangeTracker changeTracker)
        {
            var propName = property.GetName();

            AddToPath(propName);
            try
            {
                if (container is PropertyWrapper <TValue> || value is PropertyWrapper <TValue> )
                {
                    GuiFactory.CollectionSizeField(property, ref container, ref value, VisitorContext);
                    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);
                        }
                    }

                    return(VisitStatus.Override);
                }

                if (typeof(TValue).IsClass && null == value)
                {
                    var nullElement = new NullElement <TValue>(property.GetName());
                    VisitorContext.Parent.contentContainer.Add(nullElement);

                    return(VisitStatus.Override);
                }

                var foldout = GuiFactory.Foldout(property, ref container, ref value, VisitorContext);

                using (VisitorContext.MakeParentScope(foldout))
                {
                    if (TryGetInspector(ref value, property, new PropertyPath(m_Path.ToString()), propName,
                                        InspectorVisitLevel.Field))
                    {
                        return(VisitStatus.Override);
                    }
                    GuiFactory.CollectionSizeField(property, ref container, ref value, VisitorContext);

                    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);
                        }
                    }
                }

                return(VisitStatus.Override);
            }
            finally
            {
                RemoveFromPath(propName);
            }
        }