Pre and post processing before a method executes

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
 

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

Top