Exemplo n.º 1
0
 internal SetCollectionItemGetter(PropertyPath propertyPath, int propertyPathIndex, TTargetValue value)
 {
     m_PropertyPath      = propertyPath;
     m_PropertyPathIndex = propertyPathIndex;
     m_Value             = value;
     ErrorCode           = VisitErrorCode.Ok;
 }
 internal GetValueAtPathAction(PropertyPath propertyPath, int propertyPathIndex)
 {
     m_PropertyPath      = propertyPath;
     m_PropertyPathIndex = propertyPathIndex;
     Value     = default;
     ErrorCode = VisitErrorCode.Ok;
 }
Exemplo n.º 3
0
 internal GetCountAtPathGetter(PropertyPath propertyPath, int propertyPathIndex)
 {
     m_PropertyPath      = propertyPath;
     m_PropertyPathIndex = propertyPathIndex;
     Count     = -1;
     ErrorCode = default;
 }
 internal GetCollectionItemGetter(PropertyPath propertyPath, int propertyPathIndex)
 {
     m_PropertyPath      = propertyPath;
     m_PropertyPathIndex = propertyPathIndex;
     Value     = default;
     ErrorCode = VisitErrorCode.Ok;
 }
Exemplo n.º 5
0
 internal SetCollectionCountGetter(PropertyPath propertyPath, int propertyPathIndex, int count)
 {
     m_PropertyPath      = propertyPath;
     m_PropertyPathIndex = propertyPathIndex;
     m_Count             = count;
     ErrorCode           = VisitErrorCode.Ok;
 }
Exemplo n.º 6
0
 internal SetCountAtPathAction(PropertyPath propertyPath, int propertyPathIndex, int count)
 {
     m_PropertyPath      = propertyPath;
     m_PropertyPathIndex = propertyPathIndex;
     m_Count             = count;
     ErrorCode           = VisitErrorCode.Ok;
 }
Exemplo n.º 7
0
 internal VisitAtPathGetter(PropertyPath propertyPath, int propertyPathIndex, IPropertyVisitor visitor)
 {
     m_PropertyPath      = propertyPath;
     m_PropertyPathIndex = propertyPathIndex;
     m_Visitor           = visitor;
     ErrorCode           = VisitErrorCode.Ok;
 }
Exemplo n.º 8
0
 internal GetCollectionCountGetter(PropertyPath propertyPath, int propertyPathIndex)
 {
     m_PropertyPath      = propertyPath;
     m_PropertyPathIndex = propertyPathIndex;
     Count     = -1;
     ErrorCode = VisitErrorCode.Ok;
 }
Exemplo n.º 9
0
 internal SetValueAtPathAction(PropertyPath propertyPath, int propertyPathIndex, TTargetValue value)
 {
     m_Path = propertyPath;
     m_PropertyPathIndex = propertyPathIndex;
     m_Value             = value;
     ErrorCode           = VisitErrorCode.Ok;
 }
Exemplo n.º 10
0
 private SetValueCallback(object container, PropertyPath propertyPath, int propertyPathIndex, TValue value, ref ChangeTracker changeTracker)
 {
     m_Container         = container;
     m_PropertyPath      = propertyPath;
     m_PropertyPathIndex = propertyPathIndex;
     Value           = value;
     m_ChangeTracker = changeTracker;
     m_ErrorCode     = VisitErrorCode.Ok;
 }
Exemplo n.º 11
0
 private GetCountFromActualTypeCallback(object container, PropertyPath propertyPath, int propertyPathIndex, ref ChangeTracker changeTracker)
 {
     m_Container         = container;
     m_PropertyPath      = propertyPath;
     m_PropertyPathIndex = propertyPathIndex;
     m_ChangeTracker     = changeTracker;
     m_Count             = -1;
     m_ErrorCode         = VisitErrorCode.Ok;
 }
Exemplo n.º 12
0
 private SetCountCallback(object container, PropertyPath propertyPath, int propertyPathIndex, int count, ref ChangeTracker changeTracker)
 {
     m_Container         = container;
     m_PropertyPath      = propertyPath;
     m_PropertyPathIndex = propertyPathIndex;
     m_Count             = count;
     m_ChangeTracker     = changeTracker;
     m_ErrorCode         = VisitErrorCode.Ok;
 }
