Eugene
Who is making the called method?
If you don't want to do that , than just don't do it
Just my thought,
Cor
mmm... so David, is there no way to get such a restriction? any workaround?
Is this standard across all .net supported languages?
Anyone know if MS would add in the const parameter support for VB in the
future?
That's not supported, except for value type parameters where a copy of the
original object is generated if the value is passed by value.
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
One possibility for a workaround is to create an immutable verssion of
obj1's class and pass that through to MethodB
' Your obj1 class containing read/write properties
Public Class Foo
Public Property Bar() As String
Get
Return _bar
End Get
Set(ByVal Value As String)
_bar = Value
End Set
End Property
Private _bar As String
End Class
' An immutable version of Foo with read-only versions of the properties
Public Class FooImm
Public Sub New( _
ByVal foo As Foo _
)
_foo = foo
End Sub
Public ReadOnly Property Bar() As String
Get
Return _foo.Bar
End Get
End Property
Private _foo As Foo
End Class
NOTE: This can also be done by inheriting from Foo and Shadowing the
properties as readonly.
<in methodA>
...
MethodB(new FooImm(foo))
...
Private sub MethodB ( fooImm as FooImm )
<< has readonly access to all the properties in foo but cannot
update them >>
end sub
It is not a full replacement for const parameters and in many cases
cannot be used (e.g. where the object passed to MethodB must be of type
Foo) but can help in some situations.
hth,
Alan.
Two choices.
Use Interfaces to define what the Developer is allowed to do
- and make all the properties on this [particular] Interface ReadOnly.
This is probably the safest approach.
Have your class provide a "data-only" version of itself, via a
property, something like
Public Class BigClass
' Here's an updatable property that we don't want tampered with
Public Property Thingy() as Integer
Get
Return m_iThingy
End Get
Set( Value as Integer )
m_iThingy = Value
End Set
End Property
Private m_iThingy as Integer = -1
' Property to get hold of the "safe" Data Class
Public ReadOnly Property ViewData() as DataClass
Return New DataClass( Me )
End Property
' The Data class that others should be reading
Public Class DataClass
Friend Sub New( ByVal oaParent as BigClass )
m_oParent = oaParent
End Sub
' ReadOnly version of the previously updatable property
Public ReadOnly Property Thingy() As Integer
Get
Return m_oParent.Thingy
End Get
End Property
Private m_oParent as BigClass = Nothing
End Class
End Class
then, Developers should only ever write functions that use the Data Class.
HTH,
Phill W.
This construction bellow (if the method is made by others) can change the
value of an object and Eugene asks a solution for that
\\\
dim mydataset as new dataset
external.foreignprocedure(mydataset)
///
The foreignprocedure is
\\\
Private Sub foreignprocedure(byval ds as dataset)
dim dt as table
ds.tables.add(dt) 'or whatever
End Sub
///
He has not made this class, he is using it and can not protect his object
even not by copying it if that is not serializable.
And because it is hidden and don't know what the foreignprocedure does he
has a problem.
Cor
"Phill. W" <P.A.Ward@o-p-e-n-.-a-c-.-u-k> schreef in bericht
news:dfkbs4$t23$1...@yarrow.open.ac.uk...
Others have mentioned the workarounds, wrap your data in a readonly
object or interface, or copy it before you hand it off.
> Is this standard across all .net supported languages?
AFAIK, yes.
> Anyone know if MS would add in the const parameter support for VB in the
> future?
Pretty unlikely. Anders Hejlberg, the C#/CLR architect, seems pretty
opposed to it.