L
lukev123
Hi,
I have a class that has many methods and is growing all the time. In
each method I do a security check to see if the caller is allowed to
call the method. I also have a try catch block in every method for
exceptions.
This seems to be a lot of code for each method, so I'd like to know if
there's a way to apply an attribute that will allow pre and post
processing on a method. Ideally it looks something like this:
public MyClass
{
private Exception ex = null;
private UserSession userSession = null
// Assume that the user session is set on instantiation of the class
[PreProcessing("DoSecurityCheck")]
[PostProcessing("CheckForExceptions")]
public MyResult GetStuff()
{
// ... Get results
return myResultInstance;
}
private void DoSecurityCheck()
{
SecurityManager.IsValidSession(this.userSession);
}
private void CheckForExceptions(Object returnValue, Exception ex) //
He he he I'm being hopeful here
{
AuditManager.LogResult(returnValue);
if(ex != null)
{
AuditManager.LogException(ex);
}
}
}
Is this sort of thing possible?
Thanks,
Luke
I have a class that has many methods and is growing all the time. In
each method I do a security check to see if the caller is allowed to
call the method. I also have a try catch block in every method for
exceptions.
This seems to be a lot of code for each method, so I'd like to know if
there's a way to apply an attribute that will allow pre and post
processing on a method. Ideally it looks something like this:
public MyClass
{
private Exception ex = null;
private UserSession userSession = null
// Assume that the user session is set on instantiation of the class
[PreProcessing("DoSecurityCheck")]
[PostProcessing("CheckForExceptions")]
public MyResult GetStuff()
{
// ... Get results
return myResultInstance;
}
private void DoSecurityCheck()
{
SecurityManager.IsValidSession(this.userSession);
}
private void CheckForExceptions(Object returnValue, Exception ex) //
He he he I'm being hopeful here
{
AuditManager.LogResult(returnValue);
if(ex != null)
{
AuditManager.LogException(ex);
}
}
}
Is this sort of thing possible?
Thanks,
Luke