Best use of SET within a Property?

R

Rob Meade

Hi all,

At work one of my colleagues wrote a set of classes that we use in a common
class library within our applications. Although I use this on a daily basis
I haven't actually looked at his source. Now - I'm writing something at
home which needs a bit of similar functionality and I'm not sure of how it
was done.

On my web pages' code behind I'm inheriting from my page base class - some
of my pages need to be secured via a login. At work we achieve this with a
line like this:

LoginRequired = True

The only way I can think that this is being achieve is that LoginRequired is
a property of the base class (in my case), and then, in the SET part of the
Property I would need to make a call to do something, for example:

Public Property LoginRequired As Boolean
Get
Return _loginRequired
End Get
Set(ByVal value As Boolean)
_loginRequired = value
CheckSession()
End Set
End Property

Does that seem like a good use of the Set part of a property? Normally I'd
only use a writeable property like the above but without the CheckSession()
function call for example.

Any advise would be appreciated - if you can think of any others way the
original "LoginRequired = True" call is being made I'm open to suggestions.

I could obviously check the source at work tomorrow but was hoping to get
somewhere with my project at home today.

Thanks in advance for any help.

Regards

Rob
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

It looks like it could work.

I think that you should only do the actual checking if the value is set
to true, and if the check wan't done already. If you set the start value
of the member variable to false, you could use that to only do the check
when value changes from false to true.

Of course that would still mean that the check is done twice if you do:

LoginRequired = True
LoginRequired = False
LoginRequired = True

but that might be acceptable, as long as it's possible to do the check
twice without causing an error. To make sure that it never is done twice
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top