472,784 Members | 796 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,784 software developers and data experts.

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
2 1195
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: zorro | last post by:
Hello, I'm programming an Amazon type web site and find myself "wasting" a lot of time writing code that gets information from include files rather than from the database because I have this...
0
by: zorro | last post by:
Thanks all for your suggestions. I'm definitely scrapping my method for now. I liked the following idea most but I'll probably go with the db method because it's probably easiest to manage. ;)...
22
by: Martin MOKREJ© | last post by:
Hi, I'm looking for some easy way to do something like include in c or PHP. Imagine I would like to have: cat somefile.py a = 222 b = 111 c = 9
5
by: Kenneth | last post by:
Can anyone explain me why it is neccesary to include SqlDbType to the SqlParameter. In every example I see, it is done, but no one explaines why. I have for example a date I want to save into my...
7
by: mescaline | last post by:
Hi, Suppose a_file.cpp contains a function a_function() Now to include it in main_file.cpp I just do #include "a_file.cpp" and I'm all set. i recently came across this seemingly roundabout...
0
by: Patrick Kearney | last post by:
Hi All, I have seen this type of question raised in various groups but no one has supplied a definitive answer. I am trying to load a dataset schema that has an xs:include. Project policy is to...
2
by: Garry Freemyer | last post by:
I wrote a screensaver, via Visual Studio 2003 in C# and I decided a wiser choice for me was to use an xml file to save my configs. Btw: I wonder if this is why every bit of documentation I've found...
5
by: David Mathog | last post by:
One thing that can make porting C code from one platform to another miserable is #include. In particular, the need to either place the path to an included file within the #include statement or to...
6
by: Dmitri Shvetsov | last post by:
Hi All, Does somebody know how can I include an external file into my C# source file? I need to insert the same strings (about 5-10) into about 75 different files, probably I will need to...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.