コード例 #1
0
        // GET: DMultipleModelsInView
        public ActionResult Index()
        {
            List <ModelA> listModelA = new List <ModelA>();
            List <ModelB> listModelB = new List <ModelB>();

            listModelA.Add(new ModelA {
                Name = "Juan"
            });
            listModelA.Add(new ModelA {
                Name = "Jose"
            });
            listModelA.Add(new ModelA {
                Name = "Pegro"
            });

            listModelB.Add(new ModelB {
                Country = "Colombia"
            });
            listModelB.Add(new ModelB {
                Country = "Peru"
            });
            listModelB.Add(new ModelB {
                Country = "Mexico"
            });

            ModelC modelC = new ModelC();

            modelC.modelAs = listModelA;
            modelC.modelBs = listModelB;
            modelC.Age     = 27;

            return(View(modelC));
        }
コード例 #2
0
        // GET: TwoModel
        public ActionResult Index()
        {
            List <ModelA> listA = new List <ModelA>();
            List <ModelB> listB = new List <ModelB>();

            listA.Add(new ModelA {
                Name = "Shuvo"
            });
            listA.Add(new ModelA {
                Name = "Roy"
            });
            listA.Add(new ModelA {
                Name = "Hridoy"
            });

            listB.Add(new ModelB {
                City = "Dhaka"
            });
            listB.Add(new ModelB {
                City = "Rangpur"
            });
            listB.Add(new ModelB {
                City = "Dhaka"
            });

            ModelC finalItem = new ModelC();

            finalItem.ListA = listA;
            finalItem.ListB = listB;
            finalItem.age   = 28;
            return(View(finalItem));
        }
コード例 #3
0
        public IActionResult GetCamelComplex()
        {
            var model = new ModelC();

            return(Json(model, new JsonSerializerSettings()
            {
                ContractResolver = new CamelCasePropertyNamesContractResolver(),
                Formatting = Formatting.Indented
            }));
        }
コード例 #4
0
        public void TestItemNestedPropertyChanged()
        {
            var source = new ModelD();
            var target = new TestViewFactory();

            var go = new GameObject("Test");
            var dc = go.AddComponent <DataContext>();

            // create collection binding
            var binding = new CollectionBinding("List", target);

            dc.AddBinding(binding);

            BindingManager.Instance.AddSource(source, "Test");
            BindingManager.Instance.AddDataContext(dc, "Test");

            // add item
            var item = new ModelC();

            item.NestedValue.IntValue = 2;
            source.List.Add(item);

            var itemView        = binding.BindingDictionary[item];
            var itemDataContext = itemView.GetComponent <IDataContext>();

            // add item binding
            var itemTarget  = new ModelA();
            var itemBinding = new Binding("NestedValue.IntValue", itemTarget, "IntValue");

            itemDataContext.AddBinding(itemBinding);

            // check item value
            Assert.AreEqual(2, itemTarget.IntValue);

            // update value
            item.NestedValue.IntValue = 3;
            Assert.AreEqual(2, itemTarget.IntValue);

            // notify
            BindingManager.Instance.NotifyItemPropertyChanged(source, source, source.List, item, item.NestedValue, "IntValue");
            Assert.AreEqual(3, itemTarget.IntValue);

            // update value
            item.NestedValue.IntValue = 4;
            Assert.AreEqual(3, itemTarget.IntValue);

            // notify with null
            BindingManager.Instance.NotifyItemPropertyChanged(source, source, source.List, item, item.NestedValue, null);
            Assert.AreEqual(4, itemTarget.IntValue);

            BindingManager.Instance.Clear();
            target.Clear();
            GameObject.DestroyImmediate(go);
        }
コード例 #5
0
        public void TestPropertyChangedBoth()
        {
            var source = new ModelC();
            var target = new ModelC();

            var go = new GameObject();
            var dc = go.AddComponent <DataContext>();

            var bindingA = new Binding("IntValue", target, "IntValue");
            var bindingB = new Binding("NestedValue.IntValue", target, "NestedValue.IntValue");

            dc.AddBinding(bindingA);
            dc.AddBinding(bindingB);

            BindingManager.Instance.AddSource(source, "Test");
            BindingManager.Instance.AddDataContext(dc, "Test");

            // set value
            source.IntValue             = 20;
            source.NestedValue.IntValue = 2;
            Assert.AreEqual(0, target.IntValue);
            Assert.AreEqual(0, target.NestedValue.IntValue);

            // notify source
            BindingManager.Instance.NotifyPropertyChanged(source, "IntValue");
            Assert.AreEqual(20, target.IntValue);
            Assert.AreEqual(0, target.NestedValue.IntValue);

            // notify nested
            source.IntValue             = 30;
            source.NestedValue.IntValue = 3;
            BindingManager.Instance.NotifyPropertyChanged(source, source.NestedValue, "IntValue");
            Assert.AreEqual(20, target.IntValue);
            Assert.AreEqual(3, target.NestedValue.IntValue);

            // notify source with null path
            source.IntValue             = 40;
            source.NestedValue.IntValue = 4;
            BindingManager.Instance.NotifyPropertyChanged(source, null);
            Assert.AreEqual(40, target.IntValue);
            Assert.AreEqual(3, target.NestedValue.IntValue);

            // notify nested with null path
            source.IntValue             = 50;
            source.NestedValue.IntValue = 5;
            BindingManager.Instance.NotifyPropertyChanged(source, source.NestedValue, null);
            Assert.AreEqual(40, target.IntValue);
            Assert.AreEqual(5, target.NestedValue.IntValue);

            GameObject.DestroyImmediate(go);
            BindingManager.Instance.Clear();
        }
コード例 #6
0
        public void BindToNestedProperty()
        {
            var source = new ModelC();
            var target = new ModelA();

            // bind to nested property
            var binding = new Binding("NestedValue.IntValue", target, "IntValue");

            binding.Bind(source);

            source.NestedValue.IntValue = 2;
            Assert.AreEqual(0, target.IntValue);

            // notify nested property changed
            binding.HandleSourcePropertyChanged(source.NestedValue, "IntValue");
            Assert.AreEqual(2, target.IntValue);

            source.NestedValue.IntValue = 3;

            // notify with null property name
            binding.HandleSourcePropertyChanged(source.NestedValue, null);
            Assert.AreEqual(3, target.IntValue);
        }
コード例 #7
0
        public IActionResult GetComplex()
        {
            var model = new ModelC();

            return(Ok(model));
        }