From af1f5f88d661d39c31bd5b681413c82445f35c16 Mon Sep 17 00:00:00 2001 From: Marek Safar Date: Fri, 15 May 2015 09:16:43 +0200 Subject: [PATCH] [System.Data.DataSetExtensions] Switch to reference sources --- .../System.Data.DataSetExtensions/Makefile | 13 +- .../ReferenceSources/Strings.cs | 28 ++ .../System.Data.DataSetExtensions.dll.sources | 25 +- .../System.Data/ChangeLog | 77 ------ .../System.Data/DataRowComparer.cs | 42 --- .../System.Data/DataRowComparer_1.cs | 109 -------- .../System.Data/DataRowExtensions.cs | 93 ------- .../System.Data/DataTableExtensions.cs | 106 -------- .../System.Data/EnumerableRowCollection.cs | 62 ----- .../EnumerableRowCollectionExtensions.cs | 94 ------- .../System.Data/EnumerableRowCollection_1.cs | 57 ----- .../OrderedEnumerableRowCollection.cs | 128 --------- .../System.Data/RowEnumerableDataReader.cs | 242 ------------------ .../System.Data/TypedTableBase.cs | 68 ----- .../System.Data/TypedTableBaseExtensions.cs | 81 ------ .../Test/System.Data/DataRowExtensionsTest.cs | 2 +- 16 files changed, 43 insertions(+), 1184 deletions(-) create mode 100644 mcs/class/System.Data.DataSetExtensions/ReferenceSources/Strings.cs delete mode 100644 mcs/class/System.Data.DataSetExtensions/System.Data/ChangeLog delete mode 100644 mcs/class/System.Data.DataSetExtensions/System.Data/DataRowComparer.cs delete mode 100644 mcs/class/System.Data.DataSetExtensions/System.Data/DataRowComparer_1.cs delete mode 100644 mcs/class/System.Data.DataSetExtensions/System.Data/DataRowExtensions.cs delete mode 100644 mcs/class/System.Data.DataSetExtensions/System.Data/DataTableExtensions.cs delete mode 100644 mcs/class/System.Data.DataSetExtensions/System.Data/EnumerableRowCollection.cs delete mode 100644 mcs/class/System.Data.DataSetExtensions/System.Data/EnumerableRowCollectionExtensions.cs delete mode 100644 mcs/class/System.Data.DataSetExtensions/System.Data/EnumerableRowCollection_1.cs delete mode 100644 mcs/class/System.Data.DataSetExtensions/System.Data/OrderedEnumerableRowCollection.cs delete mode 100644 mcs/class/System.Data.DataSetExtensions/System.Data/RowEnumerableDataReader.cs delete mode 100644 mcs/class/System.Data.DataSetExtensions/System.Data/TypedTableBase.cs delete mode 100644 mcs/class/System.Data.DataSetExtensions/System.Data/TypedTableBaseExtensions.cs diff --git a/mcs/class/System.Data.DataSetExtensions/Makefile b/mcs/class/System.Data.DataSetExtensions/Makefile index 48c293f8650..c19c4b9e997 100644 --- a/mcs/class/System.Data.DataSetExtensions/Makefile +++ b/mcs/class/System.Data.DataSetExtensions/Makefile @@ -4,18 +4,9 @@ include ../../build/rules.make LIBRARY = System.Data.DataSetExtensions.dll -LIB_REFS = System.Core System System.Data System.Xml System.Web -LIB_MCS_FLAGS = \ - -r:$(corlib) \ - -r:System.Data.dll \ - -r:System.Xml.dll \ - -r:System.Web.dll \ - $(OTHER_LIB_MCS_FLAGS) +RESOURCE_STRINGS = ../../../external/referencesource/System.Data.DataSetExtensions/System.Data.DataSetExtensions.txt -ifeq (2.0, $(FRAMEWORK_VERSION)) -# This is a .NET 3.5 only assembly, but built during the 2.0 build -LIB_MCS_FLAGS += -d:NET_3_5 -nowarn:1720 -endif +LIB_REFS = System.Core System System.Data System.Xml TEST_MCS_FLAGS = $(LIB_MCS_FLAGS) -doc:$(test_lib:.dll=.xml) -nowarn:219 -nowarn:169 $(NUNIT_RESOURCE_FILES:%=/resource:%) diff --git a/mcs/class/System.Data.DataSetExtensions/ReferenceSources/Strings.cs b/mcs/class/System.Data.DataSetExtensions/ReferenceSources/Strings.cs new file mode 100644 index 00000000000..6a779e764b0 --- /dev/null +++ b/mcs/class/System.Data.DataSetExtensions/ReferenceSources/Strings.cs @@ -0,0 +1,28 @@ +namespace System.Data.DataSetExtensions +{ + static class Strings + { + public const string DataSetLinq_CannotCompareDeletedRow = "DataSetLinq_CannotCompareDeletedRow"; + public const string DataSetLinq_CannotLoadDeletedRow = "DataSetLinq_CannotLoadDeletedRow"; + public const string DataSetLinq_CannotLoadDetachedRow = "DataSetLinq_CannotLoadDetachedRow"; + public const string DataSetLinq_EmptyDataRowSource = "DataSetLinq_EmptyDataRowSource"; + public const string DataSetLinq_NullDataRow = "DataSetLinq_NullDataRow"; + public const string LDVRowStateError = "LDVRowStateError"; + public const string ToLDVUnsupported = "ToLDVUnsupported"; + + public static string DataSetLinq_InvalidEnumerationValue (params object[] args) + { + return SR.GetString ("DataSetLinq_InvalidEnumerationValue", args); + } + + public static string DataSetLinq_NonNullableCast (object arg) + { + return SR.GetString ("DataSetLinq_NonNullableCast", arg); + } + + public static string LDV_InvalidNumOfKeys (params object[] args) + { + return SR.GetString ("LDV_InvalidNumOfKeys", args); + } + } +} \ No newline at end of file diff --git a/mcs/class/System.Data.DataSetExtensions/System.Data.DataSetExtensions.dll.sources b/mcs/class/System.Data.DataSetExtensions/System.Data.DataSetExtensions.dll.sources index 45c800af638..5f5c4c521d1 100644 --- a/mcs/class/System.Data.DataSetExtensions/System.Data.DataSetExtensions.dll.sources +++ b/mcs/class/System.Data.DataSetExtensions/System.Data.DataSetExtensions.dll.sources @@ -1,15 +1,14 @@ ../../build/common/Consts.cs -../../build/common/Locale.cs -../../build/common/MonoTODOAttribute.cs Assembly/AssemblyInfo.cs -System.Data/DataRowComparer.cs -System.Data/DataRowComparer_1.cs -System.Data/DataRowExtensions.cs -System.Data/DataTableExtensions.cs -System.Data/EnumerableRowCollection.cs -System.Data/EnumerableRowCollectionExtensions.cs -System.Data/EnumerableRowCollection_1.cs -System.Data/OrderedEnumerableRowCollection.cs -System.Data/RowEnumerableDataReader.cs -System.Data/TypedTableBase.cs -System.Data/TypedTableBaseExtensions.cs +../../../external/referencesource/System.Data.DataSetExtensions/System/Data/DataRowComparer.cs +../../../external/referencesource/System.Data.DataSetExtensions/System/Data/DataRowExtensions.cs +../../../external/referencesource/System.Data.DataSetExtensions/System/Data/DataSetUtil.cs +../../../external/referencesource/System.Data.DataSetExtensions/System/Data/DataTableExtensions.cs +../../../external/referencesource/System.Data.DataSetExtensions/System/Data/EnumerableRowCollection.cs +../../../external/referencesource/System.Data.DataSetExtensions/System/Data/EnumerableRowCollectionExtensions.cs +../../../external/referencesource/System.Data.DataSetExtensions/System/Data/LinqDataView.cs +../../../external/referencesource/System.Data.DataSetExtensions/System/Data/OrderedEnumerableRowCollection.cs +../../../external/referencesource/System.Data.DataSetExtensions/System/Data/SortExpressionBuilder.cs +../../../external/referencesource/System.Data.DataSetExtensions/System/Data/TypedTableBase.cs +../../../external/referencesource/System.Data.DataSetExtensions/System/Data/TypedTableBaseExtensions.cs +ReferenceSources/Strings.cs \ No newline at end of file diff --git a/mcs/class/System.Data.DataSetExtensions/System.Data/ChangeLog b/mcs/class/System.Data.DataSetExtensions/System.Data/ChangeLog deleted file mode 100644 index b6c487f060b..00000000000 --- a/mcs/class/System.Data.DataSetExtensions/System.Data/ChangeLog +++ /dev/null @@ -1,77 +0,0 @@ -2010-03-26 Miguel de Icaza - - * RowEnumerableDataReader.cs: Applied patch from Tony Fish fixing - bug #591397 - -2008-12-02 Marek Habersack - - * DataRowExtensions.cs: when Field is specialized on a - nullable type (either a reference or an instance of Nullable ) - do not throw exception for column value being DBNull but return - null instead. - -2008-08-15 Gert Driesen - - * DataRowComparer_1.cs: Modified Equals to return true if all column - values are equal. Modified ColumnsEqual to use Object.Equals for - reference types. Fixes bug #417398. - -2008-05-14 Atsushi Enomoto - - * DataTableExtensions.cs : - implemented AsDataView() and CopyToDataTable(). - * EnumerableRowCollection.cs : added Table property for internal use. - -2008-05-14 Atsushi Enomoto - - * TypedTableBase.cs : serialization .ctor() does nothing here (it - might do something in derived types. no need to throw NIE here). - -2008-05-14 Atsushi Enomoto - - * EnumerableRowCollectionExtensions.cs, - OrderedEnumerableRowCollection.cs : implemented ThenBy(). - It required some generic refactoring. - -2008-05-13 Jb Evain - - * EnumerableRowCollection.cs: delete methods - Select/Where/Cast that duplicate Linq to Objects - methods. - * EnumerableRowCollectionExtensions.cs - TypedTableBase.cs, TypedTableBaseExtensions.cs: directly - fallback to Linq to Objects. - -2008-05-13 Atsushi Enomoto - - * DataTableExtensions.cs, EnumerableRowCollection.cs, - EnumerableRowCollectionExtensions.cs, EnumerableRowCollection_1.cs, - OrderedEnumerableRowCollection.cs, TypedTableBase.cs, - TypedTableBaseExtensions.cs : lots of significant refactoring to - make collection/enumerable things unified. - Implemented OrderBy() and OrderByDescending(). - -2008-05-13 Marek Habersack - - * DataRowComparer_1.cs: implemented GetHashCode and Equals. - -2008-05-13 Atsushi Enomoto - - * DataTableExtensions.cs : implemented AsEnumerable(). - * DataRowExtensions.cs : implemented. - * EnumerableRowCollection_1.cs : implemented. - * EnumerableRowCollectionExtensions.cs : - implemented Select() and Where(). - * OrderedEnumerableRowCollection.cs : base is not parameterless now. - * TypedTableBaseExtensions.cs: - some overloads can just delegate to others. - * DataRowComparer_1.cs : (added some non-working code.) - -2008-05-13 Atsushi Enomoto - - * DataRowComparer.cs, DataRowComparer_1.cs, DataRowExtensions.cs, - DataTableExtensions.cs, EnumerableRowCollection.cs, - EnumerableRowCollectionExtensions.cs, EnumerableRowCollection_1.cs, - OrderedEnumerableRowCollection.cs, TypedTableBase.cs, - TypedTableBaseExtensions.cs : stubbed all. - diff --git a/mcs/class/System.Data.DataSetExtensions/System.Data/DataRowComparer.cs b/mcs/class/System.Data.DataSetExtensions/System.Data/DataRowComparer.cs deleted file mode 100644 index 006e180ac1f..00000000000 --- a/mcs/class/System.Data.DataSetExtensions/System.Data/DataRowComparer.cs +++ /dev/null @@ -1,42 +0,0 @@ -// -// DataRowComparer.cs -// -// Author: -// Atsushi Enomoto -// -// Copyright (C) 2008 Novell, Inc. http://www.novell.com -// - -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; - -namespace System.Data -{ - public static class DataRowComparer - { - static readonly DataRowComparer default_instance = DataRowComparer.Default; - public static DataRowComparer Default { - get { return default_instance; } - } - } -} diff --git a/mcs/class/System.Data.DataSetExtensions/System.Data/DataRowComparer_1.cs b/mcs/class/System.Data.DataSetExtensions/System.Data/DataRowComparer_1.cs deleted file mode 100644 index 2529e518f9a..00000000000 --- a/mcs/class/System.Data.DataSetExtensions/System.Data/DataRowComparer_1.cs +++ /dev/null @@ -1,109 +0,0 @@ -// -// DataRowComparer_1.cs -// -// Author: -// Atsushi Enomoto -// -// Copyright (C) 2008 Novell, Inc. http://www.novell.com -// - -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; -using System.Collections.Generic; - -namespace System.Data -{ - public sealed class DataRowComparer : IEqualityComparer where TRow : DataRow - { - static readonly DataRowComparer default_instance = new DataRowComparer (); - - public static DataRowComparer Default { - get { return default_instance; } - } - - private DataRowComparer () - { - } - - // LAMESPEC: neither of the parameters throws ArgumentNullException if it's null - public bool Equals (TRow leftRow, TRow rightRow) - { - if (object.ReferenceEquals (leftRow, rightRow)) - return true; - - if (leftRow == null || rightRow == null) - return false; - - int columnCount = leftRow.Table.Columns.Count; - if (columnCount != rightRow.Table.Columns.Count) - return false; - - for (int i = 0; i < columnCount; i++) - if (!ColumnsEqual (leftRow [i], rightRow [i])) - return false; - return true; - } - - bool ColumnsEqual (object leftCol, object rightCol) - { - if (object.ReferenceEquals (leftCol, rightCol)) - return true; - - if (leftCol == null || rightCol == null) - return false; - - var vt = leftCol as System.ValueType; - if (vt != null && vt.Equals (rightCol)) - return true; - - return leftCol.Equals (rightCol); - } - - public int GetHashCode (TRow row) - { - if (row == null) - throw new ArgumentNullException ("row"); - - DataTable table = row.Table; - if (table == null) - throw new ArgumentException ("The source DataRow objects does not belong to a DataTable."); - - DataColumnCollection columns = table.Columns; - int columnCount = columns.Count; - if (columnCount == 0) - return 0; - - int ret = 0; - object o; - for (int i = 0; i < columnCount; i++) { - o = row [i]; - if (o == null) - continue; - - ret ^= o.GetHashCode (); - } - - return ret; - } - } -} diff --git a/mcs/class/System.Data.DataSetExtensions/System.Data/DataRowExtensions.cs b/mcs/class/System.Data.DataSetExtensions/System.Data/DataRowExtensions.cs deleted file mode 100644 index 29ad935f21c..00000000000 --- a/mcs/class/System.Data.DataSetExtensions/System.Data/DataRowExtensions.cs +++ /dev/null @@ -1,93 +0,0 @@ -// -// DataRowExtensions.cs -// -// Author: -// Atsushi Enomoto -// -// Copyright (C) 2008 Novell, Inc. http://www.novell.com -// - -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; -using System.Runtime.CompilerServices; - -namespace System.Data -{ - public static class DataRowExtensions - { - public static T Field (this DataRow row, int columnIndex) - { - return Field (row, columnIndex, DataRowVersion.Current); - } - - public static T Field (this DataRow row, int columnIndex, DataRowVersion version) - { - object ret = row [columnIndex, version]; - if (ret == DBNull.Value) { - Type type = typeof (T); - Type genericTypeDef = type.IsGenericType ? type.GetGenericTypeDefinition () : null; - if (!type.IsValueType || genericTypeDef != null && genericTypeDef == typeof (Nullable <>)) - return default (T); - - throw new StrongTypingException ("Cannot get strong typed value since it is DB null. Please use a nullable type.", null); - } - - return (T) ret; - } - - public static T Field (this DataRow row, string columnName) - { - return Field (row, columnName, DataRowVersion.Current); - } - - public static T Field (this DataRow row, string columnName, DataRowVersion version) - { - return Field (row, row.Table.Columns [columnName], version); - } - - public static T Field (this DataRow row, DataColumn column) - { - return Field (row, column, DataRowVersion.Current); - } - - public static T Field (this DataRow row, DataColumn column, DataRowVersion version) - { - return Field (row, row.Table.Columns.IndexOf (column), version); - } - - public static void SetField (this DataRow row, int columnIndex, T value) - { - row [columnIndex] = value; - } - - public static void SetField (this DataRow row, string columnName, T value) - { - row [columnName] = value; - } - - public static void SetField (this DataRow row, DataColumn column, T value) - { - row [column] = value; - } - } -} diff --git a/mcs/class/System.Data.DataSetExtensions/System.Data/DataTableExtensions.cs b/mcs/class/System.Data.DataSetExtensions/System.Data/DataTableExtensions.cs deleted file mode 100644 index 47682be96a5..00000000000 --- a/mcs/class/System.Data.DataSetExtensions/System.Data/DataTableExtensions.cs +++ /dev/null @@ -1,106 +0,0 @@ -// -// DataTableExtensions.cs -// -// Author: -// Atsushi Enomoto -// -// Copyright (C) 2008 Novell, Inc. http://www.novell.com -// - -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; -using System.Collections; -using System.Collections.Generic; -using System.Linq; - - -namespace System.Data -{ - - public static class DataTableExtensions - { - public static DataView AsDataView (this DataTable table) - { - return AsDataView (table.AsEnumerable ()); - } - - [MonoTODO ("We should implement an effective DataView derivation; looks like .NET does.")] - public static DataView AsDataView (this EnumerableRowCollection source) - where T : DataRow - { - return CopyToDataTable (source).DefaultView; - } - - public static EnumerableRowCollection AsEnumerable (this DataTable source) - { - return new EnumerableRowCollection (new DataRowEnumerable (source)); - } - - public static DataTable CopyToDataTable (this IEnumerable source) - where T : DataRow - { - DataTable dt = new DataTable (); - IEnumerator e = source.GetEnumerator (); - if (!e.MoveNext ()) - throw new InvalidOperationException ("The source contains no DataRows"); - foreach (DataColumn col in e.Current.Table.Columns) - dt.Columns.Add (new DataColumn (col.ColumnName, col.DataType, col.Expression, col.ColumnMapping)); - CopyToDataTable (source, dt, LoadOption.PreserveChanges); - return dt; - } - - public static void CopyToDataTable (this IEnumerable source, DataTable table, LoadOption options) - where T : DataRow - { - CopyToDataTable (source, table, options, null); - } - - public static void CopyToDataTable (this IEnumerable source, DataTable table, LoadOption options, FillErrorEventHandler errorHandler) - where T : DataRow - { - var reader = new RowEnumerableDataReader (source, 0); - table.Load (reader, options, errorHandler); - } - } - - class DataRowEnumerable : IEnumerable - { - DataTable source; - - public DataRowEnumerable (DataTable source) - { - this.source = source; - } - - public IEnumerator GetEnumerator () - { - foreach (TRow row in source.Rows) - yield return row; - } - - IEnumerator IEnumerable.GetEnumerator () - { - return GetEnumerator (); - } - } -} diff --git a/mcs/class/System.Data.DataSetExtensions/System.Data/EnumerableRowCollection.cs b/mcs/class/System.Data.DataSetExtensions/System.Data/EnumerableRowCollection.cs deleted file mode 100644 index f95142c3513..00000000000 --- a/mcs/class/System.Data.DataSetExtensions/System.Data/EnumerableRowCollection.cs +++ /dev/null @@ -1,62 +0,0 @@ -// -// EnumerableRowCollection.cs -// -// Author: -// Atsushi Enomoto -// -// Copyright (C) 2008 Novell, Inc. http://www.novell.com -// - -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; -using System.Collections; -using System.Collections.Generic; - -namespace System.Data -{ - public abstract class EnumerableRowCollection : IEnumerable - { - DataTable table; - - internal EnumerableRowCollection () - { - } - - internal DataTable Table { - get { - if (table == null) - foreach (DataRow r in this) { - table = r.Table; - break; - } - return table; - } - } - - IEnumerator IEnumerable.GetEnumerator () - { - // it is the documented behavior. - return null; - } - } -} diff --git a/mcs/class/System.Data.DataSetExtensions/System.Data/EnumerableRowCollectionExtensions.cs b/mcs/class/System.Data.DataSetExtensions/System.Data/EnumerableRowCollectionExtensions.cs deleted file mode 100644 index e1b2fed3ea7..00000000000 --- a/mcs/class/System.Data.DataSetExtensions/System.Data/EnumerableRowCollectionExtensions.cs +++ /dev/null @@ -1,94 +0,0 @@ -// -// EnumerableRowCollectionExtensions.cs -// -// Author: -// Atsushi Enomoto -// -// Copyright (C) 2008 Novell, Inc. http://www.novell.com -// - -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; -using System.Collections.Generic; -using System.Linq; - -namespace System.Data -{ - public static class EnumerableRowCollectionExtensions - { - public static EnumerableRowCollection Cast (this EnumerableRowCollection source) - { - return new EnumerableRowCollection (Enumerable.Cast (source)); - } - - public static OrderedEnumerableRowCollection OrderBy (this EnumerableRowCollection source, Func keySelector) - { - return OrderBy (source, keySelector, Comparer.Default); - } - - public static OrderedEnumerableRowCollection OrderBy (this EnumerableRowCollection source, Func keySelector, IComparer comparer) - { - return OrderedEnumerableRowCollection.Create (source, keySelector, comparer, false); - } - - public static OrderedEnumerableRowCollection OrderByDescending (this EnumerableRowCollection source, Func keySelector) - { - return OrderByDescending (source, keySelector, Comparer.Default); - } - - public static OrderedEnumerableRowCollection OrderByDescending (this EnumerableRowCollection source, Func keySelector, IComparer comparer) - { - return OrderedEnumerableRowCollection.Create (source, keySelector, comparer, true); - } - - public static EnumerableRowCollection Select (this EnumerableRowCollection source, Func selector) - { - return new EnumerableRowCollection (Enumerable.Select (source, selector)); - } - - public static OrderedEnumerableRowCollection ThenBy (this OrderedEnumerableRowCollection source, Func keySelector) - { - return ThenBy (source, keySelector, Comparer.Default); - } - - public static OrderedEnumerableRowCollection ThenBy (this OrderedEnumerableRowCollection source, Func keySelector, IComparer comparer) - { - return OrderedEnumerableRowCollection.AddSort (source, keySelector, comparer, false); - } - - public static OrderedEnumerableRowCollection ThenByDescending (this OrderedEnumerableRowCollection source, Func keySelector) - { - return ThenByDescending (source, keySelector, Comparer.Default); - } - - public static OrderedEnumerableRowCollection ThenByDescending (this OrderedEnumerableRowCollection source, Func keySelector, IComparer comparer) - { - return OrderedEnumerableRowCollection.AddSort (source, keySelector, comparer, true); - } - - public static EnumerableRowCollection Where (this EnumerableRowCollection source, Func predicate) - { - return new EnumerableRowCollection (Enumerable.Where (source, predicate)); - } - } -} diff --git a/mcs/class/System.Data.DataSetExtensions/System.Data/EnumerableRowCollection_1.cs b/mcs/class/System.Data.DataSetExtensions/System.Data/EnumerableRowCollection_1.cs deleted file mode 100644 index bc2ddcc171f..00000000000 --- a/mcs/class/System.Data.DataSetExtensions/System.Data/EnumerableRowCollection_1.cs +++ /dev/null @@ -1,57 +0,0 @@ -// -// EnumerableRowCollection_1.cs -// -// Author: -// Atsushi Enomoto -// -// Copyright (C) 2008 Novell, Inc. http://www.novell.com -// - -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; -using System.Collections; -using System.Collections.Generic; - -namespace System.Data -{ - public class EnumerableRowCollection : EnumerableRowCollection, IEnumerable - { - IEnumerable source; - - internal EnumerableRowCollection (IEnumerable source) - { - this.source = source; - } - - public IEnumerator GetEnumerator () - { - foreach (TRow row in source) - yield return row; - } - - IEnumerator IEnumerable.GetEnumerator () - { - return GetEnumerator (); - } - } -} diff --git a/mcs/class/System.Data.DataSetExtensions/System.Data/OrderedEnumerableRowCollection.cs b/mcs/class/System.Data.DataSetExtensions/System.Data/OrderedEnumerableRowCollection.cs deleted file mode 100644 index e10170f72cb..00000000000 --- a/mcs/class/System.Data.DataSetExtensions/System.Data/OrderedEnumerableRowCollection.cs +++ /dev/null @@ -1,128 +0,0 @@ -// -// OrderedEnumerableRowCollection.cs -// -// Author: -// Atsushi Enomoto -// -// Copyright (C) 2008 Novell, Inc. http://www.novell.com -// - -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; -using System.Collections; -using System.Collections.Generic; - -namespace System.Data -{ - public sealed class OrderedEnumerableRowCollection - : EnumerableRowCollection - { - internal static OrderedEnumerableRowCollection Create (IEnumerable source, Func keySelector, IComparer comparer, bool descending) - { - var sorter = new SortComparer (); - sorter.AddSort (keySelector, comparer, descending); - return new OrderedEnumerableRowCollection (new SortedEnumerable (source, sorter)); - } - - internal static OrderedEnumerableRowCollection AddSort (OrderedEnumerableRowCollection source, Func keySelector, IComparer comparer, bool descending) - { - source.source.Sorter.AddSort (keySelector, comparer, descending); - return source; - } - - OrderedEnumerableRowCollection (SortedEnumerable source) - : base (source) - { - this.source = source; - } - - SortedEnumerable source; - } - - class SortComparer : IComparer - { - public SortComparer () - { - } - - List> comparers = new List> (); - - public void AddSort (Comparison comparer) - { - comparers.Add (comparer); - } - - public void AddSort (Func keySelector, IComparer comparer, bool descending) - { - if (keySelector == null) - throw new ArgumentNullException ("keySelector"); - if (comparer == null) - comparer = Comparer.Default; - comparers.Add (delegate (TRow r1, TRow r2) { - int ret = comparer.Compare (keySelector (r1), keySelector (r2)); - return descending ? -ret : ret; - }); - } - - public int Compare (TRow r1, TRow r2) - { - foreach (var c in comparers) { - int ret = c (r1, r2); - if (ret != 0) - return ret; - } - return 0; - } - } - - class SortedEnumerable : IEnumerable - { - IEnumerable source; - SortComparer sorter; - - public SortedEnumerable (IEnumerable source, SortComparer sorter) - { - this.source = source; - this.sorter = sorter; - } - - public SortComparer Sorter { - get { return sorter; } - } - - public IEnumerator GetEnumerator () - { - var list = new List (); - foreach (TRow row in source) - list.Add (row); - list.Sort (sorter); - for (int i = 0, c = list.Count; i < c; i++) - yield return list [i]; - } - - IEnumerator IEnumerable.GetEnumerator () - { - return GetEnumerator (); - } - } -} diff --git a/mcs/class/System.Data.DataSetExtensions/System.Data/RowEnumerableDataReader.cs b/mcs/class/System.Data.DataSetExtensions/System.Data/RowEnumerableDataReader.cs deleted file mode 100644 index f9a8564d122..00000000000 --- a/mcs/class/System.Data.DataSetExtensions/System.Data/RowEnumerableDataReader.cs +++ /dev/null @@ -1,242 +0,0 @@ -// -// RowEnumerableDataReader.cs -// -// Author: -// Atsushi Enomoto -// -// Copyright (C) 2008 Novell, Inc. http://www.novell.com -// - -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; -using System.Collections; -using System.Collections.Generic; -using System.Linq; - -namespace System.Data -{ - internal class RowEnumerableDataReader : IDataReader - { - EnumerableRowCollection source; - IEnumerator e; - int depth; - bool done; - - public RowEnumerableDataReader (IEnumerable source, int depth) - { - this.source = source as EnumerableRowCollection; - if (this.source == null) - this.source = new EnumerableRowCollection ((IEnumerable) source); - this.depth = depth; - } - - public DataRow Current { - get { return e != null ? (DataRow) e.Current : null; } - } - - public int Depth { - get { return depth; } - } - - public bool IsClosed { - get { return done; } - } - - public int RecordsAffected { - get { return -1; } - } - - public void Close () - { - done = true; - } - - public DataTable GetSchemaTable () - { - return new DataTableReader (source.Table).GetSchemaTable (); - } - - public bool NextResult () - { - return e.MoveNext (); - } - - public bool Read () - { - if (e == null) - e = ((IEnumerable) source).GetEnumerator (); - return NextResult (); - } - - // IDisposable - public void Dispose () - { - Close (); - } - - // IDataRecord - - DataTable GetTable () - { - DataRow r = Current; - if (r == null) - foreach (DataRow rr in source) { - r = rr; - break; - } - return r.Table; - } - - public int FieldCount { - get { return GetTable ().Columns.Count; } - } - - public object this [int i] { - get { return Current [i]; } - } - - public object this [string name] { - get { return Current [name]; } - } - - public string GetDataTypeName (int i) - { - return GetFieldType (i).Name; - } - - public Type GetFieldType (int i) - { - return GetTable ().Columns [i].DataType; - } - - public string GetName (int i) - { - return GetTable ().Columns [i].ColumnName; - } - - public int GetOrdinal (string name) - { - return GetTable ().Columns [name].Ordinal; - } - - public long GetBytes (int i, long fieldOffset, byte [] buffer, int bufferoffset, int length) - { - // FIXME: do we need it? - throw new NotSupportedException (); - } - - public long GetChars (int i, long fieldOffset, char [] buffer, int bufferoffset, int length) - { - // FIXME: do we need it? - throw new NotSupportedException (); - } - - public IDataReader GetData (int i) - { - // FIXME: do we need it? - throw new NotSupportedException (); - } - - public int GetValues (object [] values) - { - int fieldCount = FieldCount; - int i; - - //target object is byval so we can not just assign new object[] to values , calling side will not change - //hence copy each item into values - for (i = 0; i < values.Length && i < fieldCount; ++i) - values[i] = Current[i]; - return i - 1; - } - - public bool IsDBNull (int i) - { - return Current.IsNull (i); - } - - public bool GetBoolean (int i) - { - return (bool) Current [i]; - } - - public byte GetByte (int i) - { - return (byte) Current [i]; - } - - public char GetChar (int i) - { - return (char) Current [i]; - } - - public DateTime GetDateTime (int i) - { - return (DateTime) Current [i]; - } - - public decimal GetDecimal (int i) - { - return (decimal) Current [i]; - } - - public double GetDouble (int i) - { - return (double) Current [i]; - } - - public float GetFloat (int i) - { - return (float) Current [i]; - } - - public Guid GetGuid (int i) - { - return (Guid) Current [i]; - } - - public short GetInt16 (int i) - { - return (short) Current [i]; - } - - public int GetInt32 (int i) - { - return (int) Current [i]; - } - - public long GetInt64 (int i) - { - return (long) Current [i]; - } - - public string GetString (int i) - { - return (string) Current [i]; - } - - public object GetValue (int i) - { - return Current [i]; - } - } -} diff --git a/mcs/class/System.Data.DataSetExtensions/System.Data/TypedTableBase.cs b/mcs/class/System.Data.DataSetExtensions/System.Data/TypedTableBase.cs deleted file mode 100644 index 6058be908e8..00000000000 --- a/mcs/class/System.Data.DataSetExtensions/System.Data/TypedTableBase.cs +++ /dev/null @@ -1,68 +0,0 @@ -// -// TypedTableBase.cs -// -// Author: -// Atsushi Enomoto -// -// Copyright (C) 2008 Novell, Inc. http://www.novell.com -// - -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; -using System.Collections; -using System.Collections.Generic; -using System.Linq; -using System.Runtime.Serialization; - -namespace System.Data -{ - [Serializable] - public abstract class TypedTableBase : DataTable, IEnumerable, IEnumerable - where T : DataRow - { - protected TypedTableBase () - { - } - - protected TypedTableBase (SerializationInfo info, StreamingContext context) - : base (info, context) - { - } - - public EnumerableRowCollection Cast () - { - return new EnumerableRowCollection (Enumerable.Cast (this)); - } - - public IEnumerator GetEnumerator () - { - foreach (object o in Rows) - yield return (T) o; - } - - IEnumerator IEnumerable.GetEnumerator () - { - return GetEnumerator (); - } - } -} diff --git a/mcs/class/System.Data.DataSetExtensions/System.Data/TypedTableBaseExtensions.cs b/mcs/class/System.Data.DataSetExtensions/System.Data/TypedTableBaseExtensions.cs deleted file mode 100644 index 3d476d3aabb..00000000000 --- a/mcs/class/System.Data.DataSetExtensions/System.Data/TypedTableBaseExtensions.cs +++ /dev/null @@ -1,81 +0,0 @@ -// -// TypedTableBaseExtensions.cs -// -// Author: -// Atsushi Enomoto -// -// Copyright (C) 2008 Novell, Inc. http://www.novell.com -// - -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; -using System.Collections.Generic; -using System.Linq; - -namespace System.Data -{ - public static class TypedTableBaseExtensions - { - - public static EnumerableRowCollection AsEnumerable (this TypedTableBase source) where TRow : DataRow - { - return new EnumerableRowCollection (source); - } - - public static OrderedEnumerableRowCollection OrderBy (this TypedTableBase source, Func keySelector) - where TRow : DataRow - { - return OrderBy (source, keySelector, Comparer.Default); - } - - public static OrderedEnumerableRowCollection OrderBy (this TypedTableBase source, Func keySelector, IComparer comparer) - where TRow : DataRow - { - return OrderedEnumerableRowCollection.Create (source, keySelector, comparer, false); - } - - public static OrderedEnumerableRowCollection OrderByDescending (this TypedTableBase source, Func keySelector) - where TRow : DataRow - { - return OrderByDescending (source, keySelector, Comparer.Default); - } - - public static OrderedEnumerableRowCollection OrderByDescending (this TypedTableBase source, Func keySelector, IComparer comparer) - where TRow : DataRow - { - return OrderedEnumerableRowCollection.Create (source, keySelector, comparer, true); - } - - public static EnumerableRowCollection Select (this TypedTableBase source, Func selector) - where TRow : DataRow - { - return new EnumerableRowCollection (Enumerable.Select (source, selector)); - } - - public static EnumerableRowCollection Where (this TypedTableBase source, Func predicate) - where TRow : DataRow - { - return new EnumerableRowCollection (Enumerable.Where (source, predicate)); - } - } -} diff --git a/mcs/class/System.Data.DataSetExtensions/Test/System.Data/DataRowExtensionsTest.cs b/mcs/class/System.Data.DataSetExtensions/Test/System.Data/DataRowExtensionsTest.cs index 29fe61f4f35..f7cc0e35a73 100644 --- a/mcs/class/System.Data.DataSetExtensions/Test/System.Data/DataRowExtensionsTest.cs +++ b/mcs/class/System.Data.DataSetExtensions/Test/System.Data/DataRowExtensionsTest.cs @@ -69,7 +69,7 @@ namespace MonoTests.System.Data } [Test] - [ExpectedException (typeof (StrongTypingException))] + [ExpectedException (typeof (InvalidCastException))] public void Field_T_DBNullFieldValue_ValueType () { DataRow row = SetupRow (); -- 2.25.1