public void ReflectedPropertyBagVisitor_Transfer_NestedContainer()
        {
            PropertyBagResolver.Register(new ReflectedPropertyBagProvider().Generate <SimpleContainer>());
            PropertyBagResolver.Register(new ReflectedPropertyBagProvider().Generate <NestedContainer>());
            PropertyBagResolver.Register(new ReflectedPropertyBagProvider().Generate <Foo>());

            var source = new SimpleContainer
            {
                Int32Value = 15,
                Nested     = new NestedContainer
                {
                    Int32Value = 42
                }
            };

            var foo = new Foo
            {
                Nested = new NestedContainer {
                    Int32Value = 10
                }
            };

            using (var result = PropertyContainer.Transfer(ref foo, ref source))
            {
                Assert.That(result.Succeeded, Is.True);
                Assert.AreEqual(42, foo.Nested.Int32Value);
            }
        }
        public void ReflectedPropertyBagVisitor_Visit()
        {
            PropertyBagResolver.Register(new ReflectedPropertyBagProvider().Generate <SimpleContainer>());
            PropertyBagResolver.Register(new ReflectedPropertyBagProvider().Generate <NestedContainer>());

            PropertyContainer.Visit(new SimpleContainer(), new VoidVisitor());
        }
Exemplo n.º 3
0
        public void ReflectedPropertyBag_SetValue_ReadOnly()
        {
            PropertyBagResolver.Register(new ReflectedPropertyBagProvider().Generate <ContainerWithSpecialAccess>());
            var instance = default(ContainerWithSpecialAccess);

            Assert.DoesNotThrow(() =>
            {
                PropertyContainer.SetValue(ref instance, "m_ReadWriteField", 10);
            });

            Assert.Throws <InvalidOperationException>(() =>
            {
                PropertyContainer.SetValue(ref instance, "m_ExplicitReadOnlyField", 10);
            });

            Assert.DoesNotThrow(() =>
            {
                PropertyContainer.SetValue(ref instance, "ReadWriteProperty", 10);
            });

            Assert.Throws <InvalidOperationException>(() =>
            {
                PropertyContainer.SetValue(ref instance, "ImplicitReadOnlyProperty", 10);
            });
        }
        public void ReflectedPropertyBagVisitor_Transfer_Collections()
        {
            PropertyBagResolver.Register(new ReflectedPropertyBagProvider().Generate <ContainerWithCollections>());

            var source = new ContainerWithCollections
            {
                IListGeneric = new List <int> {
                    4, 5, 6
                },
                ListGeneric = new List <int> {
                    7
                },
                Array = new [] { 6, 9, 10, 11 }
            };

            var destination = new ContainerWithCollections
            {
                IListGeneric = new List <int>(),
                ListGeneric  = new List <int>(),
                Array        = new int[0]
            };

            var changeTracker = new ChangeTracker(null);

            PropertyContainer.Transfer(ref destination, ref source, ref changeTracker);
            Assert.That(destination.IListGeneric.Count, Is.EqualTo(3));
            Assert.That(destination.ListGeneric.Count, Is.EqualTo(1));
            Assert.That(destination.Array.Length, Is.EqualTo(4));
        }
        public void ReflectedPropertyBagVisitor_Transfer_NestedContainer()
        {
            PropertyBagResolver.Register(new ReflectedPropertyBagProvider().Generate <SimpleContainer>());
            PropertyBagResolver.Register(new ReflectedPropertyBagProvider().Generate <NestedContainer>());
            PropertyBagResolver.Register(new ReflectedPropertyBagProvider().Generate <Foo>());

            var source = new SimpleContainer
            {
                Int32Value = 15,
                Nested     = new NestedContainer
                {
                    Int32Value = 42
                }
            };

            var foo = new Foo
            {
                Nested = new NestedContainer {
                    Int32Value = 10
                }
            };

            var changeTracker = new ChangeTracker(null);

            PropertyContainer.Transfer(ref foo, ref source, ref changeTracker);
            Assert.AreEqual(42, foo.Nested.Int32Value);
        }
 public void SetUp()
 {
     PropertyBagResolver.Register(new TestNestedContainerPropertyBag());
     PropertyBagResolver.Register(new TestPrimitiveContainerPropertyBag());
     PropertyBagResolver.Register(new TestArrayContainerPropertyBag());
     PropertyBagResolver.Register(new CustomDataFooPropertyBag());
     PropertyBagResolver.Register(new CustomDataBarPropertyBag());
 }
