Click here to Skip to main content
Click here to Skip to main content
Alternative Tip/Trick

Tagged as

(C#) Determining whether the current build mode is Debug or Release

, 3 Feb 2012 CPOL
Rate this:
Please Sign up or sign in to vote.
While I think alternative 3 could be quite useful I often have access to the assembly name and not the actual file name.For example the assembly name might be:Company.ProductWhereas the file name might be:Company.Product.dllThere are times when I'll fully qualify a class such...
While I think alternative 3 could be quite useful I often have access to the assembly name and not the actual file name.
For example the assembly name might be:
Company.Product
Whereas the file name might be:
Company.Product.dll
 
There are times when I'll fully qualify a class such as:
"Company.Product.Namespace.MyClass, Company.Product"
and therefore I have the name of the assembly, but not the name of the file.
 
The fully qualified class name is useful to pass to Type.GetType(string) when passing only the full class name doesn't seem to work.
 
While adding ".dll" on the end is not difficult I do think there are times when the following alternative might be useful.
 
Instead of passing the file name you simply pass the assembly name. Which does tend to be the file name without the .dll.
 
Instead of using the Assembly.LoadFile function it uses Assembly.Load.
 
        public static bool IsInDebugMode(string assemblyName)
        {
            var assembly = System.Reflection.Assembly.Load(assemblyName);
            var attributes = assembly.GetCustomAttributes(typeof(System.Diagnostics.DebuggableAttribute), false);
            if (attributes.Length > 0)
            {
                var debuggable = attributes[0] as System.Diagnostics.DebuggableAttribute;
                if (debuggable != null)
                    return (debuggable.DebuggingFlags & System.Diagnostics.DebuggableAttribute.DebuggingModes.Default) == System.Diagnostics.DebuggableAttribute.DebuggingModes.Default;
                else
                    return false;
            }
            else
                return false;
        }
 
However I'm sure there are plenty of times when people have the file name and therefore the previous alternative would be more suited.
 
So the function used depends on whether the assembly info you have access to is the assembly name or the file name.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

SoftwareMonkeys
SoftwareMonkeys
Australia Australia
Founder of www.softwaremonkeys.net

Comments and Discussions

 
GeneralGood job, I updated my tip at http://www.codeproject.com/Tip... PinmemberHuisheng Chen3-Feb-12 23:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150129.1 | Last Updated 3 Feb 2012
Article Copyright 2012 by SoftwareMonkeys
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid