Miben,
|I need to set a variable returned by a readonly property in a class by
| another class. So the only way to set that value is from a specific
| class and function.
You can use a Friend method/member, as long as both types are within a
single Assembly (executable or Class Library). Types outside that Assembly
will not be able to directly access the Friend member. However any type
within the first Assembly will have direct access to the Friend member.
In VB 2002 & 2003 I normally create a SetValue method for the Value
property, something like:
| Public Class ToBeSet
| Private m_sValue As String
|
| Public ReadOnly Property Value As String
Get
| Return m_sValue
End Get
| End Property
Friend Sub SetValue(value As String)
m_sValue = value
End Sub
| End Class
In VB 2005 you can simply define the Property Setter as a different access
level:
| Public Class ToBeSet
| Private m_sValue As String
|
| Public Property Value As String
Get
| Return m_sValue
End Get
Friend Set(value As String)
m_sValue = value
End Set
| End Property
| End Class
I would consider continuing to use the Sub SetValue method in VB 2005 if I
wanted or needed the property to be Readonly...
--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley -
http://www.tsbradley.net
<mi***@miben.net> wrote in message
news:11*********************@g47g2000cwa.googlegro ups.com...
|I need to set a variable returned by a readonly property in a class by
| another class. So the only way to set that value is from a specific
| class and function.
|
| Public Sub Main
| Dim setter As New GoingToSetYou
| Dim item As New ToBeSet
|
| setter.NewItem(item)
| Dim sValue As String = item.Value
| End Sub
|
| Public Class GoingToSetYou
| Public Function NewItem(item As ToBeSet)
|
| I want to set the private variable m_sValue here some how and
| keep the access of it away from others
|
| End Function
| End Class
|
| Public Class ToBeSet
| Private m_sValue As String
|
| Public ReadOnly Property Value As String
| Return m_sValue
| End Property
| End Class
|