Exemplo n.º 7
0
 public static void InitializePropertyBags()
 {
     PropertyBagResolver.Register(new TestNestedContainerPropertyBag());
     PropertyBagResolver.Register(new TestPrimitiveContainerPropertyBag());
     PropertyBagResolver.Register(new TestArrayContainerPropertyBag());
     PropertyBagResolver.Register(new TestListContainerPropertyBag());
     PropertyBagResolver.Register(new CustomDataFooPropertyBag());
     PropertyBagResolver.Register(new CustomDataBarPropertyBag());
 }
Exemplo n.º 8
0
        static DomainReload()
        {
            // Save and close the project during an assembly reload or application shutdown
            AssemblyReloadEvents.beforeAssemblyReload += HandleDomainWillUnload;
            EditorApplication.quitting += HandleDomainWillUnload;

            // Register to unity application events
            EditorApplication.update += HandleUpdate;

            PropertyBagResolver.Register(new SessionState.PropertyBag());
        }
Exemplo n.º 9
0
        private static void Initialize()
        {
            var provider = new ReflectedPropertyBagProvider();

            provider.AddGenerator(new CharPropertyGenerator());

            PropertyBagResolver.RegisterProvider(provider);
            PropertyBagResolver.Register(new SerializedObjectViewPropertyBag());

            AssemblyReloadEvents.beforeAssemblyReload += HandleDomainWillUnload;
            EditorApplication.update += HandleUpdate;
            Bridge.EditorApplication.UpdateMainWindowTitleHandler += MainWindowTitleHandler;
        }
Exemplo n.º 10
0
        public void ReflectedPropertyBag_SetValue_CSharpProperties()
        {
            PropertyBagResolver.Register(new ReflectedPropertyBagProvider().Generate <ContainerWithProperties>());
            var instance = default(ContainerWithProperties);

            PropertyContainer.SetValue(ref instance, "IntProperty", 10);

            Assert.That(instance.IntProperty, Is.EqualTo(10));

            Assert.Throws <InvalidOperationException>(() =>
            {
                PropertyContainer.SetValue(ref instance, "HiddenInt32Property", 10);
            });
        }
Exemplo n.º 11
0
        public void ReflectedPropertyBag_SetValue_PrivateFields()
        {
            PropertyBagResolver.Register(new ReflectedPropertyBagProvider().Generate <SimpleContainerWithPrivateFields>());
            var instance = default(SimpleContainerWithPrivateFields);

            PropertyContainer.SetValue(ref instance, "m_Int32Value", 10);

            Assert.That(instance.Int32Value, Is.EqualTo(10));

            Assert.Throws <InvalidOperationException>(() =>
            {
                PropertyContainer.SetValue(ref instance, "m_HiddenInt32Value", 10);
            });
        }
Exemplo n.º 12
0
 static JsonObject()
 {
     PropertyBagResolver.Register(new JsonObjectPropertyBag());
 }
Exemplo n.º 13
0
 static EntityContainer()
 {
     PropertyBagResolver.Register(new EntityContainerPropertyBag());
     PropertyBagResolver.RegisterProvider(new ReflectedPropertyBagProvider());
 }
 static EntityContainer()
 {
     PropertyBagResolver.Register(new EntityContainerPropertyBag());
 }
Exemplo n.º 15
0
 static SerializedObjectView()
 {
     PropertyBagResolver.Register(new SerializedObjectViewPropertyBag());
 }
Exemplo n.º 16
0
 static DynamicBufferContainer()
 {
     PropertyBagResolver.Register(new PropertyBag());
 }
Exemplo n.º 17
0
 static SceneContainer()
 {
     PropertyBagResolver.Register(new ScenePropertyBag());
 }