![]() |
Languages »
VB.NET »
Visual Basic .NET
Beginner
License: The Code Project Open License (CPOL)
PropertyBag in VB .NETBy kiruba kumaresh RThis article gives an overview of the propertybag class implemented in VB.NET. |
VB, Windows, .NET (.NET 2.0), Dev
|
|
Advanced Search |
|
|
|
||||||||||||||||
This article gives an overview of the propertybag class implemented in VB.NET.
Basically Propertybag is a virtual container which can hold any type of data and can be used to persist objects between instances. This class simulates the behaviour of propertybag supported in VB 6.0.
The PropertyBag class exposes the following methods/properties which can be used to add/access the objects in it.
Public Sub WriteProperty(ByVal szobjDesc As String, ByVal objValue As Object)
szObjDesc: Description of the objectobjValue: Object Writes the given object to the bag with the specified description.
Public Function ReadProperty(ByVal szobjDesc As String, _
Optional ByVal ObjDefValue As Object = Nothing) As Object
szObjDesc: Description of the objectObjDefValue: Default value to be returned if the object was not found in the bag. Defaults to nothing if not specified.Returns the specified object from the bag. If the object is not found, default value specified in the method call will be returned.
Public Property Contents()
Gets or sets the Contents of the bag.
Get: Returns the Contents of the bag as a byte array (in binary serialized format) Set: Sets the Contents of the bag with the given byte array Public Sub Clear()
Clears the contents of the bag.
Here are the steps to be followed to access the PropertyBag in your application:
PropertyBag Assembly in your application. The PropertyBag class becomes visible now.Dim pbag as New PropertyBag()
contents property. pbag.WriteProperty("iInputNum",1)
Dim iValue as integer
iValue = pbag.ReadProperty("iInputNum")
Propertybag across processes, serialize it to binary format and send the data:Dim bytearr() as byte
bytearr= pbag.Contents
RemoteSub(bytearr)
// RemoteSub which runs in separate process
Public sub RemoteSub(bytearr() as byte)
Dim pbag as New Propertybag
Dim iValue as integer
pbag.contents = bytearr
iValue = pbag.ReadProperty("iInputNum")
........
End Sub
| You must Sign In to use this message board. | ||||||||
|
||||||||
|
||||||||
|
||||||||
|
||||||||
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 11 Jan 2008 Editor: Deeksha Shenoy |
Copyright 2008 by kiruba kumaresh R Everything else Copyright © CodeProject, 1999-2009 Web09 | Advertise on the Code Project |