"hansiman" <ha***@hotmail.com> wrote in message
news:60********************************@4ax.com...
Just beginning using FxCop in my asp.net projects...
I get a lot of error messages under the header: AvoidUnusedParameters
for funtions and routines lik:
Sub isUserAuthenticated(ByVal blnLoggedIn As Boolean)
If Not (blnLoggedIn) Then
System.Web.HttpContext.Current.Response.Redirect(p cPageLogin)
End If
End Sub
Where the suggested resolution is:
"The 'this' parameter (or 'Me' in VB) of UtilsAdmin.
isUserAuthenticated(Boolean):Void is never used. Mark
the method as static (or Shared in VB) or use 'this'/Me
in the method body."
I don't get it? How do I use 'this'?
FxCop is complaining that you do _not_ use Me.
For instance, if your Sub had said
If Not (blnLoggedIn) Then
Response.Redirect(pcPageLogin)
End If
Then it would not have complained, because "Response" is actually
"Me.Response". By Using HttpContext.Current.Response, you're going out of
your way to avoid using Me.Response.
(Why, by the way? Was that line transported from elsewhere?)
At any rate, the other way to meet FxCop's suggestion would be to declare
the sub as
Shared Sub isUserAuthenticated(ByVal blnLoggedIn As Boolean)
John Saunders
P.S. I don't know if FxCop will complain about it, but as long as we're
nitpicking, I'm going to complain about your choice of method name. A method
named Is<something> should be a Function returning Boolean, and should test
to see if the current instance is <something>, or if the supplied parameter
is <something>. An example would be IsBlank or IsNull or IsNumeric. From the
looks of things, you already know whether your user is authenticated, and
you're just looking to _do_ something with that knowledge.
I'd call the method MaybeRedirect or RedirectIfAuthenticated.