473,394 Members | 1,073 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Serializing custom component with a strongly typed collection property

I make a similar post in another newsgroup, but this example is
simplified somewhat.

I have a component (cmpMyComponent) with 2 properties. The 1st property
is a string value (Description) and the 2nd property is a strongly typed
collection class (myCollectionProperty).

The collection contains a simple class (myCustomClass) which has 1 text
property (TextProperty).

Editing the properties for the component in the windows forms designer
works fine, but compiling the application causes the collection property
to lose its values. I assume this is because the component's collection
property isn't being serialized to the the myForm.resx file
automatically.

I've tried setting a <serializable> attribute on the component, as well
as the
<DesignerSerializationVisibility(DesignerSerializa tionVisibility.Content
)> attribute on the collection property in the component.

Below is the sample project code. Help is greatly appreciated.

'// THIS IS THE COMPONENT

Public Class myComponent
Inherits System.ComponentModel.Component
Private m_strDescription As String
Private m_myCollectionProperty As myCustomClassCollection

#Region " Component Designer generated code "
Public Sub New(ByVal Container As System.ComponentModel.IContainer)
MyClass.New()
'Required for Windows.Forms Class Composition Designer support
Container.Add(Me)
End Sub

Public Sub New()
MyBase.New()
'This call is required by the Component Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Component overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As
Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Component Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Component Designer
'It can be modified using the Component Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
components = New System.ComponentModel.Container
End Sub
#End Region
<DesignerSerializationVisibility(DesignerSerializa tionVisibility.Content
)> _
Public Property myCollectionProperty() As
myCustomClassCollection
Get
Return m_myCollectionProperty
End Get
Set(ByVal Value As myCustomClassCollection)
m_myCollectionProperty = Value
End Set
End Property

Public Property Description() As String
Get
Return m_strDescription
End Get
Set(ByVal Value As String)
m_strDescription = Value
End Set
End Property

End Class


'// THIS IS THE COLLECTION AND CUSTOM CLASS

<Serializable()> _
Public Class myCustomClassCollection
Inherits System.Collections.CollectionBase

Public Sub New()
MyBase.New()
End Sub

Public Sub New(ByVal myCValue As myCustomClassCollection)
MyBase.New()
Me.AddRange(myCValue)
End Sub

Public Sub New(ByVal myCValue() As myCustomClass)
MyBase.New()
Me.AddRange(myCValue)
End Sub

Default Public Property Item(ByVal intIndex As Integer) As
myCustomClass
Get
Return CType(List(intIndex), myCustomClass)
End Get
Set(ByVal Value As myCustomClass)
List(intIndex) = value
End Set
End Property

Public Function Add(ByVal myCValue As myCustomClass) As Integer
Return List.Add(myCValue)
End Function

Public Overloads Sub AddRange(ByVal myCValue() As myCustomClass)
Dim intCounter As Integer = 0
Do While (intCounter < myCValue.Length)
Me.Add(myCValue(intCounter))
intCounter = (intCounter + 1)
Loop
End Sub

Public Overloads Sub AddRange(ByVal myCValue As
myCustomClassCollection)
Dim intCounter As Integer = 0
Do While (intCounter < myCValue.Count)
Me.Add(myCValue(intCounter))
intCounter = (intCounter + 1)
Loop
End Sub

Public Function Contains(ByVal myCValue As myCustomClass) As Boolean
Return List.Contains(myCValue)
End Function

Public Sub CopyTo(ByVal myCArray() As myCustomClass, ByVal intIndex
As Integer)
List.CopyTo(myCArray, intIndex)
End Sub

Public Function IndexOf(ByVal myCValue As myCustomClass) As Integer
Return List.IndexOf(myCValue)
End Function

Public Sub Insert(ByVal intIndex As Integer, ByVal myCValue As
myCustomClass)
List.Insert(intIndex, myCValue)
End Sub

Public Shadows Function GetEnumerator() As myCustomClassEnumerator
Return New myCustomClassEnumerator(Me)
End Function

Public Sub Remove(ByVal myCValue As myCustomClass)
List.Remove(myCValue)
End Sub
End Class

Public Class myCustomClassEnumerator
Inherits Object
Implements System.Collections.IEnumerator

Private iEnBase As System.Collections.IEnumerator

Private iEnLocal As System.Collections.IEnumerable

Public Sub New(ByVal myCMappings As myCustomClassCollection)
MyBase.New()
Me.iEnLocal = CType(myCMappings, System.Collections.IEnumerable)
Me.iEnBase = iEnLocal.GetEnumerator
End Sub

Public ReadOnly Property Current() As myCustomClass
Get
Return CType(iEnBase.Current, myCustomClass)
End Get
End Property

ReadOnly Property System_Collections_IEnumerator_Current() As Object
Implements System.Collections.IEnumerator.Current
Get
Return iEnBase.Current
End Get
End Property

Public Function MoveNext() As Boolean
Return iEnBase.MoveNext
End Function

Function System_Collections_IEnumerator_MoveNext() As Boolean
Implements System.Collections.IEnumerator.MoveNext
Return iEnBase.MoveNext
End Function

Public Sub Reset()
iEnBase.Reset()
End Sub

Sub System_Collections_IEnumerator_Reset() Implements
System.Collections.IEnumerator.Reset
iEnBase.Reset()
End Sub
End Class

Public Class myCustomClass

Private m_strTextProperty As String

Public Property TextProperty() As String
Get
Return m_strTextProperty
End Get
Set(ByVal Value As String)
m_strTextProperty = Value
End Set
End Property

End Class

================
Jordan Bowness
================

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #1
0 1407

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: jamie_m_ | last post by:
I have a custom collection ... clFile that INHERITS from NameObjectCollectionBase the problem is, when I try to create an xmlserializer instance i get an error You must implement a default...
1
by: Carl Gilbert | last post by:
Hi I am trying to serialize a collection of GUIDs by overriding the serialize function on a diagram component I am using. The following code sucessfully serializes a single GUID: Public...
1
by: womber | last post by:
I am getting XML from a dataset that has been populated via a storedprocedure no schemas have been applied nor any relationships. But the correct table names have been given to match the table(s)...
1
by: Derrick | last post by:
Hello all; I have created a custom component, whose properties (let's call them myObjectA and an collection of myObjectB) I'm trying to set via a GUI. I have the GUI running after the user...
2
by: Mark | last post by:
Assume you have a strongly typed collection of a class called Person. The strongly typed collection implements IEnumerable so it can be databound to a server control like a DataGrid. The Person...
2
by: AMDRIT | last post by:
Hello everyone, I have created a custom component and one of its properties is a class object with it's own properties. During runtime, I can assign values to the class object properties just...
2
by: Eamon Millman | last post by:
Greetings, I'm fairly new to the new ASP.NET 2.0 controls and I'm trying to get the TreeView control to display some non-xml/sitemap data I want to have in a tree format. To accomplish this...
5
by: Simon | last post by:
Hi all, I am writing a windows application using vb.net on the 1.1 framework. We have in the application, some strongly typed collections that have been written as classes that do not inherit...
5
by: Simon Woods | last post by:
Hi Does anyone know if there any dotnet software out there which converts a dataset into a collection of custom objects, programmatically i.e. actually creates the class structure and collection...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.