Background and motivation
I find myself occasionally wanting to make Debugger.Launch() conditional with syntax like:
if (string.Equals(Environment.GetEnvironmentVariable(DebugEnvironmentVariableName), bool.TrueString, StringComparison.OrdinalIgnoreCase))
{
Debugger.Launch();
}
I think it would be a good addition if an overload to Debugger.Launch() accepted a bool that I could use as my conditional expression. Since Debugger is static, I can't add my own extension method.
API Proposal
namespace System.Diagnostics
{
public static partial class Debugger
{
/// <summary>
/// Launches and attaches a debugger to the process. If a debugger is already attached, nothing happens.
/// </summary>
/// <param name="condition"><c>true</c> to launch the debugger, otherwise <c>false</c>.</param>
/// <returns><c>true</c> if the debugger was launched or a debugger is already attached, otherwise <c>false</c>.</returns>
public static bool Launch(bool condition) => condition && Launch();
}
}
API Usage
Debugger.Launch(condition: string.Equals(Environment.GetEnvironmentVariable(DebugEnvironmentVariableName), bool.TrueString, StringComparison.OrdinalIgnoreCase));
Alternative Designs
I can have my own static class like DebuggerExtensions:
public static class DebuggerExtensions
{
/// <summary>
/// Launches and attaches a debugger to the process. If a debugger is already attached, nothing happens.
/// </summary>
/// <param name="condition"><c>true</c> to launch the debugger, otherwise <c>false</c>.</param>
/// <returns><c>true</c> if the debugger was launched or a debugger is already attached, otherwise <c>false</c>.</returns>
public static bool Launch(bool condition) => condition && System.Diagnostics.Debugger.Launch();
}
But I find myself doing this in multiple projects and don't think its wroth shipping a standalone class library for this.
Risks
Since it would be an overload with a unique set of parameters, there should not be any breaking change in the public API. But if no one is going to use it other than me, it's probably not worth shipping. Also, there's potential frustration where code targeting .NET Framework wouldn't compile with this syntax, since only newer versions of .NET would have it.
Background and motivation
I find myself occasionally wanting to make
Debugger.Launch()conditional with syntax like:I think it would be a good addition if an overload to
Debugger.Launch()accepted aboolthat I could use as my conditional expression. SinceDebuggeris static, I can't add my own extension method.API Proposal
API Usage
Alternative Designs
I can have my own static class like
DebuggerExtensions:But I find myself doing this in multiple projects and don't think its wroth shipping a standalone class library for this.
Risks
Since it would be an overload with a unique set of parameters, there should not be any breaking change in the public API. But if no one is going to use it other than me, it's probably not worth shipping. Also, there's potential frustration where code targeting .NET Framework wouldn't compile with this syntax, since only newer versions of .NET would have it.