Reputation: 48476
I have an object with several methods. Some of which are decorated with a [AuthenticationRequired]
attribute. When, and how, should I be checking whether the callee is authenticated?
This is just a simple null
check, but I don't know how to hook it to the actual method calls. I'm kind of lost here.
Do I:
The class structure is roughly:
public class Stuff
{
public void ImFine()
{
CommonMethod("fine");
}
public void ImGood()
{
CommonMethod("good");
}
[AuthenticationRequired]
public void ImTerrible()
{
CommonMethod("terrible", true); // not an optional parameter.
}
[AuthenticationRequired]
public void ImDeceased()
{
CommonMethod("dead");
}
protected void CommonMethod(string state)
{
Console.WriteLine(string.Format("I feel {0}", state));
}
protected void CommonMethod(string state, bool pet)
{
if (pet)
{
Console.WriteLine(string.Format("My pet feels {0}", state));
}
else
{
Console.WriteLine(string.Format("I feel {0}", state));
}
}
}
Assume CommonMethod
is barely more complex and one can't invoke the other (in order to have one method shared by every callee).
Upvotes: 0
Views: 300