⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 collection.vb

📁 大名鼎鼎的mono是.NET平台的跨平台(支持linux
💻 VB
📖 第 1 页 / 共 2 页
字号:
'' Collection.vb'' Author:'   Chris J Breisch (cjbreisch@altavista.net) '   Mizrahi Rafael (rafim@mainsoft.com)'   Boris Kirzner (borisk@mainsoft.com)''' Copyright (C) 2002-2006 Mainsoft Corporation.' Copyright (C) 2004-2006 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.'Imports SystemImports System.Runtime.InteropServicesImports System.CollectionsImports System.ComponentModelImports System.Runtime.SerializationImports System.ReflectionNamespace Microsoft.VisualBasic#If NET_VER >= 2.0 Then    '<DebuggerTypeProxy ("??")>    <Serializable()> _    <DebuggerDisplay("Count = {Count}")> _    Public NotInheritable Class Collection#Else    Public NotInheritable Class Collection#End If        Implements ICollection        Implements IList#If NET_VER >= 2.0 Then        Implements ISerializable        Implements IDeserializationCallback#End If        ' Declarations        Private m_Hashtable As Hashtable = New Hashtable        Private m_HashIndexers As ArrayList = New ArrayList        Private m_KeysCount As Integer = Integer.MinValue        Friend Modified As Boolean = False#If NET_VER < 2.0 Then        Private m_Broken As Boolean#End If        Private Class ColEnumerator            Implements IEnumerator            Private currentKey As Object            Private afterLast As Boolean = False            Private m_col As Collection#If NET_VER >= 2.0 Then            Private m_Current As Object#End If            Public Sub New(ByRef coll As Collection)                m_col = coll                currentKey = Nothing            End Sub            Public Sub Reset() Implements System.Collections.IEnumerator.Reset                If (m_col.Modified) Then                    'LAMESPEC: spec says throw exception, MS doesn't                    'throw new InvalidOperationException();                End If                currentKey = Nothing                afterLast = False            End Sub            Public Function MoveNext() As Boolean Implements System.Collections.IEnumerator.MoveNext                If (m_col.Modified) Then                    'LAMESPEC: spec says throw exception, MS doesn't                    'throw new InvalidOperationException();                End If                If currentKey Is Nothing And m_col.Count > 0 Then                    currentKey = m_col.m_HashIndexers(0)#If NET_VER >= 2.0 Then                    m_Current = CurrentInternal#End If                    Return True                End If#If NET_VER >= 2.0 Then                If afterLast Then                    m_Current = Nothing                    Return False                End If#End If                Dim index As Integer = m_col.m_HashIndexers.IndexOf(currentKey)                If index >= m_col.Count - 1 Then                    afterLast = True#If NET_VER >= 2.0 Then                    m_Current = Nothing#End If                    Return False                End If                currentKey = m_col.m_HashIndexers(index + 1)                afterLast = False#If NET_VER >= 2.0 Then                m_Current = CurrentInternal#End If                Return True            End Function            Public ReadOnly Property Current() As Object Implements System.Collections.IEnumerator.Current                Get#If NET_VER >= 2.0 Then                    Return m_Current#Else                    return CurrentInternal#End If                End Get            End Property            Private ReadOnly Property CurrentInternal() As Object                Get                    Dim index As Integer = m_col.m_HashIndexers.IndexOf(currentKey)                    If index > m_col.Count - 1 Then                        Return Nothing                    Else                        If afterLast Then                            If MoveNext() Then                                Dim tmo As ColEnumerator = Me                                Return tmo.Current()                            Else                                Return Nothing                            End If                        End If                        Return m_col(index + 1)                    End If                End Get            End Property        End Class        ' Constructors        ' Properties        Private ReadOnly Property IsReadOnly() As Boolean Implements System.Collections.IList.IsReadOnly            Get                Return False            End Get        End Property        Private ReadOnly Property IsSynchronized() As Boolean Implements System.Collections.ICollection.IsSynchronized            Get                Return m_Hashtable.IsSynchronized            End Get        End Property        Private ReadOnly Property SyncRoot() As Object Implements System.Collections.ICollection.SyncRoot            Get                Return m_Hashtable.SyncRoot            End Get        End Property        Private ReadOnly Property IsFixedSize() As Boolean Implements System.Collections.IList.IsFixedSize            Get                Return False            End Get        End Property        Public ReadOnly Property Count() As Integer            Get                Return IList_Count            End Get        End Property        Private ReadOnly Property IList_Count() As Integer Implements System.Collections.IList.Count            Get                Return m_HashIndexers.Count            End Get        End Property#If NET_VER >= 2.0 Then        <EditorBrowsable(EditorBrowsableState.Advanced)> _        Default Public Overloads ReadOnly Property Item(ByVal index As Object) As Object#Else        Default Public Overloads ReadOnly Property Item(ByVal index As Object) As Object#End If            Get                If index Is Nothing Then Throw New IndexOutOfRangeException("Argument 'Index' is not a valid index.")                If TypeOf index Is Integer Then                    Return Item(CInt(index))                Else                    Dim idx As Integer = m_HashIndexers.IndexOf(index)                    If idx = -1 Then                        Throw New ArgumentException("Argument 'Index' is not a valid value.")                    End If                    Return Item(idx + 1)                End If            End Get        End Property        Default Public Overloads ReadOnly Property Item(ByVal index As Integer) As Object            Get                'The behaviour of Collection.Item is NOT the same as the IList.Item interface implementation.                index = index - 1                If index > Count - 1 Or index < 0 Then                    Throw New IndexOutOfRangeException("Collection1 index must be in the range 1 to the size of the collection.")                End If                Return m_Hashtable(m_HashIndexers(index))            End Get        End Property#If NET_2_0 Then        Default Public Overloads ReadOnly Property Item(ByVal index As String) As Object            Get                Return Item(CObj(index))            End Get        End Property#End If        Private Property IList_Item(ByVal index As Integer) As Object Implements System.Collections.IList.Item            Get#If NET_VER < 2.0 Then                If m_Broken Then Throw New InvalidCastException ()#End If                If index < 0 AndAlso Count > 0 Then                    'Oh man this behaviour is weird...                    index = 0                End If                If index > Count - 1 Or index < 0 Then                    Throw New ArgumentOutOfRangeException("Collection1 index must be in the range 1 to the size of the collection.")                End If                Return m_Hashtable(m_HashIndexers(index))            End Get            Set(ByVal Value As Object)#If NET_VER < 2.0 Then                m_Broken = True#End If                If index < 0 AndAlso Count > 0 Then                    'Oh man this behaviour is weird...                    index = 0                End If

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -