Imported Upstream version 4.2.0.179

Former-commit-id: 4610231f55806d2a05ed69e5ff3faa7336cc1479
This commit is contained in:
Xamarin Public Jenkins
2015-08-26 07:17:56 -04:00
committed by Jo Shields
parent aa7da660d6
commit c042cd0c52
7507 changed files with 90259 additions and 657307 deletions

View File

@@ -4,19 +4,9 @@ include ../../build/rules.make
LIBRARY = System.Data.DataSetExtensions.dll
LIB_MCS_FLAGS = \
-r:$(corlib) \
-r:System.Core.dll \
-r:System.dll \
-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:%)

View File

@@ -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);
}
}
}

View File

@@ -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

View File

@@ -1,77 +0,0 @@
2010-03-26 Miguel de Icaza <miguel@novell.com>
* RowEnumerableDataReader.cs: Applied patch from Tony Fish fixing
bug #591397
2008-12-02 Marek Habersack <mhabersack@novell.com>
* DataRowExtensions.cs: when Field <T> is specialized on a
nullable type (either a reference or an instance of Nullable <T>)
do not throw exception for column value being DBNull but return
null instead.
2008-08-15 Gert Driesen <drieseng@users.sourceforge.net>
* 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 <atsushi@ximian.com>
* DataTableExtensions.cs :
implemented AsDataView() and CopyToDataTable().
* EnumerableRowCollection.cs : added Table property for internal use.
2008-05-14 Atsushi Enomoto <atsushi@ximian.com>
* 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 <atsushi@ximian.com>
* EnumerableRowCollectionExtensions.cs,
OrderedEnumerableRowCollection.cs : implemented ThenBy().
It required some generic refactoring.
2008-05-13 Jb Evain <jbevain@novell.com>
* 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 <atsushi@ximian.com>
* 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 <mhabersack@novell.com>
* DataRowComparer_1.cs: implemented GetHashCode and Equals.
2008-05-13 Atsushi Enomoto <atsushi@ximian.com>
* 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 <atsushi@ximian.com>
* DataRowComparer.cs, DataRowComparer_1.cs, DataRowExtensions.cs,
DataTableExtensions.cs, EnumerableRowCollection.cs,
EnumerableRowCollectionExtensions.cs, EnumerableRowCollection_1.cs,
OrderedEnumerableRowCollection.cs, TypedTableBase.cs,
TypedTableBaseExtensions.cs : stubbed all.

View File

@@ -1,42 +0,0 @@
//
// DataRowComparer.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// 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<DataRow> default_instance = DataRowComparer<DataRow>.Default;
public static DataRowComparer<DataRow> Default {
get { return default_instance; }
}
}
}

View File

@@ -1,109 +0,0 @@
//
// DataRowComparer_1.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// 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<TRow> : IEqualityComparer<TRow> where TRow : DataRow
{
static readonly DataRowComparer<TRow> default_instance = new DataRowComparer<TRow> ();
public static DataRowComparer<TRow> 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;
ValueType vt = leftCol as 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;
}
}
}

View File

@@ -1,93 +0,0 @@
//
// DataRowExtensions.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// 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<T> (this DataRow row, int columnIndex)
{
return Field<T> (row, columnIndex, DataRowVersion.Current);
}
public static T Field<T> (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<T> (this DataRow row, string columnName)
{
return Field<T> (row, columnName, DataRowVersion.Current);
}
public static T Field<T> (this DataRow row, string columnName, DataRowVersion version)
{
return Field<T> (row, row.Table.Columns [columnName], version);
}
public static T Field<T> (this DataRow row, DataColumn column)
{
return Field<T> (row, column, DataRowVersion.Current);
}
public static T Field<T> (this DataRow row, DataColumn column, DataRowVersion version)
{
return Field<T> (row, row.Table.Columns.IndexOf (column), version);
}
public static void SetField<T> (this DataRow row, int columnIndex, T value)
{
row [columnIndex] = value;
}
public static void SetField<T> (this DataRow row, string columnName, T value)
{
row [columnName] = value;
}
public static void SetField<T> (this DataRow row, DataColumn column, T value)
{
row [column] = value;
}
}
}

