From 52c3b98acc50be0b74c9e9c6c8a951fd6cc9ff1a Mon Sep 17 00:00:00 2001 From: Chris Toshok Date: Mon, 21 May 2007 04:57:02 +0000 Subject: [PATCH] In Test/System.Data: 2007-05-18 Chris Toshok * DataViewTest.cs (DefaultColumnNameAddListChangedTest): new test for figuring out the sorts of events raised between 1.1 and 2.0 when you add a column with the default name. In System.Data: 2007-05-18 Chris Toshok * DataColumnCollection.cs (Add ()): handle the default name case in Add(DataColumn). (Add (string)): same - let Add(DataColumn) handle the default name setting. (Add (DataColumn)): in the 1.1 case, we need to add the column's PropertyChanged handler *before* possibly setting the column name to the default so we emit the right events (Changed/Added). In the 2.0 case, we add the event handler after the name is set, and therefore only emit the Added event. svn path=/trunk/mcs/; revision=77738 --- mcs/class/System.Data/System.Data/ChangeLog | 12 ++++ .../System.Data/DataColumnCollection.cs | 22 ++++---- mcs/class/System.Data/Test/System.Data/ChangeLog | 6 ++ .../System.Data/Test/System.Data/DataViewTest.cs | 66 ++++++++++++++++++++++ 4 files changed, 96 insertions(+), 10 deletions(-) diff --git a/mcs/class/System.Data/System.Data/ChangeLog b/mcs/class/System.Data/System.Data/ChangeLog index ff1bb429bd7..bc4613b40a9 100644 --- a/mcs/class/System.Data/System.Data/ChangeLog +++ b/mcs/class/System.Data/System.Data/ChangeLog @@ -1,3 +1,15 @@ +2007-05-18 Chris Toshok + + * DataColumnCollection.cs (Add ()): handle the default name case + in Add(DataColumn). + (Add (string)): same - let Add(DataColumn) handle the default name + setting. + (Add (DataColumn)): in the 1.1 case, we need to add the column's + PropertyChanged handler *before* possibly setting the column name + to the default so we emit the right events (Changed/Added). In + the 2.0 case, we add the event handler after the name is set, and + therefore only emit the Added event. + 2007-05-07 Adar Wesley * ConstraintCollection.cs: added CopyTo method with strongly typed Constraint[] diff --git a/mcs/class/System.Data/System.Data/DataColumnCollection.cs b/mcs/class/System.Data/System.Data/DataColumnCollection.cs index 4b41cc16a25..58ab7c6c39a 100644 --- a/mcs/class/System.Data/System.Data/DataColumnCollection.cs +++ b/mcs/class/System.Data/System.Data/DataColumnCollection.cs @@ -168,8 +168,7 @@ namespace System.Data { #endif DataColumn Add() { - string defaultName = GetNextDefaultColumnName (); - DataColumn column = new DataColumn (defaultName); + DataColumn column = new DataColumn (null); Add (column); return column; } @@ -266,6 +265,13 @@ namespace System.Data { if (column == null) throw new ArgumentNullException ("column", "'column' argument cannot be null."); +#if !NET_2_0 + /* in 1.1, they must do this here, as the + * setting of ColumnName below causes an event + * to be raised */ + column.PropertyChanged += new PropertyChangedEventHandler (ColumnPropertyChanged); +#endif + if (column.ColumnName.Equals(String.Empty)) { column.ColumnName = GetNextDefaultColumnName (); @@ -277,11 +283,10 @@ namespace System.Data { if (column.Table != null) throw new ArgumentException ("Column '" + column.ColumnName + "' already belongs to this or another DataTable."); - CollectionChangeEventArgs e = new CollectionChangeEventArgs(CollectionChangeAction.Add, column); - column.SetTable (parentTable); RegisterName(column.ColumnName, column); int ordinal = base.List.Add(column); + #if NET_2_0 column.Ordinal = ordinal; #else @@ -310,9 +315,11 @@ namespace System.Data { if (column.AutoIncrement) autoIncrement.Add(column); +#if NET_2_0 column.PropertyChanged += new PropertyChangedEventHandler (ColumnPropertyChanged); +#endif - OnCollectionChanged (e); + OnCollectionChanged (new CollectionChangeEventArgs(CollectionChangeAction.Add, column)); } /// @@ -326,11 +333,6 @@ namespace System.Data { #endif DataColumn Add(string columnName) { - if (columnName == null || columnName == String.Empty) - { - columnName = GetNextDefaultColumnName(); - } - DataColumn column = new DataColumn(columnName); Add (column); return column; diff --git a/mcs/class/System.Data/Test/System.Data/ChangeLog b/mcs/class/System.Data/Test/System.Data/ChangeLog index 72fc6550799..d52d592a569 100644 --- a/mcs/class/System.Data/Test/System.Data/ChangeLog +++ b/mcs/class/System.Data/Test/System.Data/ChangeLog @@ -1,3 +1,9 @@ +2007-05-18 Chris Toshok + + * DataViewTest.cs (DefaultColumnNameAddListChangedTest): new test + for figuring out the sorts of events raised between 1.1 and 2.0 + when you add a column with the default name. + 2007-02-23 Nagappan A * DataRowTest2.cs (DataRowExpressionDefaultValueTest): Added new diff --git a/mcs/class/System.Data/Test/System.Data/DataViewTest.cs b/mcs/class/System.Data/Test/System.Data/DataViewTest.cs index ba887b620d2..c31a312b065 100644 --- a/mcs/class/System.Data/Test/System.Data/DataViewTest.cs +++ b/mcs/class/System.Data/Test/System.Data/DataViewTest.cs @@ -895,6 +895,72 @@ table changed. AssertEquals (result, eventWriter.ToString ().Replace ("\r\n", "\n")); } + [Test] + public void DefaultColumnNameAddListChangedTest () + { +#if NET_2_0 + string result = @"setting table... +---- OnListChanged PropertyDescriptorChanged,0,0 +----- UpdateIndex : True +---- OnListChanged Reset,-1,-1 +table was set. +---- OnListChanged PropertyDescriptorAdded,0,0 + default named column added. +---- OnListChanged PropertyDescriptorAdded,0,0 + non-default named column added. +---- OnListChanged PropertyDescriptorAdded,0,0 + another default named column added (Column2). +---- OnListChanged PropertyDescriptorAdded,0,0 + add a column with the same name as the default columnnames. +---- OnListChanged PropertyDescriptorAdded,0,0 + add a column with a null name. +---- OnListChanged PropertyDescriptorAdded,0,0 + add a column with an empty name. +"; +#else + string result = @"setting table... +---- OnListChanged PropertyDescriptorChanged,0,0 +----- UpdateIndex : True +---- OnListChanged Reset,-1,-1 +table was set. +---- OnListChanged PropertyDescriptorChanged,0,0 +---- OnListChanged PropertyDescriptorAdded,0,0 + default named column added. +---- OnListChanged PropertyDescriptorAdded,0,0 + non-default named column added. +---- OnListChanged PropertyDescriptorChanged,0,0 +---- OnListChanged PropertyDescriptorAdded,0,0 + another default named column added (Column2). +---- OnListChanged PropertyDescriptorAdded,0,0 + add a column with the same name as the default columnnames. +---- OnListChanged PropertyDescriptorChanged,0,0 +---- OnListChanged PropertyDescriptorAdded,0,0 + add a column with a null name. +---- OnListChanged PropertyDescriptorChanged,0,0 +---- OnListChanged PropertyDescriptorAdded,0,0 + add a column with an empty name. +"; +#endif + eventWriter = new StringWriter (); + DataTable dt = new DataTable ("table"); + ComplexEventSequence1View dv = + new ComplexEventSequence1View (dt, eventWriter); + dt.Columns.Add (); + eventWriter.WriteLine (" default named column added."); + dt.Columns.Add ("non-defaultNamedColumn"); + eventWriter.WriteLine (" non-default named column added."); + DataColumn c = dt.Columns.Add (); + eventWriter.WriteLine (" another default named column added ({0}).", c.ColumnName); + dt.Columns.Add ("Column3"); + eventWriter.WriteLine (" add a column with the same name as the default columnnames."); + dt.Columns.Add ((string)null); + eventWriter.WriteLine (" add a column with a null name."); + dt.Columns.Add (""); + eventWriter.WriteLine (" add a column with an empty name."); + + AssertEquals (result, eventWriter.ToString ().Replace ("\r\n", "\n")); + } + public class ComplexEventSequence1View : DataView { TextWriter w; -- 2.11.4.GIT