Implement Interface in debug build only

  • Thread starter Thread starter ramhog
  • Start date Start date
R

ramhog

I have a class which implements several interfaces. One of them I
would like to have implemented only if it is a debug build. Is there
a way to do this?

Thanks.
 
Hello ramhog,

and what the problem? just use #if DEBUG preprocessor directive for this

but u cant miss implementing some interfaces, u need provide either debug
implementation or the standart one

---
WBR,
Michael Nemtsev [.NET/C# MVP] :: blog: http://spaces.live.com/laflour

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo


r> I have a class which implements several interfaces. One of them I
r> would like to have implemented only if it is a debug build. Is there
r> a way to do this?
r>
r> Thanks.
r>
 
The problem with this is that if I only want to have the interface
implmented during a debug build. If I just put the #if DEBUG...#endif
around the methods, then a release build will have errors because the
interface isn't fully implemented.

public class MyBigTestClass : IReleaseMethods, ITestMethods
{
....
}

In this example, I want to only have the ITestMethods implemented in a
debug build.

I hope I am making sense.

Thank you for your help.
 
Hello ramhog,

Then I suppose u need to have the 2 classes, and wrapping one with #if debug
and another with #if RELEASE

---
WBR,
Michael Nemtsev [.NET/C# MVP] :: blog: http://spaces.live.com/laflour

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo


r> The problem with this is that if I only want to have the interface
r> implmented during a debug build. If I just put the #if
r> DEBUG...#endif around the methods, then a release build will have
r> errors because the interface isn't fully implemented.
r>
r> public class MyBigTestClass : IReleaseMethods, ITestMethods
r> {
r> ...
r> }
r> In this example, I want to only have the ITestMethods implemented in
r> a debug build.
r>
r> I hope I am making sense.
r>
r> Thank you for your help.
r>
Hello ramhog,

and what the problem? just use #if DEBUG preprocessor directive for
this

but u cant miss implementing some interfaces, u need provide either
debug implementation or the standart one

---
WBR,
Michael Nemtsev [.NET/C# MVP] :: blog:http://spaces.live.com/laflour
"The greatest danger for most of us is not that our aim is too high
and we miss it, but that it is too low and we reach it" (c)
Michelangelo

r> I have a class which implements several interfaces. One of them I
r> would like to have implemented only if it is a debug build. Is
there
r> a way to do this?
r>
r> Thanks.
r
 
Hi,


ramhog said:
The problem with this is that if I only want to have the interface
implmented during a debug build. If I just put the #if DEBUG...#endif
around the methods, then a release build will have errors because the
interface isn't fully implemented.

You have to do the same in the declaration:
class AddEditAgencySessionInfo
#if DEBUG
: IDisposable
#endif
 
Hi,




You have to do the same in the declaration:
class AddEditAgencySessionInfo
#if DEBUG
: IDisposable
#endif

Thanks for everyones help.

This gives me an error:
class MyTestClass : IReleaseMethods #if DEBUG , IDebugMethods #endif
{...}

I have tried different variantions of this with the same problem, such
as:
class MyTestClass : IReleaseMethods, #if DEBUG IDebugMethods #endif
class MyTestClass #if DEBUG : IReleaseMethods, IDebugMethods #endif
 
Hello ramhog,

Just check your code, everything works fine

u can use the following code to check it

public interface IMyInterface
{
void MethodOne();
void MethodTwo();
}

class Program
#if DEBUG
: IMyInterface
#endif

{
static void Main(string[] args)
{
}
#if DEBUG

#region IMyInterface Members

public void MethodOne()
{
throw new NotImplementedException();
}

public void MethodTwo()
{
throw new NotImplementedException();
}

#endregion

#endif

---
WBR,
Michael Nemtsev [.NET/C# MVP] :: blog: http://spaces.live.com/laflour

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo


r> On Aug 30, 10:19 am, "Ignacio Machin \( .NET/ C# MVP \)" <machin TA
r> laceupsolutions.com> wrote:
r>r> Thanks for everyones help.
r>
r> This gives me an error:
r> class MyTestClass : IReleaseMethods #if DEBUG , IDebugMethods #endif
r> {...}
r> I have tried different variantions of this with the same problem,
r> such
r> as:
r> class MyTestClass : IReleaseMethods, #if DEBUG IDebugMethods #endif
r> class MyTestClass #if DEBUG : IReleaseMethods, IDebugMethods #endi
 
ramhog said:
Thanks for everyones help.

This gives me an error:
class MyTestClass : IReleaseMethods #if DEBUG , IDebugMethods #endif
{...}

Yes, it would.
I have tried different variantions of this with the same problem, such
as:
class MyTestClass : IReleaseMethods, #if DEBUG IDebugMethods #endif
class MyTestClass #if DEBUG : IReleaseMethods, IDebugMethods #endif

You didn't try the code as posted though, I suspect.

Pre-processor directives need to be on lines on their own. Use exactly
the code Ignacio posted instead.

To be honest though, I'd try to avoid having this kind of thing in the
first place. It sounds like a recipe for problems.
 
Yes, it would.


You didn't try the code as posted though, I suspect.

Pre-processor directives need to be on lines on their own. Use exactly
the code Ignacio posted instead.

To be honest though, I'd try to avoid having this kind of thing in the
first place. It sounds like a recipe for problems.

Thank you very much all of you for your help. I didn't realize the
directive had to be on it's own line, that worked good.

class MyTestClass : IReleaseMethods
#if DEBUG
, ITestMethods
#endif
 

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

Back
Top