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