<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comments on: Implementing CollectionBase</title>
	<atom:link href="http://www.mattberther.com/2004/09/05/implementing-collectionbase/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.mattberther.com/2004/09/05/implementing-collectionbase/</link>
	<description>Agile Manager and Occasional Code Monkey</description>
	<pubDate>Thu, 20 Nov 2008 22:16:17 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.3</generator>
		<item>
		<title>By: heracles maroudas</title>
		<link>http://www.mattberther.com/2004/09/05/implementing-collectionbase/#comment-647</link>
		<dc:creator>heracles maroudas</dc:creator>
		<pubDate>Mon, 17 Apr 2006 14:49:45 +0000</pubDate>
		<guid isPermaLink="false">http://www.mattberther.com/blog/?p=540#comment-647</guid>
		<description>Strongly Typed CollectionBase Class
			Eric Maroudas
			Creates a Strongly Typed Collection Base Class Implementation.
			classCollectionBase
			
				Expansion
			
		
		
			
				
					ClassName
					Replace with your collection base class name.
					className
				
				
					TypeName
					Replace with your custom type class.
					yourType
				
				
					ItemName
					Replace with an item name of your choice
					item
				
			
			
				 
				{	
					#region Implemantation
					
					public int Add($TypeName$ $ItemName$)
					{
						return ((IList)this).Add((object)$ItemName$);
					}
					
					public void Remove($TypeName$ $ItemName$)
					{
						((IList)this).Remove((object)$ItemName$);
					}
					
					public void Insert(int index, $TypeName$ $ItemName$)
					{
						((IList)this).Insert(index, (object)$ItemName$);
					}
					
					public bool Contains($TypeName$ $ItemName$)
					{
						return ((IList)this).Contains((object)$ItemName$);
					}
					
					public int IndexOf($TypeName$ $ItemName$)
					{
						return ((IList)this).IndexOf((object)$ItemName$);
					}
					
					public void CopyTo($TypeName$[] $ItemName$Array, int index)
					{
						((ICollection)this).CopyTo($ItemName$Array, index);
					}
					
					public $TypeName$ this[int index]
					{
						get { return ($TypeName$)((IList)this)[index]; }
						set { ((IList)this)[index] = value; }
					}
					
					#endregion Implemantation
					
					#region IEnumerable Members
					
					public new IEnumerator GetEnumerator()
					{
						foreach ($TypeName$ $ItemName$ in InnerList)
						{
							yield return $ItemName$;
						}        
					}
					
					#endregion IEnumerable Members
					
					#region Overrides
					
					protected override void OnValidate(object value)
					{
						base.OnValidate(value);
						if (!(value is $TypeName$))
						{   
							throw new ArgumentException("This type only supports objects of this type.");
						}
					}
					
					#endregion Overrides
				}$end$]]&#62;</description>
		<content:encoded><![CDATA[<p>Strongly Typed CollectionBase Class<br />
			Eric Maroudas<br />
			Creates a Strongly Typed Collection Base Class Implementation.<br />
			classCollectionBase</p>
<p>				Expansion</p>
<p>					ClassName<br />
					Replace with your collection base class name.<br />
					className</p>
<p>					TypeName<br />
					Replace with your custom type class.<br />
					yourType</p>
<p>					ItemName<br />
					Replace with an item name of your choice<br />
					item</p>
<p>				{<br />
					#region Implemantation</p>
<p>					public int Add($TypeName$ $ItemName$)<br />
					{<br />
						return ((IList)this).Add((object)$ItemName$);<br />
					}</p>
<p>					public void Remove($TypeName$ $ItemName$)<br />
					{<br />
						((IList)this).Remove((object)$ItemName$);<br />
					}</p>
<p>					public void Insert(int index, $TypeName$ $ItemName$)<br />
					{<br />
						((IList)this).Insert(index, (object)$ItemName$);<br />
					}</p>
<p>					public bool Contains($TypeName$ $ItemName$)<br />
					{<br />
						return ((IList)this).Contains((object)$ItemName$);<br />
					}</p>
<p>					public int IndexOf($TypeName$ $ItemName$)<br />
					{<br />
						return ((IList)this).IndexOf((object)$ItemName$);<br />
					}</p>
<p>					public void CopyTo($TypeName$[] $ItemName$Array, int index)<br />
					{<br />
						((ICollection)this).CopyTo($ItemName$Array, index);<br />
					}</p>
<p>					public $TypeName$ this[int index]<br />
					{<br />
						get { return ($TypeName$)((IList)this)[index]; }<br />
						set { ((IList)this)[index] = value; }<br />
					}</p>
<p>					#endregion Implemantation</p>
<p>					#region IEnumerable Members</p>
<p>					public new IEnumerator GetEnumerator()<br />
					{<br />
						foreach ($TypeName$ $ItemName$ in InnerList)<br />
						{<br />
							yield return $ItemName$;<br />
						}<br />
					}</p>
<p>					#endregion IEnumerable Members</p>
<p>					#region Overrides</p>
<p>					protected override void OnValidate(object value)<br />
					{<br />
						base.OnValidate(value);<br />
						if (!(value is $TypeName$))<br />
						{<br />
							throw new ArgumentException(&#8221;This type only supports objects of this type.&#8221;);<br />
						}<br />
					}</p>
<p>					#endregion Overrides<br />
				}$end$]]&gt;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: heracles maroudas</title>
		<link>http://www.mattberther.com/2004/09/05/implementing-collectionbase/#comment-646</link>
		<dc:creator>heracles maroudas</dc:creator>
		<pubDate>Mon, 17 Apr 2006 14:49:05 +0000</pubDate>
		<guid isPermaLink="false">http://www.mattberther.com/blog/?p=540#comment-646</guid>
		<description>heres a nice update for this article: a C# code snippet for vs 2005. just place the xml into a .snippet file and add to vs from the tools menus Code Snippet Manager. 

once imported type the short name classCollectionBase and press tab from within the ide...</description>
		<content:encoded><![CDATA[<p>heres a nice update for this article: a C# code snippet for vs 2005. just place the xml into a .snippet file and add to vs from the tools menus Code Snippet Manager. </p>
<p>once imported type the short name classCollectionBase and press tab from within the ide&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sudhakar</title>
		<link>http://www.mattberther.com/2004/09/05/implementing-collectionbase/#comment-645</link>
		<dc:creator>Sudhakar</dc:creator>
		<pubDate>Thu, 05 May 2005 14:19:36 +0000</pubDate>
		<guid isPermaLink="false">http://www.mattberther.com/blog/?p=540#comment-645</guid>
		<description>i want to create windows installer project in which i want to restrict the installation based on the 'Product serial number' entered in the 'Customer information' user interface custom dialog box. i also added the custom action and able to validate the product serial number entered. but my problem is unable to terminate the installation if user enters the wrong serial number. 

can anybody share your experience on this ?

Thanks in advance.
Sudhakar-D
chudhakar@yahoo.com</description>
		<content:encoded><![CDATA[<p>i want to create windows installer project in which i want to restrict the installation based on the &#8216;Product serial number&#8217; entered in the &#8216;Customer information&#8217; user interface custom dialog box. i also added the custom action and able to validate the product serial number entered. but my problem is unable to terminate the installation if user enters the wrong serial number. </p>
<p>can anybody share your experience on this ?</p>
<p>Thanks in advance.<br />
Sudhakar-D<br />
<a href="mailto:chudhakar@yahoo.com">chudhakar@yahoo.com</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matt Berther</title>
		<link>http://www.mattberther.com/2004/09/05/implementing-collectionbase/#comment-644</link>
		<dc:creator>Matt Berther</dc:creator>
		<pubDate>Thu, 05 May 2005 12:45:48 +0000</pubDate>
		<guid isPermaLink="false">http://www.mattberther.com/blog/?p=540#comment-644</guid>
		<description>It seems to me that you would need to implement the Add method to perform a check if the inner list has a count &#62;= 10 before adding.

public void Add(MyType obj)
{
    if (InnerList.Count &#62;= 10)
    {
        throw new ApplicationException("This collection can only hold 10 objects.");
    }
    Innerlist.Add(obj);
}</description>
		<content:encoded><![CDATA[<p>It seems to me that you would need to implement the Add method to perform a check if the inner list has a count &gt;= 10 before adding.</p>
<p>public void Add(MyType obj)<br />
{<br />
    if (InnerList.Count &gt;= 10)<br />
    {<br />
        throw new ApplicationException(&#8221;This collection can only hold 10 objects.&#8221;);<br />
    }<br />
    Innerlist.Add(obj);<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: arun</title>
		<link>http://www.mattberther.com/2004/09/05/implementing-collectionbase/#comment-643</link>
		<dc:creator>arun</dc:creator>
		<pubDate>Thu, 05 May 2005 04:13:42 +0000</pubDate>
		<guid isPermaLink="false">http://www.mattberther.com/blog/?p=540#comment-643</guid>
		<description>Sir
  I created collection property using collection base class.I want to limit the object added (say 10) to the collection.If it is greater than 10 i want to throw an error dialogbox.How to control the no. of objects added to a collection in design time.</description>
		<content:encoded><![CDATA[<p>Sir<br />
  I created collection property using collection base class.I want to limit the object added (say 10) to the collection.If it is greater than 10 i want to throw an error dialogbox.How to control the no. of objects added to a collection in design time.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matej Rizman</title>
		<link>http://www.mattberther.com/2004/09/05/implementing-collectionbase/#comment-642</link>
		<dc:creator>Matej Rizman</dc:creator>
		<pubDate>Thu, 24 Mar 2005 04:27:22 +0000</pubDate>
		<guid isPermaLink="false">http://www.mattberther.com/blog/?p=540#comment-642</guid>
		<description>Chris,

I found error in VB.NET version of template. Instead of

Default Public Property aCustomer(ByVal index As Integer) As Customer

it should generate

Default Public Property Item(ByVal index As Integer) As Customer

If this property is not named "Item", collection editor in PropertyGrid does not recognize generated collection as a strongly-typed collection.

Matej Rizman</description>
		<content:encoded><![CDATA[<p>Chris,</p>
<p>I found error in VB.NET version of template. Instead of</p>
<p>Default Public Property aCustomer(ByVal index As Integer) As Customer</p>
<p>it should generate</p>
<p>Default Public Property Item(ByVal index As Integer) As Customer</p>
<p>If this property is not named &#8220;Item&#8221;, collection editor in PropertyGrid does not recognize generated collection as a strongly-typed collection.</p>
<p>Matej Rizman</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matt Berther</title>
		<link>http://www.mattberther.com/2004/09/05/implementing-collectionbase/#comment-641</link>
		<dc:creator>Matt Berther</dc:creator>
		<pubDate>Thu, 30 Sep 2004 13:20:49 +0000</pubDate>
		<guid isPermaLink="false">http://www.mattberther.com/blog/?p=540#comment-641</guid>
		<description>And you're using CodeSmith to transform the template? If so, send me an email with your file as an attachment, and Ill be glad to take a look at it.</description>
		<content:encoded><![CDATA[<p>And you&#8217;re using CodeSmith to transform the template? If so, send me an email with your file as an attachment, and Ill be glad to take a look at it.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chris Lane</title>
		<link>http://www.mattberther.com/2004/09/05/implementing-collectionbase/#comment-640</link>
		<dc:creator>Chris Lane</dc:creator>
		<pubDate>Thu, 30 Sep 2004 13:17:36 +0000</pubDate>
		<guid isPermaLink="false">http://www.mattberther.com/blog/?p=540#comment-640</guid>
		<description>Matt,

Doh, Sorry about that, The code I posted is an attempt at trying to convert the output of the C# file that the template creates to VB.NET, then I was going to convert the template to VB Style. 

Thank You,

Chris</description>
		<content:encoded><![CDATA[<p>Matt,</p>
<p>Doh, Sorry about that, The code I posted is an attempt at trying to convert the output of the C# file that the template creates to VB.NET, then I was going to convert the template to VB Style. </p>
<p>Thank You,</p>
<p>Chris</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matt Berther</title>
		<link>http://www.mattberther.com/2004/09/05/implementing-collectionbase/#comment-639</link>
		<dc:creator>Matt Berther</dc:creator>
		<pubDate>Thu, 30 Sep 2004 00:57:30 +0000</pubDate>
		<guid isPermaLink="false">http://www.mattberther.com/blog/?p=540#comment-639</guid>
		<description>Chris,

Im not sure what you're trying to do here. It looks like you're trying to combine the codesmith file with a .vb file. 

Which one are you trying to get to work?</description>
		<content:encoded><![CDATA[<p>Chris,</p>
<p>Im not sure what you&#8217;re trying to do here. It looks like you&#8217;re trying to combine the codesmith file with a .vb file. </p>
<p>Which one are you trying to get to work?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chris Lane</title>
		<link>http://www.mattberther.com/2004/09/05/implementing-collectionbase/#comment-638</link>
		<dc:creator>Chris Lane</dc:creator>
		<pubDate>Wed, 29 Sep 2004 21:28:52 +0000</pubDate>
		<guid isPermaLink="false">http://www.mattberther.com/blog/?p=540#comment-638</guid>
		<description>I am having problems trying to convert this example to VB.NET. VS is complaining about the multipile inherits with in a class since the readonly class is within the other class and the regions tags are messed up. Does anybody have a VB.NET version of this template or the result of the template?
Here is what I have so far.
Imports System
Imports System.Collections
Imports Customer


Namespace BusinessObjects.MyClass



     _
        Public Class CustomerCollection
        Inherits CollectionBase

        Public Sub New()

        End Sub

        Public Sub New(ByVal col1 As CustomerCollection)

            Me.InnerList.AddRange(col1)

        End Sub

        Default Public Property aCustomer(ByVal index As Integer) As Customer

            Get

                Return CType(List(index), Customer)

            End Get

            Set(ByVal Value As Customer)

                List(index) = Value

            End Set

        End Property

        Public Overridable Function Add(ByVal value As Customer) As Integer

            Return List.Add(value)

        End Function

        Public Overridable Sub Insert(ByVal index As Integer, ByVal value As Customer)

            List.Insert(index, value)

        End Sub

        Public Overridable Sub Remove(ByVal value As Customer)

            List.Remove(value)

        End Sub

        Public Function Contains(ByVal value As Customer) As Boolean

            Return List.Contains(value)

        End Function

        Public Function IndexOf(ByVal value As Customer) As Integer

            Return List.IndexOf(value)

        End Function

        Public Sub CopyTo(ByVal value() As Customer, ByVal index As Integer)

            List.CopyTo(value, index)

        End Sub

        Public Static Function ReadOnlyCustomerCollection(ByVal col1 As CustomerCollection)

            Return New CustomerCollection.ReadOnlyCustomerCollection(coll)

        End Function

        Protected Overrides Sub OnValidate(ByVal value As Object)

            MyBase.OnValidate(value)

            If Not TypeOf value Is Customer Then

                Throw New ArgumentException("Collection only supports Customer objects.")

            End If

        End Sub

        Public Enum AccessibilityEnum
            [Public]

            [Protected]

            [Internal]

            [ProtectedInternal]

            [Private]
        End Enum



        Public Function GetAccessModifier(ByVal accessibility As AccessibilityEnum) As String

            Select Case accessibility

                Case AccessibilityEnum.Public

                    Return "public"

                Case AccessibilityEnum.Protected

                    Return "protected"

                Case AccessibilityEnum.Internal

                    Return "internal"

                Case AccessibilityEnum.ProtectedInternal

                    Return "protected internal"

                Case AccessibilityEnum.Private

                    Return "private"

                Case Else

                    Return "public"

            End Select

        End Function
#Region "ReadOnlyClass"

Private NonInheritable Class ReadOnlyCustomerCollection 
        Inherits CustomerCollection

        Private Const ERROR_STRING As String = "Collection is read-only."

        Friend ReadOnly Sub New(ByVal value As Customer)
            MyBase.New(coll)
        End Sub

        Public Overrides Function Add(ByVal value As Customer) As Integer

            Throw New NotSupportedException(ERROR_STRING)

        End Function

        Public Overrides Sub Remove(ByVal value As Customer)

            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



End Namespace</description>
		<content:encoded><![CDATA[<p>I am having problems trying to convert this example to VB.NET. VS is complaining about the multipile inherits with in a class since the readonly class is within the other class and the regions tags are messed up. Does anybody have a VB.NET version of this template or the result of the template?<br />
Here is what I have so far.<br />
Imports System<br />
Imports System.Collections<br />
Imports Customer</p>
<p>Namespace BusinessObjects.MyClass</p>
<p>     _<br />
        Public Class CustomerCollection<br />
        Inherits CollectionBase</p>
<p>        Public Sub New()</p>
<p>        End Sub</p>
<p>        Public Sub New(ByVal col1 As CustomerCollection)</p>
<p>            Me.InnerList.AddRange(col1)</p>
<p>        End Sub</p>
<p>        Default Public Property aCustomer(ByVal index As Integer) As Customer</p>
<p>            Get</p>
<p>                Return CType(List(index), Customer)</p>
<p>            End Get</p>
<p>            Set(ByVal Value As Customer)</p>
<p>                List(index) = Value</p>
<p>            End Set</p>
<p>        End Property</p>
<p>        Public Overridable Function Add(ByVal value As Customer) As Integer</p>
<p>            Return List.Add(value)</p>
<p>        End Function</p>
<p>        Public Overridable Sub Insert(ByVal index As Integer, ByVal value As Customer)</p>
<p>            List.Insert(index, value)</p>
<p>        End Sub</p>
<p>        Public Overridable Sub Remove(ByVal value As Customer)</p>
<p>            List.Remove(value)</p>
<p>        End Sub</p>
<p>        Public Function Contains(ByVal value As Customer) As Boolean</p>
<p>            Return List.Contains(value)</p>
<p>        End Function</p>
<p>        Public Function IndexOf(ByVal value As Customer) As Integer</p>
<p>            Return List.IndexOf(value)</p>
<p>        End Function</p>
<p>        Public Sub CopyTo(ByVal value() As Customer, ByVal index As Integer)</p>
<p>            List.CopyTo(value, index)</p>
<p>        End Sub</p>
<p>        Public Static Function ReadOnlyCustomerCollection(ByVal col1 As CustomerCollection)</p>
<p>            Return New CustomerCollection.ReadOnlyCustomerCollection(coll)</p>
<p>        End Function</p>
<p>        Protected Overrides Sub OnValidate(ByVal value As Object)</p>
<p>            MyBase.OnValidate(value)</p>
<p>            If Not TypeOf value Is Customer Then</p>
<p>                Throw New ArgumentException(&#8221;Collection only supports Customer objects.&#8221;)</p>
<p>            End If</p>
<p>        End Sub</p>
<p>        Public Enum AccessibilityEnum<br />
            [Public]</p>
<p>            [Protected]</p>
<p>            [Internal]</p>
<p>            [ProtectedInternal]</p>
<p>            [Private]<br />
        End Enum</p>
<p>        Public Function GetAccessModifier(ByVal accessibility As AccessibilityEnum) As String</p>
<p>            Select Case accessibility</p>
<p>                Case AccessibilityEnum.Public</p>
<p>                    Return &#8220;public&#8221;</p>
<p>                Case AccessibilityEnum.Protected</p>
<p>                    Return &#8220;protected&#8221;</p>
<p>                Case AccessibilityEnum.Internal</p>
<p>                    Return &#8220;internal&#8221;</p>
<p>                Case AccessibilityEnum.ProtectedInternal</p>
<p>                    Return &#8220;protected internal&#8221;</p>
<p>                Case AccessibilityEnum.Private</p>
<p>                    Return &#8220;private&#8221;</p>
<p>                Case Else</p>
<p>                    Return &#8220;public&#8221;</p>
<p>            End Select</p>
<p>        End Function<br />
#Region &#8220;ReadOnlyClass&#8221;</p>
<p>Private NonInheritable Class ReadOnlyCustomerCollection<br />
        Inherits CustomerCollection</p>
<p>        Private Const ERROR_STRING As String = &#8220;Collection is read-only.&#8221;</p>
<p>        Friend ReadOnly Sub New(ByVal value As Customer)<br />
            MyBase.New(coll)<br />
        End Sub</p>
<p>        Public Overrides Function Add(ByVal value As Customer) As Integer</p>
<p>            Throw New NotSupportedException(ERROR_STRING)</p>
<p>        End Function</p>
<p>        Public Overrides Sub Remove(ByVal value As Customer)</p>
<p>            Throw New NotSupportedException(ERROR_STRING)</p>
<p>        End Sub</p>
<p>        Protected Overrides Sub OnClear()</p>
<p>            Throw New NotSupportedException(ERROR_STRING)</p>
<p>        End Sub</p>
<p>        Protected Overrides Sub OnInsert(ByVal index As Integer, ByVal value As Object)</p>
<p>            Throw New NotSupportedException(ERROR_STRING)</p>
<p>        End Sub</p>
<p>        Protected Overrides Sub OnRemove(ByVal index As Integer, ByVal value As Object)</p>
<p>            Throw New NotSupportedException(ERROR_STRING)</p>
<p>        End Sub</p>
<p>        Protected Overrides Sub OnSet(ByVal index As Integer, ByVal oldValue As Object, ByVal NewValue As Object)</p>
<p>            Throw New NotSupportedException(ERROR_STRING)</p>
<p>        End Sub</p>
<p>    End Class</p>
<p>#end Region</p>
<p>End Class</p>
<p>End Namespace</p>
]]></content:encoded>
	</item>
</channel>
</rss>
