Skip to content

Commit d4c8ea0

Browse files
authored
Move into Shared SqlErrorCollection.cs (#1305)
1 parent b75dfb5 commit d4c8ea0

File tree

5 files changed

+56
-120
lines changed

5 files changed

+56
-120
lines changed

src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,9 @@
259259
<Compile Include="..\..\src\Microsoft\Data\SqlClient\SqlDataAdapter.cs">
260260
<Link>Microsoft\Data\SqlClient\SqlDataAdapter.cs</Link>
261261
</Compile>
262+
<Compile Include="..\..\src\Microsoft\Data\SqlClient\SqlErrorCollection.cs">
263+
<Link>Microsoft\Data\SqlClient\SqlErrorCollection.cs</Link>
264+
</Compile>
262265
<Compile Include="..\..\src\Microsoft\Data\SqlClient\SqlInfoMessageEventHandler.cs">
263266
<Link>Microsoft\Data\SqlClient\SqlInfoMessageEventHandler.cs</Link>
264267
</Compile>
@@ -533,7 +536,6 @@
533536
<Compile Include="Microsoft\Data\SqlClient\SqlDelegatedTransaction.cs" />
534537
<Compile Include="Microsoft\Data\SqlClient\SqlEnums.cs" />
535538
<Compile Include="Microsoft\Data\SqlClient\SqlError.cs" />
536-
<Compile Include="Microsoft\Data\SqlClient\SqlErrorCollection.cs" />
537539
<Compile Include="..\..\src\Microsoft\Data\SqlClient\SqlEnclaveSession.cs">
538540
<Link>Microsoft\Data\SqlClient\SqlEnclaveSession.cs</Link>
539541
</Compile>

src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlErrorCollection.cs

Lines changed: 0 additions & 46 deletions
This file was deleted.

src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,9 @@
333333
<Compile Include="..\..\src\Microsoft\Data\SqlClient\SqlEnclaveSession.cs">
334334
<Link>Microsoft\Data\SqlClient\SqlEnclaveSession.cs</Link>
335335
</Compile>
336+
<Compile Include="..\..\src\Microsoft\Data\SqlClient\SqlErrorCollection.cs">
337+
<Link>Microsoft\Data\SqlClient\SqlErrorCollection.cs</Link>
338+
</Compile>
336339
<Compile Include="..\..\src\Microsoft\Data\SqlClient\SqlInfoMessageEventHandler.cs">
337340
<Link>Microsoft\Data\SqlClient\SqlInfoMessageEventHandler.cs</Link>
338341
</Compile>
@@ -515,7 +518,6 @@
515518
<Compile Include="Microsoft\Data\SqlClient\SqlDependencyUtils.cs" />
516519
<Compile Include="Microsoft\Data\SqlClient\SqlEnums.cs" />
517520
<Compile Include="Microsoft\Data\SqlClient\SqlError.cs" />
518-
<Compile Include="Microsoft\Data\SqlClient\SqlErrorCollection.cs" />
519521
<Compile Include="Microsoft\Data\SqlClient\SqlException.cs" />
520522
<Compile Include="Microsoft\Data\SqlClient\SqlInfoMessageEvent.cs" />
521523
<Compile Include="Microsoft\Data\SqlClient\SqlInternalConnection.cs" />

src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlErrorCollection.cs

Lines changed: 0 additions & 72 deletions
This file was deleted.
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System;
6+
using System.Collections;
7+
using System.Collections.Generic;
8+
using System.ComponentModel;
9+
10+
namespace Microsoft.Data.SqlClient
11+
{
12+
/// <include file='../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlErrorCollection.xml' path='docs/members[@name="SqlErrorCollection"]/SqlErrorCollection/*' />
13+
[Serializable, ListBindable(false)]
14+
public sealed class SqlErrorCollection : ICollection
15+
{
16+
// Ideally this would be typed as List<SqlError>, but that would make the non-generic
17+
// CopyTo behave differently than the full framework (which uses ArrayList), throwing
18+
// ArgumentException instead of the expected InvalidCastException for incompatible types.
19+
// Instead, we use List<object>, which makes the non-generic CopyTo behave like
20+
// ArrayList.CopyTo.
21+
private readonly List<object> _errors = new List<object>();
22+
23+
internal SqlErrorCollection() { }
24+
25+
/// <include file='../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlErrorCollection.xml' path='docs/members[@name="SqlErrorCollection"]/CopyToArrayIndex1/*' />
26+
public void CopyTo(Array array, int index) => ((ICollection)_errors).CopyTo(array, index);
27+
28+
/// <include file='../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlErrorCollection.xml' path='docs/members[@name="SqlErrorCollection"]/CopyToArrayIndex2/*' />
29+
public void CopyTo(SqlError[] array, int index) => _errors.CopyTo(array, index);
30+
31+
/// <include file='../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlErrorCollection.xml' path='docs/members[@name="SqlErrorCollection"]/Count/*' />
32+
public int Count => _errors.Count;
33+
34+
/// <include file='../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlErrorCollection.xml' path='docs/members[@name="SqlErrorCollection"]/System.Collections.ICollection.SyncRoot/*' />
35+
// MDAC 68481
36+
object ICollection.SyncRoot => this;
37+
38+
/// <include file='../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlErrorCollection.xml' path='docs/members[@name="SqlErrorCollection"]/System.Collections.ICollection.IsSynchronized/*' />
39+
// MDAC 68481
40+
bool ICollection.IsSynchronized => false;
41+
42+
/// <include file='../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlErrorCollection.xml' path='docs/members[@name="SqlErrorCollection"]/Item/*' />
43+
public SqlError this[int index] => (SqlError)_errors[index];
44+
45+
/// <include file='../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlErrorCollection.xml' path='docs/members[@name="SqlErrorCollection"]/GetEnumerator/*' />
46+
public IEnumerator GetEnumerator() => _errors.GetEnumerator();
47+
48+
internal void Add(SqlError error) => _errors.Add(error);
49+
}
50+
}

0 commit comments

Comments
 (0)