469,929 Members | 1,597 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,929 developers. It's quick & easy.

Why can't a writeonly property overload a readonly property?

Just a silly question, but why can't you overload a writeonly property with
a readonly one? Surely the compiler can tell the difference of which one to
call at compile time, depending on if it is an assignment or a get?

I know there isn't much point to this anyway, but until Properties with
different scope for Get and Set methods are brought back (as asked by George
in a previous post about "properties with different scope", it would have
been nice to do the following:

--------------------------

Private mName As String
Public ReadOnly Property Name() As String
Get
Return mName
End Get
End Property
Protected Friend WriteOnly Property Name() As String
Set(ByVal Value As String)
mName = Value
End Set
End Property

--------------------

Saying that, it would be nicer to do this (as George and numerous others
mentioned):

-----------------------------
Private mName As String
Public Property Name() As String
Public Get
Return mName
End Get
Protected Friend Set(ByVal Value As String)
mName = Value
End Set
End Property
----------------------------
Nov 20 '05 #1
14 3416
Hi,

At the PDC they showed the new syntax:

Private mName As String
Public Property Name() As String
Get
Return mName
End Get
Protected Friend Set(ByVal Value As String)
mName = Value
End Set
End Property
----------------------------

Note: you declare the property with the most permissible modifier, then
apply the more restrictive modifier to the Set or Get, such as Private ot
Protected etc.


"Codemonkey" <hu*********@hotmail.com> wrote in message
news:ee**************@TK2MSFTNGP09.phx.gbl...
Just a silly question, but why can't you overload a writeonly property with a readonly one? Surely the compiler can tell the difference of which one to call at compile time, depending on if it is an assignment or a get?

I know there isn't much point to this anyway, but until Properties with
different scope for Get and Set methods are brought back (as asked by George in a previous post about "properties with different scope", it would have
been nice to do the following:

--------------------------

Private mName As String
Public ReadOnly Property Name() As String
Get
Return mName
End Get
End Property
Protected Friend WriteOnly Property Name() As String
Set(ByVal Value As String)
mName = Value
End Set
End Property

--------------------

Saying that, it would be nicer to do this (as George and numerous others
mentioned):

-----------------------------
Private mName As String
Public Property Name() As String
Public Get
Return mName
End Get
Protected Friend Set(ByVal Value As String)
mName = Value
End Set
End Property
----------------------------

Nov 20 '05 #2
I can see how this could be useful actually and its a shame it doesent work.

I can only assume that due to the way the compiler is designed internally
that this would have caused complications for Microsoft which were too much
to overcome. Alternatively, maybe they simply didnt think of it ?

Who knows!, perhaps you should suggest it to them

Regards - OHM#
Codemonkey wrote:
Just a silly question, but why can't you overload a writeonly
property with a readonly one? Surely the compiler can tell the
difference of which one to call at compile time, depending on if it
is an assignment or a get?

I know there isn't much point to this anyway, but until Properties
with different scope for Get and Set methods are brought back (as
asked by George in a previous post about "properties with different
scope", it would have been nice to do the following:

--------------------------

Private mName As String
Public ReadOnly Property Name() As String
Get
Return mName
End Get
End Property
Protected Friend WriteOnly Property Name() As String
Set(ByVal Value As String)
mName = Value
End Set
End Property

--------------------

Saying that, it would be nicer to do this (as George and numerous
others mentioned):

-----------------------------
Private mName As String
Public Property Name() As String
Public Get
Return mName
End Get
Protected Friend Set(ByVal Value As String)
mName = Value
End Set
End Property
----------------------------


Regards - OHM# On**********@BTInternet.com
Nov 20 '05 #3
By new you mean Whidbey ?

regards - OHM#

Bill McCarthy wrote:
Hi,

At the PDC they showed the new syntax:

Private mName As String
Public Property Name() As String
Get
Return mName
End Get
Protected Friend Set(ByVal Value As String)
mName = Value
End Set
End Property
----------------------------

Note: you declare the property with the most permissible modifier,
then apply the more restrictive modifier to the Set or Get, such as
Private ot Protected etc.


"Codemonkey" <hu*********@hotmail.com> wrote in message
news:ee**************@TK2MSFTNGP09.phx.gbl...
Just a silly question, but why can't you overload a writeonly
property with a readonly one? Surely the compiler can tell the
difference of which one to call at compile time, depending on if it
is an assignment or a get?

I know there isn't much point to this anyway, but until Properties
with different scope for Get and Set methods are brought back (as
asked by George in a previous post about "properties with different
scope", it would have been nice to do the following:

--------------------------

Private mName As String
Public ReadOnly Property Name() As String
Get
Return mName
End Get
End Property
Protected Friend WriteOnly Property Name() As String
Set(ByVal Value As String)
mName = Value
End Set
End Property

--------------------

Saying that, it would be nicer to do this (as George and numerous
others mentioned):

-----------------------------
Private mName As String
Public Property Name() As String
Public Get
Return mName
End Get
Protected Friend Set(ByVal Value As String)
mName = Value
End Set
End Property
----------------------------


Regards - OHM# On**********@BTInternet.com
Nov 20 '05 #4
Cor
Hi Codemonkey,

I sometimes get the idea that people want to use C with VB.
I am thinking than always: "when those things are so important, why don't
those people switch to C?

What I find crazy is that I cannot simple write

Set
mName = Value
End Set

And when I want to use another value

Set (AnotherValue)
mName = AnotherValue
End Set

I write this, to give a contra opinion about this in this newsgroup, not
that I find it really important.

Cor
Nov 20 '05 #5
Even better. Cheers Bill.
"Bill McCarthy" <bi******@i.primus.com.au> wrote in message
news:On**************@TK2MSFTNGP11.phx.gbl...
Hi,

At the PDC they showed the new syntax:

Private mName As String
Public Property Name() As String
Get
Return mName
End Get
Protected Friend Set(ByVal Value As String)
mName = Value
End Set
End Property
----------------------------

Note: you declare the property with the most permissible modifier, then
apply the more restrictive modifier to the Set or Get, such as Private ot
Protected etc.


"Codemonkey" <hu*********@hotmail.com> wrote in message
news:ee**************@TK2MSFTNGP09.phx.gbl...
Just a silly question, but why can't you overload a writeonly property

with
a readonly one? Surely the compiler can tell the difference of which one

to
call at compile time, depending on if it is an assignment or a get?

I know there isn't much point to this anyway, but until Properties with
different scope for Get and Set methods are brought back (as asked by

George
in a previous post about "properties with different scope", it would have been nice to do the following:

--------------------------

Private mName As String
Public ReadOnly Property Name() As String
Get
Return mName
End Get
End Property
Protected Friend WriteOnly Property Name() As String
Set(ByVal Value As String)
mName = Value
End Set
End Property

--------------------

Saying that, it would be nicer to do this (as George and numerous others
mentioned):

-----------------------------
Private mName As String
Public Property Name() As String
Public Get
Return mName
End Get
Protected Friend Set(ByVal Value As String)
mName = Value
End Set
End Property
----------------------------


Nov 20 '05 #6
Who knows!, perhaps you should suggest it to them
No point. Properties with different scope are gonna be in the next version
as Bill mentioned anyway. Aside from Properties, I can't really see there
being any need for overloading Fields with different scope modifiers.

"One Handed Man [ OHM# ]" <On**********@BTInternet.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl... I can see how this could be useful actually and its a shame it doesent work.
I can only assume that due to the way the compiler is designed internally
that this would have caused complications for Microsoft which were too much to overcome. Alternatively, maybe they simply didnt think of it ?

Who knows!, perhaps you should suggest it to them

Regards - OHM#
Codemonkey wrote:
Just a silly question, but why can't you overload a writeonly
property with a readonly one? Surely the compiler can tell the
difference of which one to call at compile time, depending on if it
is an assignment or a get?

I know there isn't much point to this anyway, but until Properties
with different scope for Get and Set methods are brought back (as
asked by George in a previous post about "properties with different
scope", it would have been nice to do the following:

--------------------------

Private mName As String
Public ReadOnly Property Name() As String
Get
Return mName
End Get
End Property
Protected Friend WriteOnly Property Name() As String
Set(ByVal Value As String)
mName = Value
End Set
End Property

--------------------

Saying that, it would be nicer to do this (as George and numerous
others mentioned):

-----------------------------
Private mName As String
Public Property Name() As String
Public Get
Return mName
End Get
Protected Friend Set(ByVal Value As String)
mName = Value
End Set
End Property
----------------------------


Regards - OHM# On**********@BTInternet.com

Nov 20 '05 #7
> when those things are so important, why don't
those people switch to C?
I have switched to C# in the past for some things, but what's wrong with
trying to improve VB?
What I find crazy is that I cannot simple write

Set
mName = Value
End Set
That doesn't really bother me as the IDE puts in the syntax automatically
when I press return after typing in the first line of the Property. Jeeze,
I'm lazy ;)

Trev.

"Cor" <no*@non.com> wrote in message
news:eA**************@tk2msftngp13.phx.gbl... Hi Codemonkey,

I sometimes get the idea that people want to use C with VB.
I am thinking than always: "when those things are so important, why don't
those people switch to C?

What I find crazy is that I cannot simple write

Set
mName = Value
End Set

And when I want to use another value

Set (AnotherValue)
mName = AnotherValue
End Set

I write this, to give a contra opinion about this in this newsgroup, not
that I find it really important.

Cor

Nov 20 '05 #8
"Codemonkey" <hu*********@hotmail.com> schrieb
Just a silly question, but why can't you overload a writeonly
property with a readonly one? Surely the compiler can tell the
difference of which one to call at compile time, depending on if it
is an assignment or a get?

I know there isn't much point to this anyway, but until Properties
with different scope for Get and Set methods are brought back (as
asked by George in a previous post about "properties with different
scope", it would have been nice to do the following:


It is a contradiction that a property is readonly *and* writeonly. If you
can only read, you can not write or even write only.
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #9
I understand this, I was making the point about using this to get around the
problem of having different scope for proeprty set and property let (Public
Readlonly Get, Protected Writeonly Set etc.)

It's supposedly gonna be included in the next version, so no matter.

Trev.

"Armin Zingler" <az*******@freenet.de> wrote in message
news:uW**************@tk2msftngp13.phx.gbl...
"Codemonkey" <hu*********@hotmail.com> schrieb
Just a silly question, but why can't you overload a writeonly
property with a readonly one? Surely the compiler can tell the
difference of which one to call at compile time, depending on if it
is an assignment or a get?

I know there isn't much point to this anyway, but until Properties
with different scope for Get and Set methods are brought back (as
asked by George in a previous post about "properties with different
scope", it would have been nice to do the following:


It is a contradiction that a property is readonly *and* writeonly. If you
can only read, you can not write or even write only.
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #10
Cor
Hi Codemonkey,

I am also a kind of lazy when it is about simple things and I said that it
did not botter me either.
Set
mName = Value
End Set

But when this becomes complex the IDE cannot do it automaticly anymore for
me I think,

Just a thought

Cor
Nov 20 '05 #11
yes.

"One Handed Man [ OHM# ]" <On**********@BTInternet.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
By new you mean Whidbey ?

regards - OHM#

Bill McCarthy wrote:
Hi,

At the PDC they showed the new syntax:

Private mName As String
Public Property Name() As String
Get
Return mName
End Get
Protected Friend Set(ByVal Value As String)
mName = Value
End Set
End Property
----------------------------

Note: you declare the property with the most permissible modifier,
then apply the more restrictive modifier to the Set or Get, such as
Private ot Protected etc.


"Codemonkey" <hu*********@hotmail.com> wrote in message
news:ee**************@TK2MSFTNGP09.phx.gbl...
Just a silly question, but why can't you overload a writeonly
property with a readonly one? Surely the compiler can tell the
difference of which one to call at compile time, depending on if it
is an assignment or a get?

I know there isn't much point to this anyway, but until Properties
with different scope for Get and Set methods are brought back (as
asked by George in a previous post about "properties with different
scope", it would have been nice to do the following:

--------------------------

Private mName As String
Public ReadOnly Property Name() As String
Get
Return mName
End Get
End Property
Protected Friend WriteOnly Property Name() As String
Set(ByVal Value As String)
mName = Value
End Set
End Property

--------------------

Saying that, it would be nicer to do this (as George and numerous
others mentioned):

-----------------------------
Private mName As String
Public Property Name() As String
Public Get
Return mName
End Get
Protected Friend Set(ByVal Value As String)
mName = Value
End Set
End Property
----------------------------


Regards - OHM# On**********@BTInternet.com

Nov 20 '05 #12
On Thu, 11 Dec 2003 09:57:16 -0000, Codemonkey wrote:
Just a silly question, but why can't you overload a writeonly property with
a readonly one? Surely the compiler can tell the difference of which one to


If you wrote a class and set a particular property to ReadOnly because you
wanted to protect the property from unauthorized modification, if a user of
your class can inherit your class and override the protection, that defeats
the purpose of protecting it in the first place.

And what about private fields?

If a user of a class can inherit and override a private field, we may as
well only have public fields and properties and forget protections.

As pointed out by other posters, however, Whidbey has new syntax to allow
separate protections on the Get and Set portions of a property.

--
Chris

To send me an E-mail, remove the underscores and lunchmeat from my E-Mail
address.
Nov 20 '05 #13
Hi,
I understand this, I was making the point about using this to get around theproblem of having different scope for proeprty set and property let (Public
Readlonly Get, Protected Writeonly Set etc.)


If this works then the class's inherit class can inherit its Public and
protected property, so the inherit class will use the Mybase.PropertyName
to get the value, that is to say, the inherit class will read and write the
property.

If you have any concern on this issue, please post here.

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 20 '05 #14
Thanks for the reply, Peter.

I'm not really bothered by this limitation. It was more of a "wondering"
than a question. As others have mentioned, properties with different scope
for the get and set will be in the next version, so I guess I can wait until
then ;)

Thanks again,

Trev.

"Peter Huang" <v-******@online.microsoft.com> wrote in message
news:qp****************@cpmsftngxa07.phx.gbl...
Hi,
I understand this, I was making the point about using this to get around the
problem of having different scope for proeprty set and property let (PublicReadlonly Get, Protected Writeonly Set etc.)


If this works then the class's inherit class can inherit its Public and
protected property, so the inherit class will use the Mybase.PropertyName
to get the value, that is to say, the inherit class will read and write

the property.

If you have any concern on this issue, please post here.

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 20 '05 #15

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Simon | last post: by
8 posts views Thread by Able | last post: by
1 post views Thread by Nick Hall | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.