473,399 Members | 2,478 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Restrict access to private members covered by property

Hello,

I have a general problem in mind. Imagine, you have a private member and its
associated property:

private int member;

public int Member
{ get return member;
set {a better code with event triggering etc.}
}

As actions are associated with the SET method, even the class's inner code
MUST CALL THE PROPERTY method ("Member"). On the other side, when accessing
the member contents, the "member" will be probably quicker.

Is there a method (probably an ATTRIBUTE) which would WARN developer of the
class code itself that he should use the "Member" instead of directly
accessing the "member"? And better, how to WARN him only when SET should be
used through "Member" while GET should warn to use directly the "member"?

I suppose, such a way may exist when you are able to implement "Obsolete"
attribute warnings.

O.
Jul 21 '05 #1
1 1499
<"Ondrej Sevecek" <ondra_at_sevecek_dt_com>> wrote:
I have a general problem in mind. Imagine, you have a private member and its
associated property:

private int member;

public int Member
{ get return member;
set {a better code with event triggering etc.}
}

As actions are associated with the SET method, even the class's inner code
MUST CALL THE PROPERTY method ("Member"). On the other side, when accessing
the member contents, the "member" will be probably quicker.

Is there a method (probably an ATTRIBUTE) which would WARN developer of the
class code itself that he should use the "Member" instead of directly
accessing the "member"? And better, how to WARN him only when SET should be
used through "Member" while GET should warn to use directly the "member"?

I suppose, such a way may exist when you are able to implement "Obsolete"
attribute warnings.


Unfortunately, there's no way of doing this at the moment. Personally
I'd prefer to be able to use something like:

public int Member
{
int member;

get { return member; }

set { ... }
}

but that won't be coming in 2.0 :(

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: CoolPint | last post by:
I read in books that nested class cannot access private members of nesting class and vice versa unless they are made friends. Somehow, my compiler is letting my nested class member functions access...
6
by: Peter Frost | last post by:
Please help I don't know if this is possible but what I would really like to do is to use On Error Goto to capture the code that is being executed when an error occurs. Any help would be much...
3
by: Chua Wen Ching | last post by:
Hi there, I had seen examples for classes, but i had no idea how to implement the same thing in struct. I am quite mix up! Which one is correct? Scenario: WForm.cs - the one that calls...
10
by: Abelardo Vacca | last post by:
Hi, The title sums up the question pretty much. I would like to access all private members of a class including the private members of its base classes.( I already have the ReflectionPermission )...
1
by: Ondrej Sevecek | last post by:
Hello, I have a general problem in mind. Imagine, you have a private member and its associated property: private int member; public int Member { get return member; set {a better code...
5
by: Lyle Fairfield | last post by:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/callnetfrcom.asp The Joy of Interoperability Sometimes a revolution in programming forces you to abandon all...
4
by: sklett | last post by:
This might be a weird one ;0) I want to lazy load some member fields in a class. I had planned on handling this in the Property for the field, think; if(field == null) // load field data. ...
10
by: Les Desser | last post by:
In article <fcebdacd-2bd8-4d07-93a8-8b69d3452f3e@s50g2000hsb.googlegroups.com>, The Frog <Mr.Frog.to.you@googlemail.comMon, 14 Apr 2008 00:45:10 writes Not sure if I quite follow that. 1....
2
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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
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...
0
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...

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.