Programmatically determine if an assembly is compiled in debug or release mode?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Taco (tditiecher_at_hotmail.com)
Date: 09/13/04


Date: 13 Sep 2004 14:28:53 -0700

Dear all,

I'm writing a WinApp that makes use of plugins. In the aboutbox I want
to show a list of loaded plugins (Name, Version and if the plugin is
compiled in Debug or Release mode). The Name and Version are easy to
retrieve by using reflection, but I don't know how to determine in
which mode (debug/release) a plugin is compiled. All plugins are
derived
from a PluginBase class containing the logic to retrieve the three
above
mentioned properties. The plugins are in separate assemblies.

Of course I can make the DebugOrRelease property abstract in the base
class and override it in the concrete plugin classes. The code in the
concrete classes will then be the same as in my source code of the
base class below, but I've to repeat this for every concrete class and
I believe that's not really clean (that's why we have base classes,
isn't it).

Does someone know how to retrieve the mode (debug/release) of the
plugin assembly?

Thank you in advance.

With kind regards,
Taco.

=== Source: Common assembly ===

public interface IPlugin {
   string Name { get; }
   string Version { get; }
   string DebugOrRelease { string get; }
}

public abstract class PluginBase : IPlugin {

   public string Name {
      get { return this.GetType().Name; }
   }
   
   public string Version {
      get { return this.GetType().Assembly.GetName().Version.ToString();
}
   }
   
   public virtual string DebugOrRelease {
      get {

// The following is not working, as this is the base class and the
// real plugins are in other assemblies, maybe compiled with other
// conditional compiler constants....

#if DEBUG
         return "Debug";
#else
         return "Release";
#endif
      
      }
   }
}

=== Source: Concrete plugin assembly ===

public class MyFirstPlugin : PluginBase {
   public override string DebugOrRelease {
      get {
// The following is working but has to be repeated in every
// concrete plugin.

#if DEBUG
         return "Debug";
#else
         return "Release";
#endif
      }
   }
}

public class MySecondPlugin : PluginBase {
   public override string DebugOrRelease {
      get {
// The following is working but has to be repeated in every
// concrete plugin.

#if DEBUG
         return "Debug";
#else
         return "Release";
#endif
      }
   }
}



Relevant Pages

  • Re: force cast of object to mytype...
    ... Public Function Host_GetObject(ByVal FonctionName As String, ByVal ParamArray Parameters() As Object) As Object ... The ParamArray causes an object array to be implicitly created, unless you explicitly pass an array of object. ... i have made an app based on plugin architecture in VB.NET. ...
    (microsoft.public.dotnet.languages.vb)
  • make a JAXB2/xjc Plugin
    ... It's supposed to generate a toString method for Person, ... public class PluginImpl extends Plugin { ... public String getOptionName() { ...
    (comp.lang.java.programmer)
  • Creating an argument list for sprintf
    ... I have a program that uses a scripting language that does not support formating ... I am writing a plugin to add the ... Where fmt is the string the user provided to be used as format, ...
    (comp.lang.c)
  • [ANN] Hex Plugin
    ... Hex Plugin for REALbasic 5 and higher is a small plugin with only two ... You can give the plugin a string containing an unsigned ... decimal integer of essentially unlimited length and the plugin will ...
    (comp.lang.basic.realbasic)