Пример #1
0
            VisitStatus IPropertyVisitor.VisitProperty <TProperty2, TContainer2, TValue2>(TProperty2 property, ref TContainer2 container, ref ChangeTracker changeTracker)
            {
                if (visitedFirst)
                {
                    return(VisitStatus.Handled);
                }
                if (!Result)
                {
                    return(VisitStatus.Handled);
                }
                visitedFirst = true;

                if (property.IsContainer)
                {
                    var bag = PropertyBagResolver.Resolve <TValue2>();
                    if (bag != null)
                    {
                        var ct       = new ChangeTracker();
                        var v        = property.GetValue(ref container);
                        var visitor2 = new FirstVisitor(Visitor);
                        bag.Accept(ref v, ref visitor2, ref ct);
                        Result = visitor2.Result;
                    }
                }
                return(VisitStatus.Handled);
            }
Пример #2
0
            public static bool Execute(object container, InspectorVisitor <T> visitor, IProperty property, PropertyPath path,
                                       string propertyName, InspectorVisitLevel visitLevel)
            {
                var action = new GetCustomInspectorCallback(visitor, property, path, propertyName, visitLevel);

                PropertyBagResolver.Resolve(container.GetType()).Cast(ref action);
                return(action.Visited);
            }
Пример #3
0
        static void AssertCollectionPropertyType <TContainer>(ref TContainer container, string name, Type type)
        {
            var change = new ChangeTracker();
            var action = new AssertCollectionPropertyTypeGetter <TContainer>
            {
                ExpectedPropertyType = type
            };

            PropertyBagResolver.Resolve <TContainer>().FindProperty(name, ref container, ref change, ref action);
        }
        public static object ReadBoxedClass(Type type, PropertiesBinaryReader reader)
        {
            var forwarder = new ReadBoxedClassForwarder {
                reader = reader, Container = null
            };
            var propertyBag = PropertyBagResolver.Resolve(type);

            propertyBag.Cast(ref forwarder);

            return(forwarder.Container);
        }
Пример #5
0
        public void PropertyBag_Accept_Object()
        {
            var untypedPropertyBag = PropertyBagResolver.Resolve(typeof(TestPrimitiveContainer));
            var boxedContainer     = (object)default(TestPrimitiveContainer);
            var changeTracker      = default(ChangeTracker);

            untypedPropertyBag.Accept(ref boxedContainer, new SetPropertyVisitor {
                Name = nameof(TestPrimitiveContainer.Int32Value), Value = 42
            }, ref changeTracker);
            Assert.That(((TestPrimitiveContainer)boxedContainer).Int32Value, Is.EqualTo(42));
        }
 public static void Visit <TContainer, TVisitor>(ref TContainer container, TVisitor visitor, ref ChangeTracker changeTracker)
     where TVisitor : IPropertyVisitor
 {
     if (RuntimeTypeInfoCache <TContainer> .IsAbstractOrInterface())
     {
         PropertyBagResolver.Resolve(container.GetType())?.Accept(container, visitor, ref changeTracker);
     }
     else
     {
         PropertyBagResolver.Resolve <TContainer>()?.Accept(ref container, visitor, ref changeTracker);
     }
 }
Пример #7
0
 public static void Visit <TContainer, TVisitor>(ref TContainer container, TVisitor visitor, ref ChangeTracker changeTracker)
     where TVisitor : IPropertyVisitor
 {
     if (!RuntimeTypeInfoCache <TContainer> .IsValueType() && null != container && typeof(TContainer) != container.GetType())
     {
         var boxed = (object)container;
         PropertyBagResolver.Resolve(container.GetType())?.Accept(ref boxed, visitor, ref changeTracker);
         container = (TContainer)boxed;
     }
     else
     {
         PropertyBagResolver.Resolve <TContainer>()?.Accept(ref container, visitor, ref changeTracker);
     }
 }
Пример #8
0
 VisitStatus IPropertyVisitor.VisitProperty <TProperty2, TContainer2, TValue2>(TProperty2 property, ref TContainer2 container, ref ChangeTracker changeTracker)
 {
     if (property.IsContainer)
     {
         var bag = PropertyBagResolver.Resolve <TValue2>();
         if (bag != null)
         {
             var ct = new ChangeTracker();
             var v  = property.GetValue(ref container);
             bag.Accept(ref v, ref Visitor, ref ct);
         }
     }
     return(VisitStatus.Handled);
 }
        public static void WriteBoxedType <TVisitor>(object container, TVisitor visitor)
            where TVisitor : IPropertyVisitor
        {
            var changeTracker = new ChangeTracker();
            var resolved      = PropertyBagResolver.Resolve(container.GetType());

            if (resolved != null)
            {
                resolved.Accept(ref container, ref visitor, ref changeTracker);
            }
            else
            {
                throw new ArgumentException("Not supported");
            }
        }
        internal static void PatchEntityForPrefabInBoxedType(object container, SparseEntityRemapInfo *remapInfo, int remapInfoCount)
        {
            var visitor       = new EntityRemappingVisitor(remapInfo, remapInfoCount);
            var changeTracker = new ChangeTracker();
            var type          = container.GetType();

            var resolved = PropertyBagResolver.Resolve(type);

            if (resolved != null)
            {
                resolved.Accept(ref container, ref visitor, ref changeTracker);
            }
            else
            {
                throw new ArgumentException($"Type '{type.FullName}' not supported for visiting.");
            }
        }
Пример #11
0
 public static void Transfer <TDestination, TSource>(ref TDestination destination, ref TSource source, ref ChangeTracker changeTracker)
 {
     if (RuntimeTypeInfoCache <TSource> .IsAbstractOrInterface())
     {
         var propertyBag = PropertyBagResolver.Resolve(source.GetType());
         var action      = new TransferAbstractType <TDestination>
         {
             Destination     = destination,
             SourceContainer = (object)source
         };
         propertyBag.Cast(action);
         destination = action.Destination;
     }
     else
     {
         Visit(ref destination, new TransferVisitor <TSource>(source), ref changeTracker);
     }
 }