Exemplo n.º 13
0
 private VisitAtPathCallback(object container, PropertyPath propertyPath, int propertyPathIndex,
                             IPropertyVisitor visitor, ref ChangeTracker changeTracker)
 {
     m_Container         = container;
     m_PropertyPath      = propertyPath;
     m_PropertyPathIndex = propertyPathIndex;
     m_ChangeTracker     = changeTracker;
     m_Visitor           = visitor;
     errorCode           = VisitErrorCode.Ok;
 }
Exemplo n.º 14
0
        void IPropertyBagVisitor.Visit <TContainer>(IPropertyBag <TContainer> properties, ref TContainer container)
        {
            var part = Path[m_PathIndex++];

            IProperty <TContainer> property;

            switch (part.Type)
            {
            case PropertyPath.PartType.Name:
            {
                if (properties is IPropertyNameable <TContainer> keyable && keyable.TryGetProperty(ref container, part.Name, out property))
                {
                    ((IPropertyAccept <TContainer>)property).Accept(this, ref container);
                }
                else
                {
                    ErrorCode = VisitErrorCode.InvalidPath;
                }
            }
            break;

            case PropertyPath.PartType.Index:
            {
                if (properties is IPropertyIndexable <TContainer> indexable && indexable.TryGetProperty(ref container, part.Index, out property))
                {
                    using ((property as IAttributes).CreateAttributesScope(Property as IAttributes))
                    {
                        ((IPropertyAccept <TContainer>)property).Accept(this, ref container);
                    }
                }
                else
                {
                    ErrorCode = VisitErrorCode.InvalidPath;
                }
            }
            break;

            case PropertyPath.PartType.Key:
            {
                if (properties is IPropertyKeyable <TContainer, object> keyable && keyable.TryGetProperty(ref container, part.Key, out property))
                {
                    using ((property as IAttributes).CreateAttributesScope(Property as IAttributes))
                    {
                        ((IPropertyAccept <TContainer>)property).Accept(this, ref container);
                    }
                }
            void IPropertyBagVisitor.Visit <TContainer>(IPropertyBag <TContainer> properties, ref TContainer container)
            {
                var part = Path[PathIndex++];

                IProperty <TContainer> property;

                switch (part.Type)
                {
                case PropertyPath.PartType.Name:
                {
                    if (properties is IPropertiesNamed <TContainer> keyable && keyable.TryGetProperty(ref container, part.Name, out property))
                    {
                        property.Accept(this, ref container);
                    }
                    else
                    {
                        ErrorCode = VisitErrorCode.InvalidPath;
                    }
                }
                break;

                case PropertyPath.PartType.Index:
                {
                    if (properties is IPropertiesIndexed <TContainer> indexable && indexable.TryGetProperty(ref container, part.Index, out property))
                    {
                        property.Accept(this, ref container);
                    }
                    else
                    {
                        ErrorCode = VisitErrorCode.InvalidPath;
                    }
                }
                break;

                case PropertyPath.PartType.Key:
                {
                    if (properties is IPropertiesKeyed <TContainer, object> keyable && keyable.TryGetProperty(ref container, part.Key, out property))
                    {
                        property.Accept(this, ref container);
                    }
Exemplo n.º 16
0
        /// <summary>
        /// Gets the value of a property by path.
        /// </summary>
        /// <param name="container">The container whose property value will be returned.</param>
        /// <param name="path">The path of the property to get.</param>
        /// <param name="value">When this method returns, contains the value associated with the specified path, if the property is found. otherwise the default value for the <typeparamref name="TValue"/>.</param>
        /// <param name="errorCode">When this method returns, contains the error code.</param>
        /// <typeparam name="TContainer">The container type.</typeparam>
        /// <typeparam name="TValue">The value type.</typeparam>
        /// <returns><see langword="true"/> if the value exists at the specified path; otherwise, <see langword="false"/>.</returns>
        static bool GetValue <TContainer, TValue>(ref TContainer container, PropertyPath path, out TValue value, out VisitErrorCode errorCode)
        {
            if (null == path || path.PartsCount <= 0)
            {
                errorCode = VisitErrorCode.InvalidPath;
                value     = default;
                return(false);
            }

            var visitor = GetValueVisitor <TValue> .Pool.Get();

            visitor.Path = path;

            try
            {
                if (!Visit(ref container, visitor, out errorCode))
                {
                    value = default;
                    return(false);
                }

                value     = visitor.Value;
                errorCode = visitor.ErrorCode;
            }
            finally
            {
                GetValueVisitor <TValue> .Pool.Release(visitor);
            }

            return(errorCode == VisitErrorCode.Ok);
        }
        /// <summary>
        /// Tries to visit the specified <paramref name="container"/> by ref using the specified <paramref name="visitor"/>.
        /// </summary>
        /// <param name="visitor">The visitor.</param>
        /// <param name="container">The container to visit.</param>
        /// <param name="errorCode">When this method returns, contains the error code.</param>
        /// <typeparam name="TContainer">The declared container type.</typeparam>
        /// <returns><see langword="true"/> if the visitation succeeded; <see langword="false"/> otherwise.</returns>
        public static bool TryAccept <TContainer>(IPropertyBagVisitor visitor, ref TContainer container, out VisitErrorCode errorCode)
        {
            if (!RuntimeTypeInfoCache <TContainer> .IsContainerType)
            {
                errorCode = VisitErrorCode.InvalidContainerType;
                return(false);
            }

            // Can not visit a null container.
            if (RuntimeTypeInfoCache <TContainer> .CanBeNull)
            {
                if (EqualityComparer <TContainer> .Default.Equals(container, default))
                {
                    errorCode = VisitErrorCode.NullContainer;
                    return(false);
                }
            }

            if (!RuntimeTypeInfoCache <TContainer> .IsValueType && typeof(TContainer) != container.GetType())
            {
                if (!RuntimeTypeInfoCache.IsContainerType(container.GetType()))
                {
                    errorCode = VisitErrorCode.InvalidContainerType;
                    return(false);
                }

                var properties = PropertyBagStore.GetPropertyBag(container.GetType());

                if (null == properties)
                {
                    errorCode = VisitErrorCode.MissingPropertyBag;
                    return(false);
                }

                // At this point the generic parameter is useless to us since it's not the correct type.
                // Instead we need to retrieve the untyped property bag and accept on that. Since we don't know the type
                // We need to box the container and let the property bag cast it internally.
                var boxed = (object)container;
                properties.Accept(visitor, ref boxed);
                container = (TContainer)boxed;
            }
            else
            {
                var properties = PropertyBagStore.GetPropertyBag <TContainer>();

                if (null == properties)
                {
                    errorCode = VisitErrorCode.MissingPropertyBag;
                    return(false);
                }

                PropertyBag.AcceptWithSpecializedVisitor(properties, visitor, ref container);
            }

            errorCode = VisitErrorCode.Ok;
            return(true);
        }
Exemplo n.º 18
0
 void ICollectionElementPropertyGetter <TContainer> .VisitProperty <TProperty, TPropertyValue>(
     TProperty property,
     ref TContainer container, ref ChangeTracker changeTracker) =>
 ErrorCode = VisitSetValueProperty <TContainer, TProperty, TPropertyValue, TTargetValue>(property, ref container,
                                                                                         m_PropertyPath,
                                                                                         m_PropertyPathIndex, m_Value, ref changeTracker);
Exemplo n.º 19
0
            public void Invoke <T>()
            {
                var t = (T)m_Container;

                errorCode = TryVisitAtPathImpl(ref t, m_PropertyPath, m_PropertyPathIndex, m_Visitor, ref m_ChangeTracker);
            }
Exemplo n.º 20
0
 void ICollectionElementPropertyGetter <TContainer> .VisitCollectionProperty <TProperty, TPropertyValue>(
     TProperty property, ref TContainer container, ref ChangeTracker changeTracker)
 {
     ErrorCode = VisitCollectionPropertyAtPath <TContainer, TProperty, TPropertyValue>(property, ref container,
                                                                                       m_PropertyPath, m_PropertyPathIndex, m_Visitor, ref changeTracker);
 }
Exemplo n.º 21
0
 void IPropertyGetter <TContainer> .VisitProperty <TProperty, TPropertyValue>(TProperty property,
                                                                              ref TContainer container, ref ChangeTracker changeTracker) =>
 ErrorCode = VisitPropertyAtPath <TContainer, TProperty, TPropertyValue>(property, ref container, m_PropertyPath,
                                                                         m_PropertyPathIndex, m_Visitor, ref changeTracker);
Exemplo n.º 22
0
 void IPropertyGetter <TContainer> .VisitCollectionProperty <TProperty, TPropertyValue>(TProperty property,
                                                                                        ref TContainer container, ref ChangeTracker changeTracker) =>
 ErrorCode = VisitCollectionSetCountProperty <TContainer, TProperty, TPropertyValue>(property, ref container, m_PropertyPath,
                                                                                     m_PropertyPathIndex, m_Count, ref changeTracker);
 void IPropertyGetter <TContainer> .VisitCollectionProperty <TProperty, TPropertyValue>(TProperty property,
                                                                                        ref TContainer container, ref ChangeTracker changeTracker) =>
 ErrorCode = VisitCollectionGetValueProperty <TContainer, TProperty, TPropertyValue, TTargetValue>(property,
                                                                                                   ref container, m_PropertyPath, m_PropertyPathIndex, ref changeTracker, out Value);
Exemplo n.º 24
0
            public void Invoke <T>()
            {
                var t = (T)m_Container;

                m_ErrorCode = TrySetCountImpl(ref t, m_PropertyPath, m_PropertyPathIndex, m_Count, ref m_ChangeTracker);
            }
            public void Invoke <T>()
            {
                var t = (T)m_Container;

                m_ErrorCode = TryGetValueImpl <T, TValue>(ref t, m_PropertyPath, m_PropertyPathIndex, ref m_ChangeTracker, out m_Value);
            }
        /// <summary>
        /// Gets an <see cref="IProperty"/> on the specified container for the given <see cref="PropertyPath"/>.
        /// </summary>
        /// <remarks>
        /// While the container data is not actually read from or written to. The container itself is needed to resolve polymorphic fields and list elements.
        /// </remarks>
        /// <param name="container">The container tree to search.</param>
        /// <param name="path">The property path to resolve.</param>
        /// <param name="property">When this method returns, contains the property associated with the specified path, if the property is found; otherwise, null.</param>
        /// <param name="errorCode">When this method returns, contains the error code.</param>
        /// <typeparam name="TContainer">The strongly typed container.</typeparam>
        /// <returns><see langword="true"/> if the property was found at the specified path; otherwise, <see langword="false"/>.</returns>
        static bool GetProperty <TContainer>(ref TContainer container, PropertyPath path, out IProperty property, out VisitErrorCode errorCode)
        {
            var getPropertyVisitor = GetPropertyVisitor.Pool.Get();

            try
            {
                getPropertyVisitor.Path = path;
                if (!Visit(ref container, getPropertyVisitor, out errorCode))
                {
                    property = default;
                    return(false);
                }
                errorCode = getPropertyVisitor.ErrorCode;
                property  = getPropertyVisitor.Property;
                return(errorCode == VisitErrorCode.Ok);
            }
            finally
            {
                GetPropertyVisitor.Pool.Release(getPropertyVisitor);
            }
        }
Exemplo n.º 27
0
 void ICollectionElementPropertyGetter <TContainer> .VisitProperty <TProperty, TPropertyValue>(
     TProperty property, ref TContainer container, ref ChangeTracker changeTracker) =>
 ErrorCode = VisitGetCountProperty <TContainer, TProperty, TPropertyValue>(property, ref container, m_PropertyPath,
                                                                           m_PropertyPathIndex, ref changeTracker, out Count);