View File

@@ -1,106 +0,0 @@
//
// DataTableExtensions.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// 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<DataRow> (table.AsEnumerable ());
}
[MonoTODO ("We should implement an effective DataView derivation; looks like .NET does.")]
public static DataView AsDataView<T> (this EnumerableRowCollection<T> source)
where T : DataRow
{
return CopyToDataTable<T> (source).DefaultView;
}
public static EnumerableRowCollection<DataRow> AsEnumerable (this DataTable source)
{
return new EnumerableRowCollection<DataRow> (new DataRowEnumerable<DataRow> (source));
}
public static DataTable CopyToDataTable<T> (this IEnumerable<T> source)
where T : DataRow
{
DataTable dt = new DataTable ();
IEnumerator<T> 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<T> (source, dt, LoadOption.PreserveChanges);
return dt;
}
public static void CopyToDataTable<T> (this IEnumerable<T> source, DataTable table, LoadOption options)
where T : DataRow
{
CopyToDataTable<T> (source, table, options, null);
}
public static void CopyToDataTable<T> (this IEnumerable<T> source, DataTable table, LoadOption options, FillErrorEventHandler errorHandler)
where T : DataRow
{
var reader = new RowEnumerableDataReader (source, 0);
table.Load (reader, options, errorHandler);
}
}
class DataRowEnumerable<TRow> : IEnumerable<TRow>
{
DataTable source;
public DataRowEnumerable (DataTable source)
{
this.source = source;
}
public IEnumerator<TRow> GetEnumerator ()
{
foreach (TRow row in source.Rows)
yield return row;
}
IEnumerator IEnumerable.GetEnumerator ()
{
return GetEnumerator ();
}
}
}

View File

@@ -1,62 +0,0 @@
//
// EnumerableRowCollection.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// 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;
}
}
}

View File

@@ -1,94 +0,0 @@
//
// EnumerableRowCollectionExtensions.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// 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<TResult> Cast<TResult> (this EnumerableRowCollection source)
{
return new EnumerableRowCollection<TResult> (Enumerable.Cast<TResult> (source));
}
public static OrderedEnumerableRowCollection<TRow> OrderBy<TRow, TKey> (this EnumerableRowCollection<TRow> source, Func<TRow, TKey> keySelector)
{
return OrderBy<TRow, TKey> (source, keySelector, Comparer<TKey>.Default);
}
public static OrderedEnumerableRowCollection<TRow> OrderBy<TRow, TKey> (this EnumerableRowCollection<TRow> source, Func<TRow, TKey> keySelector, IComparer<TKey> comparer)
{
return OrderedEnumerableRowCollection<TRow>.Create<TRow, TKey> (source, keySelector, comparer, false);
}
public static OrderedEnumerableRowCollection<TRow> OrderByDescending<TRow, TKey> (this EnumerableRowCollection<TRow> source, Func<TRow, TKey> keySelector)
{
return OrderByDescending<TRow, TKey> (source, keySelector, Comparer<TKey>.Default);
}
public static OrderedEnumerableRowCollection<TRow> OrderByDescending<TRow, TKey> (this EnumerableRowCollection<TRow> source, Func<TRow, TKey> keySelector, IComparer<TKey> comparer)
{
return OrderedEnumerableRowCollection<TRow>.Create<TRow, TKey> (source, keySelector, comparer, true);
}
public static EnumerableRowCollection<S> Select<TRow, S> (this EnumerableRowCollection<TRow> source, Func<TRow, S> selector)
{
return new EnumerableRowCollection<S> (Enumerable.Select<TRow, S> (source, selector));
}
public static OrderedEnumerableRowCollection<TRow> ThenBy<TRow, TKey> (this OrderedEnumerableRowCollection<TRow> source, Func<TRow, TKey> keySelector)
{
return ThenBy<TRow, TKey> (source, keySelector, Comparer<TKey>.Default);
}
public static OrderedEnumerableRowCollection<TRow> ThenBy<TRow, TKey> (this OrderedEnumerableRowCollection<TRow> source, Func<TRow, TKey> keySelector, IComparer<TKey> comparer)
{
return OrderedEnumerableRowCollection<TRow>.AddSort<TRow, TKey> (source, keySelector, comparer, false);
}
public static OrderedEnumerableRowCollection<TRow> ThenByDescending<TRow, TKey> (this OrderedEnumerableRowCollection<TRow> source, Func<TRow, TKey> keySelector)
{
return ThenByDescending<TRow, TKey> (source, keySelector, Comparer<TKey>.Default);
}
public static OrderedEnumerableRowCollection<TRow> ThenByDescending<TRow, TKey> (this OrderedEnumerableRowCollection<TRow> source, Func<TRow, TKey> keySelector, IComparer<TKey> comparer)
{
return OrderedEnumerableRowCollection<TRow>.AddSort<TRow, TKey> (source, keySelector, comparer, true);
}
public static EnumerableRowCollection<TRow> Where<TRow> (this EnumerableRowCollection<TRow> source, Func<TRow, bool> predicate)
{
return new EnumerableRowCollection<TRow> (Enumerable.Where<TRow> (source, predicate));
}
}
}

