467,144 Members | 1,138 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,144 developers. It's quick & easy.

Include code in every method

I have about 100 methods in an application I'm developing. There will be
many, many more methods added as the application grows. I need to include a
line of code at the start of every method in the project and every method
that will be added in the future. The line of code is simply

if (!bSomeVar)
return;

Basically I have to check this bool var before executing the code in the
moethods.
Is there an easy way to inhrit this line or other options?

Jan 3 '07 #1
  • viewed: 1077
Share:
2 Replies
Jake,

You could try the template method pattern.

public abstract class Abstract
{
private bool m_Flag;

public void DoSomething()
{
if (!m_Flag)
{
DoSomethingConcrete();
}
}

protected abstract void DoSomethingConcrete();
}

public class Concrete
{
protected void DoSomethingConcrete()
{
// Whatever
}
}

I'm not sure this would be feasible in your situation since there would
have to be a template method for each method signature in your
application, but it's the first thing that comes to mind. Aspect
oriented programming might help you as well.

Brian

Jake K wrote:
I have about 100 methods in an application I'm developing. There will be
many, many more methods added as the application grows. I need to include a
line of code at the start of every method in the project and every method
that will be added in the future. The line of code is simply

if (!bSomeVar)
return;

Basically I have to check this bool var before executing the code in the
moethods.
Is there an easy way to inhrit this line or other options?
Jan 3 '07 #2


"Jake K" <no*****@address.comkwrote in message
news:u4**************@TK2MSFTNGP02.phx.gbl...
>I have about 100 methods in an application I'm developing. There will be
many, many more methods added as the application grows. I need to include
a line of code at the start of every method in the project and every method
that will be added in the future. The line of code is simply

if (!bSomeVar)
return;

Basically I have to check this bool var before executing the code in the
moethods.
Is there an easy way to inhrit this line or other options?
Not sure how you could do this "easily" but what you can do is a regular
expression search and replace to find all methods or entry points in your
project/solution and replace it with itself + your 'if' statements.

HTH,
Mythran
Jan 4 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by zorro | last post: by
reply views Thread by zorro | last post: by
reply views Thread by Patrick Kearney | last post: by
5 posts views Thread by David Mathog | last post: by
6 posts views Thread by Dmitri Shvetsov | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.