public void Deny_Unrestricted() { DataBindingCollection dbc = new DataBindingCollection(); Assert.AreEqual(0, dbc.Count, "Count"); Assert.IsFalse(dbc.IsReadOnly, "IsReadOnly"); Assert.IsFalse(dbc.IsSynchronized, "IsSynchronized"); dbc.Add(db); Assert.AreSame(db, dbc["property"], "this[string]"); Assert.IsNotNull(dbc.RemovedBindings, "RemovedBindings"); Assert.IsNotNull(dbc.SyncRoot, "SyncRoot"); Assert.IsNotNull(dbc.GetEnumerator(), "GetEnumerator"); dbc.CopyTo(new DataBinding[1], 0); dbc.Clear(); dbc.Add(db); dbc.Remove(db); dbc.Add(db); dbc.Remove("property"); dbc.Remove("property", true); dbc.Changed += new EventHandler(Handler); Assert.IsFalse(dbc.Contains("property"), "Contains"); dbc.Changed -= new EventHandler(Handler); }
private void OnOKButtonClick(object sender, EventArgs e) { if (this._bindingsDirty) { ExpressionBindingCollection expressions = ((IExpressionsAccessor)this.Control).Expressions; DataBindingCollection dataBindings = ((IDataBindingsAccessor)this.Control).DataBindings; expressions.Clear(); foreach (BindablePropertyNode node in this._bindablePropsTree.Nodes) { if (node.IsBound) { expressions.Add(node.Binding); if (dataBindings.Contains(node.Binding.PropertyName)) { dataBindings.Remove(node.Binding.PropertyName); } } } foreach (ExpressionBinding binding in this._complexBindings.Values) { expressions.Add(binding); } } base.DialogResult = DialogResult.OK; base.Close(); }
[Test] public void ChangeTest() { DataBindingCollection a = new DataBindingCollection(); a.Changed += delegate { changed = true; }; DataBinding b = new DataBinding("a", typeof(DataBindingCollectionTest), "b"); a.Add(b); Assert.AreEqual(true, changed, "DB1"); changed = false; a.Clear(); Assert.AreEqual(false, changed, "DB2"); a.Remove(b); Assert.AreEqual(true, changed, "DB3"); }
protected override void OnBindingsCollectionChanged(string propName) { // This method actually forms an DataBindingExpression of the design time and associates it to the Property of the Control. IHtmlControlDesignerBehavior myHtmlControlDesignBehavior = Behavior; DataBindingCollection myDataBindingCollection; DataBinding myDataBinding1, myDataBinding2; String myStringReplace1, myDataBindingExpression1, removedBinding, removedBindingAfterReplace, myDataBindingExpression2, myStringReplace2; string[] removedBindings1, removedBindings2; Int32 temp; IEnumerator myEnumerator; if (myHtmlControlDesignBehavior == null) { return; } // <Snippet8> DataBindingCollection myDataBindingCollection1 = new DataBindingCollection(); myDataBindingCollection1 = myDataBindingCollection = DataBindings; // </Snippet8> if (propName != null) { myDataBinding1 = myDataBindingCollection[propName]; myStringReplace1 = propName.Replace(".", "-"); if (myDataBinding1 == null) { myHtmlControlDesignBehavior.RemoveAttribute(myStringReplace1, true); return; } // DataBinding is not null. myDataBindingExpression1 = String.Concat("<%#", myDataBinding1.Expression, "%>"); myHtmlControlDesignBehavior.SetAttribute(myStringReplace1, myDataBindingExpression1, true); int index = myStringReplace1.IndexOf("-"); } else { // <Snippet9> removedBindings2 = removedBindings1 = DataBindings.RemovedBindings; // </Snippet9> temp = 0; while (removedBindings2.Length > temp) { removedBinding = removedBindings2[temp]; removedBindingAfterReplace = removedBinding.Replace('.', '-'); myHtmlControlDesignBehavior.RemoveAttribute(removedBindingAfterReplace, true); temp = temp + 1; } // <Snippet10> myDataBindingCollection = DataBindings; myEnumerator = myDataBindingCollection.GetEnumerator(); while (myEnumerator.MoveNext()) { // <Snippet11> // <Snippet12> myDataBinding2 = (DataBinding)myEnumerator.Current; String dataBindingOutput1, dataBindingOutput2, dataBindingOutput3; dataBindingOutput1 = String.Concat("The property name is ", myDataBinding2.PropertyName); dataBindingOutput2 = String.Concat("The property type is ", myDataBinding2.PropertyType.ToString(), "-", dataBindingOutput1); dataBindingOutput3 = String.Concat("The expression is ", myDataBinding2.Expression, "-", dataBindingOutput2); WriteToFile(dataBindingOutput3); // </Snippet12> // </Snippet11> myDataBindingExpression2 = String.Concat("<%#", myDataBinding2.Expression, "%>"); myStringReplace2 = myDataBinding2.PropertyName.Replace(".", "-"); myHtmlControlDesignBehavior.SetAttribute(myStringReplace2, myDataBindingExpression2, true); int index = myStringReplace2.IndexOf('-'); }// while loop ends // </Snippet10> // <Snippet13> // <Snippet14> // <Snippet15> string dataBindingOutput4, dataBindingOutput5, dataBindingOutput6, dataBindingOutput7, dataBindingOutput8; dataBindingOutput4 = String.Concat("The Count of the collection is ", myDataBindingCollection1.Count); dataBindingOutput5 = String.Concat("The IsSynchronised property of the collection is ", myDataBindingCollection1.IsSynchronized, "-", dataBindingOutput4); dataBindingOutput6 = String.Concat("The IsReadOnly property of the collection is ", myDataBindingCollection1.IsReadOnly, "-", dataBindingOutput5); WriteToFile(dataBindingOutput6); // </Snippet15> // </Snippet14> // </Snippet13> // <Snippet16> System.Array dataBindingCollectionArray = Array.CreateInstance(typeof(object), myDataBindingCollection1.Count); myDataBindingCollection1.CopyTo(dataBindingCollectionArray, 0); dataBindingOutput7 = String.Concat("The count of DataBindingArray is ", dataBindingCollectionArray.Length); WriteToFile(dataBindingOutput7); // </Snippet16> IEnumerator myEnumerator1 = myDataBindingCollection1.GetEnumerator(); if (myEnumerator1.MoveNext()) { // <Snippet17> myDataBinding1 = (DataBinding)myEnumerator1.Current; dataBindingOutput8 = String.Concat("The HashCode is", myDataBinding1.GetHashCode().ToString()); WriteToFile(dataBindingOutput8); // <Snippet18> myDataBindingCollection1.Remove(myDataBinding1); dataBindingOutput8 = String.Concat("The Count of the collection after DataBinding is removed is ", myDataBindingCollection1.Count); WriteToFile(dataBindingOutput8); // </Snippet18> // </Snippet17> } else { myDataBinding1 = (DataBinding)myEnumerator1.Current; // <Snippet19> myDataBindingCollection1.Remove("Text", true); dataBindingOutput8 = String.Concat("The Count of the collection after DataBinding is removed is ", myDataBindingCollection1.Count); WriteToFile(dataBindingOutput8); // </Snippet19> // <Snippet20> myDataBindingCollection1.Clear(); dataBindingOutput8 = String.Concat("The Count of the collection after clear method is called ", myDataBindingCollection1.Count); WriteToFile(dataBindingOutput8); // </Snippet20> } } // else ends here. }