View File

@@ -1,57 +0,0 @@
//
// EnumerableRowCollection_1.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// 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<TRow> : EnumerableRowCollection, IEnumerable<TRow>
{
IEnumerable<TRow> source;
internal EnumerableRowCollection (IEnumerable<TRow> source)
{
this.source = source;
}
public IEnumerator<TRow> GetEnumerator ()
{
foreach (TRow row in source)
yield return row;
}
IEnumerator IEnumerable.GetEnumerator ()
{
return GetEnumerator ();
}
}
}

View File

@@ -1,128 +0,0 @@
//
// OrderedEnumerableRowCollection.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// 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<TRow>
: EnumerableRowCollection<TRow>
{
internal static OrderedEnumerableRowCollection<TRow> Create<TRow, TKey> (IEnumerable<TRow> source, Func<TRow, TKey> keySelector, IComparer<TKey> comparer, bool descending)
{
var sorter = new SortComparer<TRow> ();
sorter.AddSort<TKey> (keySelector, comparer, descending);
return new OrderedEnumerableRowCollection<TRow> (new SortedEnumerable <TRow> (source, sorter));
}
internal static OrderedEnumerableRowCollection<TRow> AddSort<TRow, TKey> (OrderedEnumerableRowCollection<TRow> source, Func<TRow, TKey> keySelector, IComparer<TKey> comparer, bool descending)
{
source.source.Sorter.AddSort<TKey> (keySelector, comparer, descending);
return source;
}
OrderedEnumerableRowCollection (SortedEnumerable<TRow> source)
: base (source)
{
this.source = source;
}
SortedEnumerable<TRow> source;
}
class SortComparer<TRow> : IComparer<TRow>
{
public SortComparer ()
{
}
List<Comparison<TRow>> comparers = new List<Comparison<TRow>> ();
public void AddSort (Comparison<TRow> comparer)
{
comparers.Add (comparer);
}
public void AddSort<TKey> (Func<TRow, TKey> keySelector, IComparer<TKey> comparer, bool descending)
{
if (keySelector == null)
throw new ArgumentNullException ("keySelector");
if (comparer == null)
comparer = Comparer<TKey>.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<TRow> : IEnumerable<TRow>
{
IEnumerable<TRow> source;
SortComparer<TRow> sorter;
public SortedEnumerable (IEnumerable<TRow> source, SortComparer<TRow> sorter)
{
this.source = source;
this.sorter = sorter;
}
public SortComparer<TRow> Sorter {
get { return sorter; }
}
public IEnumerator<TRow> GetEnumerator ()
{
var list = new List<TRow> ();
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 ();
}
}
}

View File

@@ -1,241 +0,0 @@
//
// RowEnumerableDataReader.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// 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;
public RowEnumerableDataReader (IEnumerable source, int depth)
{
this.source = source as EnumerableRowCollection;
if (this.source == null)
this.source = new EnumerableRowCollection<DataRow> ((IEnumerable<DataRow>) 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 e == null; }
}
public int RecordsAffected {
get { return -1; }
}
public void Close ()
{
e = null;
}
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];
}
}
}

View File

