Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ' ***********************************************************************
- ' Author : Elektro
- ' Modified : 17-December-2015
- ' ***********************************************************************
- #Region " Imports "
- Imports System
- Imports System.Collections.ObjectModel
- Imports System.ComponentModel
- Imports System.Diagnostics
- Imports System.Linq
- #End Region
- #Region " INI Section Collection "
- Namespace Types
- ''' ----------------------------------------------------------------------------------------------------
- ''' <summary>
- ''' Represents a strongly typed list of <see cref="IniSection"/> that can be accessed by an index.
- ''' </summary>
- ''' ----------------------------------------------------------------------------------------------------
- Public NotInheritable Class IniSectionCollection : Inherits Collection(Of IniSection)
- #Region " Constructors "
- ''' ----------------------------------------------------------------------------------------------------
- ''' <summary>
- ''' Initializes a new instance of the <see cref="IniSectionCollection"/> class.
- ''' </summary>
- ''' ----------------------------------------------------------------------------------------------------
- Public Sub New()
- End Sub
- #End Region
- #Region " Indexers "
- ''' ----------------------------------------------------------------------------------------------------
- ''' <summary>
- ''' Gets or sets the <see cref="IniSection"/> that matches the specified section name.
- ''' </summary>
- ''' ----------------------------------------------------------------------------------------------------
- ''' <param name="sectionName">
- ''' The section name.
- ''' </param>
- ''' ----------------------------------------------------------------------------------------------------
- ''' <value>
- ''' The <see cref="IniSection"/>.
- ''' </value>
- ''' ----------------------------------------------------------------------------------------------------
- Default Public Overloads Property Item(ByVal sectionName As String) As IniSection
- <DebuggerStepThrough>
- Get
- Return Me.Find(sectionName)
- End Get
- <DebuggerStepThrough>
- Set(ByVal value As IniSection)
- Me(Me.IndexOf(sectionName)) = value
- End Set
- End Property
- #End Region
- #Region " Public Methods "
- ''' ----------------------------------------------------------------------------------------------------
- ''' <summary>
- ''' Adds a <see cref="IniSection"/> to the end of the <see cref="IniSectionCollection"/>.
- ''' </summary>
- ''' ----------------------------------------------------------------------------------------------------
- ''' <param name="section">
- ''' The section to add.
- ''' </param>
- ''' ----------------------------------------------------------------------------------------------------
- ''' <exception cref="ArgumentException">
- ''' Section already exists.;section
- ''' </exception>
- ''' ----------------------------------------------------------------------------------------------------
- <DebuggerStepThrough>
- Public Shadows Sub Add(ByVal section As IniSection)
- If Me.Contains(section.Name) Then
- Throw New ArgumentException(message:="Section already exists.", paramName:="section")
- Else
- MyBase.Add(section)
- End If
- End Sub
- ''' ----------------------------------------------------------------------------------------------------
- ''' <summary>
- ''' Adds a <see cref="IniSection"/> to the end of the <see cref="IniSectionCollection"/>.
- ''' </summary>
- ''' ----------------------------------------------------------------------------------------------------
- ''' <param name="sectionName">
- ''' The section name to add.
- ''' </param>
- ''' ----------------------------------------------------------------------------------------------------
- ''' <exception cref="ArgumentException">
- ''' Section already exists.;section
- ''' </exception>
- ''' ----------------------------------------------------------------------------------------------------
- <DebuggerStepThrough>
- Public Shadows Sub Add(ByVal sectionName As String)
- Me.Add(New IniSection(sectionName))
- End Sub
- ''' ----------------------------------------------------------------------------------------------------
- ''' <summary>
- ''' Adds the specified sections to the end of the <see cref="IniSectionCollection"/>.
- ''' </summary>
- ''' ----------------------------------------------------------------------------------------------------
- ''' <param name="sections">
- ''' The sections to add.
- ''' </param>
- ''' ----------------------------------------------------------------------------------------------------
- ''' <exception cref="ArgumentException">
- ''' Section already exists.;section
- ''' </exception>
- ''' ----------------------------------------------------------------------------------------------------
- <DebuggerStepThrough>
- Public Shadows Sub AddRange(ByVal sections As IniSection())
- For Each section As IniSection In sections
- Me.Add(section)
- Next section
- End Sub
- ''' ----------------------------------------------------------------------------------------------------
- ''' <summary>
- ''' Adds the specified section names to the end of the <see cref="IniSectionCollection"/>.
- ''' </summary>
- ''' ----------------------------------------------------------------------------------------------------
- ''' <param name="sectionNames">
- ''' The section names to add.
- ''' </param>
- ''' ----------------------------------------------------------------------------------------------------
- ''' <exception cref="ArgumentException">
- ''' Section already exists.;section
- ''' </exception>
- ''' ----------------------------------------------------------------------------------------------------
- <DebuggerStepThrough>
- Public Shadows Sub AddRange(ByVal sectionNames As String())
- For Each sectionName As String In sectionNames
- Me.Add(New IniSection(sectionName))
- Next sectionName
- End Sub
- ''' ----------------------------------------------------------------------------------------------------
- ''' <summary>
- ''' Removes a <see cref="IniSection"/> from the <see cref="IniSectionCollection"/>.
- ''' </summary>
- ''' ----------------------------------------------------------------------------------------------------
- ''' <param name="section">
- ''' The section to remove.
- ''' </param>
- ''' ----------------------------------------------------------------------------------------------------
- ''' <exception cref="ArgumentException">
- ''' Section doesn't exists.;section
- ''' </exception>
- ''' ----------------------------------------------------------------------------------------------------
- <DebuggerStepThrough>
- Public Shadows Sub Remove(ByVal section As IniSection)
- Dim indexOf As Integer = Me.IndexOf(section)
- If (indexOf = -1) Then
- Throw New ArgumentException(message:="Section doesn't exists.", paramName:="section")
- Else
- MyBase.RemoveAt(indexOf)
- End If
- End Sub
- ''' ----------------------------------------------------------------------------------------------------
- ''' <summary>
- ''' Removes a <see cref="IniSection"/> from the <see cref="IniSectionCollection"/>.
- ''' </summary>
- ''' ----------------------------------------------------------------------------------------------------
- ''' <param name="sectionName">
- ''' The section name to remove.
- ''' </param>
- ''' ----------------------------------------------------------------------------------------------------
- ''' <exception cref="ArgumentException">
- ''' Section doesn't exists.;section
- ''' </exception>
- ''' ----------------------------------------------------------------------------------------------------
- <DebuggerStepThrough>
- Public Shadows Sub Remove(ByVal sectionName As String)
- Dim indexOf As Integer = Me.IndexOf(sectionName)
- If (indexOf = -1) Then
- Throw New ArgumentException(message:="Section doesn't exists.", paramName:="sectionName")
- Else
- MyBase.RemoveAt(indexOf)
- End If
- End Sub
- ''' ----------------------------------------------------------------------------------------------------
- ''' <summary>
- ''' Determines whether the <see cref="IniSectionCollection"/> contains a <see cref="IniSection"/> that
- ''' matches the specified section name.
- ''' </summary>
- ''' ----------------------------------------------------------------------------------------------------
- ''' <param name="sectionName">
- ''' The section name.
- ''' </param>
- ''' ----------------------------------------------------------------------------------------------------
- ''' <returns>
- ''' <see langword="True"/> if the <see cref="IniSectionCollection"/> contains the <see cref="IniSection"/>,
- ''' <see langword="False"/> otherwise.
- ''' </returns>
- ''' ----------------------------------------------------------------------------------------------------
- <DebuggerStepThrough>
- Public Overloads Function Contains(ByVal sectionName As String) As Boolean
- Return (From section As IniSection In Me
- Where section.Name.Equals(sectionName, StringComparison.OrdinalIgnoreCase)).Any
- End Function
- ''' ----------------------------------------------------------------------------------------------------
- ''' <summary>
- ''' Searches for an <see cref="IniSection"/> that matches the specified section name,
- ''' and returns the first occurrence within the entire <see cref="IniSectionCollection"/>.
- ''' </summary>
- ''' ----------------------------------------------------------------------------------------------------
- ''' <param name="sectionName">
- ''' The section name.
- ''' </param>
- ''' ----------------------------------------------------------------------------------------------------
- ''' <returns>
- ''' <see cref="IniSection"/>.
- ''' </returns>
- ''' ----------------------------------------------------------------------------------------------------
- <DebuggerStepThrough>
- Public Overloads Function Find(ByVal sectionName As String) As IniSection
- Return (From section As IniSection In Me
- Where section.Name.Equals(sectionName, StringComparison.OrdinalIgnoreCase)).
- DefaultIfEmpty(Nothing).
- SingleOrDefault
- End Function
- ''' ----------------------------------------------------------------------------------------------------
- ''' <summary>
- ''' Searches for an <see cref="IniSection"/> that matches the specified section name and
- ''' returns the zero-based index of the first occurrence within the entire <see cref="IniSectionCollection"/>.
- ''' </summary>
- ''' ----------------------------------------------------------------------------------------------------
- ''' <param name="sectionName">
- ''' The section name.
- ''' </param>
- ''' ----------------------------------------------------------------------------------------------------
- ''' <returns>
- ''' The zero-based index of the first occurrence of <see cref="IniSection"/> within the entire <see cref="IniSectionCollection"/>, if found;
- ''' otherwise, <c>–1</c>.
- ''' </returns>
- ''' ----------------------------------------------------------------------------------------------------
- <DebuggerStepThrough>
- Public Overloads Function IndexOf(ByVal sectionName As String) As Integer
- Dim index As Integer = 0
- Dim found As Boolean = False
- For Each section As IniSection In Me
- If section.Name.Equals(sectionName, StringComparison.OrdinalIgnoreCase) Then
- found = True
- Exit For
- End If
- index += 1
- Next section
- If (found) Then
- Return index
- Else
- Return -1
- End If
- End Function
- #End Region
- End Class
- End Namespace
- #End Region
Add Comment
Please, Sign In to add comment