Imported Upstream version 3.6.0

Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
This commit is contained in:
Jo Shields
2014-08-13 10:39:27 +01:00
commit a575963da9
50588 changed files with 8155799 additions and 0 deletions

View File

@@ -0,0 +1,70 @@
//
// AssemblyInfo.cs
//
// Author:
// Andreas Nahr (ClassDevelopment@A-SoftTech.com)
//
// Copyright 2003-2004 Ximian, Inc. http://www.ximian.com
// Copyright 2004-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.Reflection;
using System.Resources;
using System.Security;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about the System.Data.DataSetExtensions assembly
// v3.5 Assembly
[assembly: AssemblyTitle ("System.Data.DataSetExtensions.dll")]
[assembly: AssemblyDescription ("System.Data.DataSetExtensions.dll")]
[assembly: AssemblyDefaultAlias ("System.Data.DataSetExtensions.dll")]
[assembly: AssemblyCompany (Consts.MonoCompany)]
[assembly: AssemblyProduct (Consts.MonoProduct)]
[assembly: AssemblyCopyright (Consts.MonoCopyright)]
[assembly: AssemblyVersion (Consts.FxVersion)]
[assembly: SatelliteContractVersion (Consts.FxVersion)]
[assembly: AssemblyInformationalVersion (Consts.FxFileVersion)]
[assembly: AssemblyFileVersion (Consts.FxFileVersion)]
[assembly: NeutralResourcesLanguage ("en-US")]
[assembly: CLSCompliant (true)]
#if TARGET_JVM
[assembly: AssemblyDelaySign (false)]
#else
[assembly: AssemblyDelaySign (true)]
[assembly: AssemblyKeyFile ("../ecma.pub")]
#endif
[assembly: ComVisible (false)]
[assembly: AllowPartiallyTrustedCallers]
[assembly: CompilationRelaxations (CompilationRelaxations.NoStringInterning)]
[assembly: SecurityCritical]
[assembly: ComCompatibleVersion (1, 0, 3300, 0)]

View File

@@ -0,0 +1,3 @@
2008-05-14 Atsushi Enomoto <atsushi@ximian.com>
* AssemblyInfo.cs : assembly names were wrong.

View File

@@ -0,0 +1,27 @@
2008-12-02 Marek Habersack <mhabersack@novell.com>
* System.Data.DataSetExtensions_test.dll.sources: added
System.Data/DataRowExtensionsTest.cs
2008-10-17 Jonathan Pryor <jpryor@novell.com>
* Test/Makefile: Add doc-update target support.
2008-05-14 Atsushi Enomoto <atsushi@ximian.com>
* Makefile : use EXTRA_DISTFILES.
2008-05-14 Atsushi Enomoto <atsushi@ximian.com>
* System.Data.DataSetExtensions.dll.sources :
added RowEnumerableDataReader.cs
* System.Data.DataSetExtensions_test.dll.sources :
added DataTableExtensionsTest.cs.
2008-05-13 Atsushi Enomoto <atsushi@ximian.com>
* System.Data.DataSetExtensions_test.dll.sources : new.
2008-05-13 Atsushi Enomoto <atsushi@ximian.com>
* Makefile : make it build under net_2_0 build profile.

View File

@@ -0,0 +1,27 @@
thisdir = class/System.Data.DataSetExtensions
SUBDIRS = Test
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)
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
TEST_MCS_FLAGS = $(LIB_MCS_FLAGS) -doc:$(test_lib:.dll=.xml) -nowarn:219 -nowarn:169 $(NUNIT_RESOURCE_FILES:%=/resource:%)
EXTRA_DISTFILES = $(RESOURCE_FILES) \
Test/System.Data/testdataset1.xml
include ../../build/library.make

View File

@@ -0,0 +1,15 @@
../../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

View File

@@ -0,0 +1,4 @@
System.Data/DataRowComparerTest.cs
System.Data/DataRowExtensionsTest.cs
System.Data/DataTableExtensionsTest.cs
System.Data/EnumerableRowCollectionTest.cs

View File

@@ -0,0 +1,77 @@
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

@@ -0,0 +1,42 @@
//
// 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

@@ -0,0 +1,109 @@
//
// 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

@@ -0,0 +1,93 @@
//
// 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

@@ -0,0 +1,106 @@
//
// 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

@@ -0,0 +1,62 @@
//
// 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

@@ -0,0 +1,94 @@
//
// 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

@@ -0,0 +1,57 @@
//
// 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

@@ -0,0 +1,128 @@
//
// 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

@@ -0,0 +1,241 @@
//
// 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

@@ -0,0 +1,68 @@
//
// 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

@@ -0,0 +1,81 @@
//
// 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

@@ -0,0 +1,8 @@
thisdir = class/System.Data.DataSetExtensions/Test
include ../../../build/rules.make
all-local install-local clean-local test-local run-test-local run-test-ondotnet-local uninstall-local doc-update-local csproj-local:
DISTFILES = $(wildcard *.aspx)
dist-local: dist-default

View File

@@ -0,0 +1,28 @@
2008-12-02 Marek Habersack <mhabersack@novell.com>
* DataRowExtensionsTest.cs: added
2008-08-15 Gert Driesen <drieseng@users.sourceforge.net>
* DataRowComparerTest.cs: added tests for Equals and GetHashCode.
Enabled GetHashCodeWithVersions test.
2008-05-14 Atsushi Enomoto <atsushi@ximian.com>
* DataTableExtensionsTest.cs : new test.
2008-05-14 Atsushi Enomoto <atsushi@ximian.com>
* EnumerableRowCollectionTest.cs : added tests for thenby (again
commented out yet).
2008-05-13 Atsushi Enomoto <atsushi@ximian.com>
* EnumerableRowCollectionTest.cs : added tests for orderby (though
commented out; they do not compile).
2008-05-13 Atsushi Enomoto <atsushi@ximian.com>
* DataRowComparerTest.cs, EnumerableRowCollectionTest.cs,
testdataset1.xml : new tests.

Some files were not shown because too many files have changed in this diff Show More