473,396 Members | 1,966 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 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 1215
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.