<%@ CodeTemplate Language="VB" TargetLanguage="VB" Description="Template description here." %> <%@ Property Name="ClassNamespace" Type="System.String" Optional="True" Category="Context" Description="The namespace that the generated class will be a member of." %> <%@ Property Name="ItemType" Type="System.String" Category="Context" Description="The type to use as an item in the collection." %> <%@ Property Name="ClassName" Type="System.String" Category="Context" Description="The name of the class to be generated." %> <%@ Property Name="Accessibility" Type="AccessibilityEnum" Category="Options" Description="The accessibility of the class to be generated." %> <%@ Property Name="GenerateDocumentation" Type="System.Boolean" Default="True" Category="Options" Description="Wether or not to include class documentation." %> Option Strict On Option Explicit On Imports System Imports System.Collections <% If Not ClassNamespace Is Nothing AndAlso ClassNamespace.Length > 0 Then %> Namespace <%=ClassNamespace%> <% End If %> <% If GenerateDocumentation Then %> ''' ''' A strongly-typed collection of objects. ''' <% End If %> <%=GetAccessModifier(Accessibility)%> Class <%= ClassName %> Inherits CollectionBase <% If GenerateDocumentation Then %> ''' ''' Initializes a new instance of the <%= ClassName %> class ''' that is empty and has the default initial capacity. ''' <% End If %> Public Sub New() End Sub <% If GenerateDocumentation Then %> ''' ''' Initializes a new instance of the <%= ClassName %> class ''' that contains elements copied from the specified <%= ClassName %>. ''' ''' The <%= ClassName %> whose elements are copied to the new collection. <% End If %> Public Sub New(ByVal c As <%= ClassName %>) Me.InnerList.AddRange(c) End Sub <% If GenerateDocumentation %> ''' ''' Gets or sets the at the specified index. ''' ''' The zero-based index of the element to get or set. ''' ''' is less than zero ''' -or- ''' is equal to or greater than . ''' <% End If %> Default Public Property <%= ItemType %> (ByVal index As Integer) As <%= ItemType %> Get Return CType(List(index), <%= ItemType %>) End Get Set(ByVal Value As <%= ItemType %>) List(index) = Value End Set End Property <% If GenerateDocumentation %> ''' ''' Adds a to the end of the <%= ClassName %>. ''' ''' The to be added to the end of the <%= ClassName %>. ''' The index at which the value has been added. <% End If %> Public Overridable Function Add(ByVal item As <%= ItemType %>) As Integer Return List.Add(item) End Function <% If GenerateDocumentation Then %> ''' ''' Inserts an element into the <%= ClassName %> at the specified index. ''' ''' The zero-based index at which should be inserted. ''' The to insert. ''' ''' is less than zero ''' -or- ''' is equal to or greater than . ''' <% End If %> Public Overridable Sub Insert(ByVal index As Integer, ByVal item As <%= ItemType %> ) List.Insert(index, Item) End Sub <% If GenerateDocumentation Then %> ''' ''' Removes the first occurrence of a specific from the <%= ClassName %>. ''' ''' The to remove from the <%= ClassName %>. ''' ''' The specified was not found in the <%= ClassName %>. ''' <% End If %> Public Overridable Sub Remove(ByVal item As <%= ItemType %>) List.Remove(Item) End Sub <% If GenerateDocumentation Then %> ''' ''' Determines whether a given is in the <%= ClassName %>. ''' ''' The to check for. ''' true if is found in the <%= ClassName %>; otherwise, false. <% End If %> Public Function Contains(ByVal item As <%= ItemType %>) As Boolean Return List.Contains(Item) End Function <% If GenerateDocumentation Then %> ''' ''' Returns the zero-based index of the first occurrence of a ''' in the <%= ClassName %>. ''' ''' The to locate in the <%= ClassName %>. ''' ''' The zero-based index of the first occurrence of ''' in the entire <%= ClassName %>, if found; otherwise, -1. ''' <% End If %> Public Function IndexOf(ByVal item As <%= ItemType %>) As Integer Return List.IndexOf(Item) End Function <% If GenerateDocumentation %> ''' ''' Copies the entire <%= ClassName %> to a one-dimensional ''' array. ''' ''' The one-dimensional array to copy to. <% End If %> Public Sub CopyTo(ByVal Array As <%= ItemType %>(), ByVal index As Integer) List.CopyTo(Array, index) End Sub <% If GenerateDocumentation Then %> ''' ''' Creates a read-only wrapper for a ''' <%= ClassName %> instance. ''' ''' ''' An <%= ClassName %> wrapper that is read-only. ''' <% End If %> Public Shared Function ReadOnlyCollection<%= ClassName %>(ByVal coll As <%= ClassName %>) As <%= ClassName %> Return New <%= ClassName %>.ReadOnly<%= ClassName %>(coll) End Sub Protected Overrides Sub OnValidate(ByVal value As Object) MyBase.OnValidate(value) If Not (TypeOf(value) Is <%= ItemType %>) Then Throw New ArgumentException("Collection only supports <%= ItemType %> objects.") End If End Sub #REGION "ReadOnly<%= ClassName %>" Private NotInheritable Class ReadOnly<%= ClassName %> Inherits <%= ClassName %> Private Const ERROR_STRING As String = "Collection is read-only." Friend Sub New(ByVal col1 As <%= ClassName %>) MyBase.New(col1) End Sub Public Overrides Function Add(ByVal value As <%= ItemType %>) As Integer Throw New NotSupportedException(ERROR_STRING) End Function Public Overrides Sub Remove(ByVal value As <%= ItemType %>) Throw New NotSupportedException(ERROR_STRING) End Sub Protected Overrides Sub OnClear() Throw New NotSupportedException(ERROR_STRING) End Sub Protected Overrides Sub OnInsert(ByVal index As Integer, ByVal value As Object) Throw New NotSupportedException(ERROR_STRING) End Sub Protected Overrides Sub OnRemove(ByVal index As Integer, ByVal value As Object) Throw New NotSupportedException(ERROR_STRING) End Sub Protected Overrides Sub OnSet(ByVal index As Integer, ByVal oldValue As Object, ByVal NewValue As Object) Throw New NotSupportedException(ERROR_STRING) End Sub End Class #End Region End Class <% If Not ClassNamespace Is Nothing AndAlso ClassNamespace.Length > 0 Then %> End NameSpace <% End If %>