Implement Interface in debug build only

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ramhog

    #1

    Implement Interface in debug build only

    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.

  • Michael Nemtsev

    #2
    Re: Implement Interface in debug build only

    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


    rI have a class which implements several interfaces. One of them I
    rwould like to have implemented only if it is a debug build. Is there
    ra way to do this?
    r>
    rThanks.
    r>


    Comment

    • ramhog

      #3
      Re: Implement Interface in debug build only

      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.

      On Aug 30, 10:05 am, Michael Nemtsev <nemt...@msn.co mwrote:
      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
      >
      rI have a class which implements several interfaces. One of them I
      rwould like to have implemented only if it is a debug build. Is there
      ra way to do this?
      r>
      rThanks.
      r>

      Comment

      • Michael Nemtsev

        #4
        Re: Implement Interface in debug build only

        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


        rThe problem with this is that if I only want to have the interface
        rimplmented during a debug build. If I just put the #if
        rDEBUG...#endif around the methods, then a release build will have
        rerrors because the interface isn't fully implemented.
        r>
        rpublic class MyBigTestClass : IReleaseMethods , ITestMethods
        r{
        r...
        r}
        rIn this example, I want to only have the ITestMethods implemented in
        ra debug build.
        r>
        rI hope I am making sense.
        r>
        rThank you for your help.
        r>
        rOn Aug 30, 10:05 am, Michael Nemtsev <nemt...@msn.co mwrote:
        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
        >>
        >rI have a class which implements several interfaces. One of them I
        >rwould like to have implemented only if it is a debug build. Is
        >there
        >ra way to do this?
        >r>
        >rThanks.
        >r>

        Comment

        • Ignacio Machin \( .NET/ C# MVP \)

          #5
          Re: Implement Interface in debug build only

          Hi,


          "ramhog" <kalvin.tuel@ng c.comwrote in message
          news:1188486804 .646283.208820@ d55g2000hsg.goo glegroups.com.. .
          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 AddEditAgencySe ssionInfo
          #if DEBUG
          : IDisposable
          #endif


          Comment

          • ramhog

            #6
            Re: Implement Interface in debug build only

            On Aug 30, 10:19 am, "Ignacio Machin \( .NET/ C# MVP \)" <machin TA
            laceupsolutions .comwrote:
            Hi,
            >
            "ramhog" <kalvin.t...@ng c.comwrote in message
            >
            news:1188486804 .646283.208820@ d55g2000hsg.goo glegroups.com.. .
            >
            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 AddEditAgencySe ssionInfo
            #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


            Comment

            • Michael Nemtsev

              #7
              Re: Implement Interface in debug build only

              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 NotImplementedE xception();
              }

              public void MethodTwo()
              {
              throw new NotImplementedE xception();
              }

              #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


              rOn Aug 30, 10:19 am, "Ignacio Machin \( .NET/ C# MVP \)" <machin TA
              rlaceupsolution s.comwrote:
              r>
              >Hi,
              >>
              >"ramhog" <kalvin.t...@ng c.comwrote in message
              >>
              >news:118848680 4.646283.208820 @d55g2000hsg.go oglegroups.com. ..
              >>
              >>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...#endi f 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 AddEditAgencySe ssionInfo
              >#if DEBUG
              >: IDisposable
              >#endif
              rThanks for everyones help.
              r>
              rThis gives me an error:
              rclass MyTestClass : IReleaseMethods #if DEBUG , IDebugMethods #endif
              r{...}
              rI have tried different variantions of this with the same problem,
              rsuch
              ras:
              rclass MyTestClass : IReleaseMethods , #if DEBUG IDebugMethods #endif
              rclass MyTestClass #if DEBUG : IReleaseMethods , IDebugMethods #endif


              Comment

              • Jon Skeet [C# MVP]

                #8
                Re: Implement Interface in debug build only

                ramhog <kalvin.tuel@ng c.comwrote:
                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.

                --
                Jon Skeet - <skeet@pobox.co m>
                http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
                If replying to the group, please do not mail me too

                Comment

                • ramhog

                  #9
                  Re: Implement Interface in debug build only

                  On Aug 30, 1:04 pm, Jon Skeet [C# MVP] <sk...@pobox.co mwrote:
                  ramhog <kalvin.t...@ng c.comwrote:
                  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.
                  >
                  --
                  Jon Skeet - <sk...@pobox.co m>http://www.pobox.com/~skeet Blog:http://www.msmvps.com/jon.skeet
                  If replying to the group, please do not mail me too
                  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

                  Comment

                  Working...