@@ -1,68 +0,0 @@
//
// TypedTableBase.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// 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<T> : DataTable, IEnumerable<T>, IEnumerable
where T : DataRow
{
protected TypedTableBase ()
{
}
protected TypedTableBase (SerializationInfo info, StreamingContext context)
: base (info, context)
{
}
public EnumerableRowCollection<TResult> Cast<TResult> ()
{
return new EnumerableRowCollection<TResult> (Enumerable.Cast<TResult> (this));
}
public IEnumerator<T> GetEnumerator ()
{
foreach (object o in Rows)
yield return (T) o;
}
IEnumerator IEnumerable.GetEnumerator ()
{
return GetEnumerator ();
}
}
}

View File

@@ -1,81 +0,0 @@
//
// TypedTableBaseExtensions.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// 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<TRow> AsEnumerable<TRow> (this TypedTableBase<TRow> source) where TRow : DataRow
{
return new EnumerableRowCollection<TRow> (source);
}
public static OrderedEnumerableRowCollection<TRow> OrderBy<TRow, TKey> (this TypedTableBase<TRow> source, Func<TRow, TKey> keySelector)
where TRow : DataRow
{
return OrderBy<TRow, TKey> (source, keySelector, Comparer<TKey>.Default);
}
public static OrderedEnumerableRowCollection<TRow> OrderBy<TRow, TKey> (this TypedTableBase<TRow> source, Func<TRow, TKey> keySelector, IComparer<TKey> comparer)
where TRow : DataRow
{
return OrderedEnumerableRowCollection<TRow>.Create<TRow, TKey> (source, keySelector, comparer, false);
}
public static OrderedEnumerableRowCollection<TRow> OrderByDescending<TRow, TKey> (this TypedTableBase<TRow> source, Func<TRow, TKey> keySelector)
where TRow : DataRow
{
return OrderByDescending<TRow, TKey> (source, keySelector, Comparer<TKey>.Default);
}
public static OrderedEnumerableRowCollection<TRow> OrderByDescending<TRow, TKey> (this TypedTableBase<TRow> source, Func<TRow, TKey> keySelector, IComparer<TKey> comparer)
where TRow : DataRow
{
return OrderedEnumerableRowCollection<TRow>.Create<TRow, TKey> (source, keySelector, comparer, true);
}
public static EnumerableRowCollection<S> Select<TRow, S> (this TypedTableBase<TRow> source, Func<TRow, S> selector)
where TRow : DataRow
{
return new EnumerableRowCollection<S> (Enumerable.Select<TRow, S> (source, selector));
}
public static EnumerableRowCollection<TRow> Where<TRow> (this TypedTableBase<TRow> source, Func<TRow, bool> predicate)
where TRow : DataRow
{
return new EnumerableRowCollection<TRow> (Enumerable.Where<TRow> (source, predicate));
}
}
}

View File

@@ -69,7 +69,7 @@ namespace MonoTests.System.Data
}
[Test]
[ExpectedException (typeof (StrongTypingException))]
[ExpectedException (typeof (InvalidCastException))]
public void Field_T_DBNullFieldValue_ValueType ()
{
DataRow row = SetupRow ();

View File

@@ -31,6 +31,7 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using NUnit.Framework;
namespace MonoTests.System.Data
@@ -72,6 +73,22 @@ namespace MonoTests.System.Data
dt.AsEnumerable ().CopyToDataTable<DataRow> (dst, LoadOption.PreserveChanges);
}
[Test]
public void AsEnumerable ()
{
DataSet ds = new DataSet ();
ds.ReadXml ("Test/System.Data/testdataset1.xml");
DataTable dt = ds.Tables [0];
Assert.AreEqual ("ScoreList", dt.TableName, "TableName");
var dv = dt.AsEnumerable ();
Assert.AreEqual (4, dv.Count (), "#0");
var i = dv.GetEnumerator ();
Assert.IsTrue (i.MoveNext (), "#1");
Assert.AreEqual (1, i.Current ["ID"], "#2");
Assert.IsTrue (i.MoveNext (), "#3");
Assert.AreEqual (2, i.Current ["ID"], "#4");
}
[Test]
public void AsDataView ()
{