|
-
May 7th, 2004, 02:15 PM
#1
Thread Starter
Frenzied Member
How to save this object to file
Im my endeavour to create an object framework for a project, I have come to the conclusion that I need to add a "savefile" method to my CDocumentCollection class
This is a simple class.. it inherits collectionbase and contains an array with simple CDocument objects.
I want to do something like this
VB Code:
dim mycollection as new CDocumentCollection
mycollection.add(new CDocument("Doc1"))
mycollection.add(new CDocument("Doc3"))
mycollection.add(new CDocument("Doc14"))
mycollection.add(new CDocument("Doc156"))
mycollection.SaveToFile("c:\myfile.gps")
Is there an easy way to save the object hieararchy to binary file and an easy way to load it the same way? Im sure there are many programs in vb.net /C# that perform this simple thing... I just want to learn the "right" way to do it...
VB Code:
dim mycollection as new CDocumentCollection
mycollection = mycollection.LoadFromFile("c:\myfile.gps")
I have very little experience in these things, are there any patterns or rules to follow to make this a good design? I know a little about serialization... I have read it is a good way to save/load binary config files... can this help me? How do I proceed?
kind regards
Henrik
-
May 7th, 2004, 03:31 PM
#2
Tips:
- Google is your friend! Search before posting!
- Name your thread appropriately... "I Need Help" doesn't cut it!
- Always post your code!!!! We can't read your mind!!! (well, at least most of us!)
- Allways Include the Name and Line of the Exception (if one is occuring!)
- If it is relevant state the version of Visual Studio/.Net Framwork you are using (2002/2003/2005)
If you think I was helpful, rate my post  IRC Contact: Rizon/xous ChakraNET/xous Freenode/xous
-
May 10th, 2004, 12:37 AM
#3
Thread Starter
Frenzied Member
Great idea... however I get this error when trying to do just that
You must implement a default accessor on EasyPrinting.EasyPrinting.CDocumentCollection because it inherits from ICollection.
here is my class
VB Code:
public Class CDocumentCollection : Inherits CollectionBase
Public Sub Add(ByVal item As CDocument)
Me.List.Add(item)
End Sub
Public ReadOnly Property Item(ByVal index As Integer) As CDocument
Get
Return DirectCast(Me.List.Item(index), CDocument)
End Get
End Property
Public WriteOnly Property Item(ByVal index As Integer, ByVal Document As CDocument) As CDocument
Set(ByVal Value As CDocument)
Me.List.Item(index) = Document
End Set
End Property
End Class
Serializing is one of the areas of .net Im not so familiar with 
kind regards
Henrik
-
May 10th, 2004, 01:12 AM
#4
Make sure that class has a default constructor (one with no parameters).
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|