コード例 #1
0
        /// <summary>
        /// Create a value binding.
        /// </summary>
        public IValueBinding CreateValueBinding(object parentObject, object value, Type type)
        {
            IValueBinding valueBinding;

            //
            // Recurse if neccessary and setup bindings for subobjects.
            //
            if (RecurseTypeForBindings(type))
            {
                // Get the sub-object from the property.
                if (type.IsArray)
                {
                    valueBinding = new ArrayBinding((Array)value, this);
                }
                else if (value is IList)
                {
                    valueBinding = new ListBinding((IList)value, this);
                }
                else
                {
                    valueBinding = new ObjectBinding(value, this);
                }
            }
            else
            {
                valueBinding = new PrimitiveBinding(value);
            }
            return(valueBinding);
        }
コード例 #2
0
 /// <summary>
 /// Initializes the test object.
 /// </summary>
 private void InitTestObject(TestClass obj)
 {
     testObject = new ObjectBinding(obj, mockBindingsFactory.Object);
 }
コード例 #3
0
        public void test_find_property_binding()
        {
            var obj = new TestClass()
            {
                X = 15
            };

            var mockObjectPropertyBinding = new Mock<IObjectPropertyBinding>();
            var mockBindingsFactory = new Mock<IBindingsFactory>();

            mockObjectPropertyBinding
                .Setup(m => m.PropertyName)
                .Returns("X");

            mockObjectPropertyBinding
                .Setup(m => m.FindNestedBinding(string.Empty))
                .Returns(mockObjectPropertyBinding.Object);

            mockBindingsFactory
                .Setup(m => m.CreateObjectBindings(obj))
                .Returns(new IObjectPropertyBinding[] { mockObjectPropertyBinding.Object });

            var testObject = new ObjectBinding(obj, mockBindingsFactory.Object);

            Assert.Equal(mockObjectPropertyBinding.Object, testObject.FindNestedBinding("X"));
        }
コード例 #4
0
        public void test_find_nested_property_binding()
        {
            var obj = new
            {
                X = new ObservableList<int>()
            };

            var mockObjectPropertyBinding = new Mock<IObjectPropertyBinding>();
            var mockBindingsFactory = new Mock<IBindingsFactory>();

            mockObjectPropertyBinding
                .Setup(m => m.PropertyName)
                .Returns("X");

            mockObjectPropertyBinding
                .Setup(m => m.FindNestedBinding("0"))
                .Returns(mockObjectPropertyBinding.Object);

            mockBindingsFactory
                .Setup(m => m.CreateObjectBindings(obj))
                .Returns(new IObjectPropertyBinding[] { mockObjectPropertyBinding.Object });

            var testObject = new ObjectBinding(obj, mockBindingsFactory.Object);

            Assert.Equal(mockObjectPropertyBinding.Object, testObject.FindNestedBinding("X.0"));
        }
コード例 #5
0
        public void property_changing_is_propagated_from_child_node_after_reconnect()
        {
            var propertyName = "X";

            var obj = new TestClass();
            var childEventStream = new Subject<BoundPropertyChangingEventArgs>();

            InitMocks();
            InitTestObjectWithPropertyChangingStream(childEventStream, obj);

            var testObject = new ObjectBinding(obj, mockBindingsFactory.Object);

            List<BoundPropertyChangingEventArgs> events = new List<BoundPropertyChangingEventArgs>();

            testObject.PropertyChangingEventStream.Subscribe(ev => events.Add(ev));

            testObject.Disconnect();

            Assert.Empty(events);

            testObject.Connect(obj);

            childEventStream.OnNext(new BoundPropertyChangingEventArgs(propertyName, mockObjectPropertyBinding.Object));

            Assert.Equal(1, events.Count);
            Assert.Equal(propertyName, events[0].PropertyName);
            Assert.Equal(mockObjectPropertyBinding.Object, events[0].Binding);
        }
コード例 #6
0
 /// <summary>
 /// Create a value binding.
 /// </summary>
 public IValueBinding CreateValueBinding(object parentObject, object value, Type type)
 {
     IValueBinding valueBinding;
     //
     // Recurse if neccessary and setup bindings for subobjects.
     //
     if (RecurseTypeForBindings(type))
     {
         // Get the sub-object from the property.
         if (type.IsArray)
         {
             valueBinding = new ArrayBinding((Array)value, this);
         }
         else if (value is IList)
         {
             valueBinding = new ListBinding((IList)value, this);
         }
         else
         {
             valueBinding = new ObjectBinding(value, this);
         }
     }
     else
     {
         valueBinding = new PrimitiveBinding(value);
     }
     return valueBinding;
 }