As you're developing you often use things like
throw new NotImplementedException("Finish this off later")
or
// TODO - Finish this off later
as a placeholder to remind you to finish something off - but these can be missed and mistakenly end up in the release.
You could use something like
#if RELEASE
Finish this off later
#endif
so it won't compile in Release build - but is there a more elegant way?
I saw an elegant implementation here
#if DEBUG
namespace FakeItEasy
{
using System;
using System.Diagnostics.CodeAnalysis;
/// <summary>
/// An exception that can be thrown before a member has been
/// implemented, will cause the build to fail when not built in
/// debug mode.
/// </summary>
[Serializable]
[SuppressMessage("Microsoft.Design",
"CA1032:ImplementStandardExceptionConstructors",
Justification = "Never used in production.")]
public class MustBeImplementedException
: Exception
{
}
}
#endif
I would recommend to use #warning
:
#warning Finish this off later
And in the Release
configuration set Treat Warnings as Errors
to True
.
In this case in Debug you will see it only as warnings but in release it will throw exceptions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With