https://bugzilla.novell.com/show_bug.cgi?id=664831
https://bugzilla.novell.com/show_bug.cgi?id=664831#c0 Summary: Inconsistent Binding.ReadValue behaviour when binding hasn't begun Classification: Mono Product: Mono: Class Libraries Version: 2.6.x Platform: x86 OS/Version: Windows 7 Status: NEW Severity: Normal Priority: P5 - None Component: Windows.Forms AssignedTo: [email protected] ReportedBy: [email protected] QAContact: [email protected] Found By: --- Blocker: --- User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/532.5 (KHTML, like Gecko) Chrome/4.1.249.1036 Safari/532.5 When calling Binding.ReadValue() when binding hasn't begun, ms.net sets a null (or default) value on the control whereas mono sets a value from the data source. Reproducible: Always Steps to Reproduce: Unit test to reproduce: [Test] public void Test_ReadValueWhenNotBinding() { TestDataSource dataSource = new TestDataSource(); dataSource.IntProperty = 10; Control.ControlValue = 10; var binding = Control.DataBindings.Add("ControlValue", dataSource, "IntProperty"); AssertEquals(10, Control.ControlValue, "Pre-condition"); binding.ReadValue(); AssertEquals(0, Control.ControlValue, "Null or default value should be set on the data source"); } TestControl control; TestControl Control { get { return control ?? (control = new TestControl()); } } class TestControl : Control { public event EventHandler ControlValueChanged; public int ControlValue { get { int result; int.TryParse(Text, out result); return result; } set { Text = value.ToString(); if (ControlValueChanged != null) { ControlValueChanged(this, EventArgs.Empty); } } } } Actual Results: Unit test fails Expected Results: Unit test should pass, as it does with ms.net. These changes fix the issue and cause the test above to pass. Code added to Binding.PushData: try { data = FormatData (data); if (!IsBinding) // line added data = null; // line added SetControlValue (data); } catch (Exception e) { Code added to Binding.PushData: void PushData (bool force) { if (manager != null && (manager.Count == 0 || manager.Position == -1)) // line added SetControlValue(null); // line added if (manager == null || manager.IsSuspended || manager.Count == 0 || manager.Position == -1) return; Code added to Binding.SetPropertyValue private void SetPropertyValue (object data) { PropertyDescriptor pd = TypeDescriptor.GetProperties (manager.Current).Find (binding_member_info.BindingField, true); if (pd.IsReadOnly) return; data = ParseData (data, pd.PropertyType); pd.SetValue(manager.Current, pd.PropertyType != typeof(object) && data is DBNull ? null : // this line of the statement added data); } -- Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- You are the QA contact for the bug. You are the assignee for the bug. _______________________________________________ mono-bugs maillist - [email protected] http://lists.ximian.com/mailman/listinfo/mono-bugs
