473,499 Members | 1,573 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3564
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
1323
by: Simon | last post by:
Hi all, What is the equivalent code of the following in C#? ********************************************************** Public ReadOnly Property EditURL(ByVal strKeyName As String, ByVal...
3
3412
by: Marina | last post by:
Hi, I have a class that inherits from CollectionBase, and I'm trying to override its Count property. As per the documentation, this property is overridable - so I should be able to do this. So...
0
421
by: besaar | last post by:
i got the current project that got the serial no.of a hard disk for software protection but i got an error,if u solve it send me,thanx alllllll. 1.file1 Option Strict On Option Explicit On...
2
5715
by: Schorschi | last post by:
Can't seemd to get ReadFile API to work! Returns invalid handle error? =========================================================================== Ok, the visual basic gurus, help! The...
8
1394
by: Able | last post by:
Dear friends In a class I have this property: Private mstr_FirstName As String Public Property FirstName() As String Get
1
1030
by: Nick Hall | last post by:
I'm getting what I think is a bug in the way the VB compiler determines the correct overloaded method to call. I have written a class to wrap System.Configuaration.ConfigurationSettings with some...
3
2746
by: Philip Wagenaar | last post by:
I created a Mustinherit class with two must override readonly properties: Public MustInherit Class RequestPart Public MustOverride ReadOnly Property Description() As Boolean Public MustOverride...
14
2355
by: Rich | last post by:
Yes, I need to store some values in an array type collection object that can hold 3 or more parameters per index. I have looked at the collection object, hashtable object and would prefer not to...
11
3942
by: Andrus | last post by:
I'm implementing entity object which should populate its properties from database when property is first referenced. In RDL reports I use object properties like MyObject.MyProperty MyObject...
0
7007
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7220
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6893
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7386
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4918
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4599
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3098
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3090
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
664
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.