mirror of
https://github.com/ElectronNET/Electron.NET.git
synced 2026-07-11 03:08:45 +00:00
Refactor debugger detection to use shared DebuggerHelper
Created a new DebuggerHelper class with Lazy<bool> initialization that is shared by both LaunchOrderDetector and UnpackagedDetector. This eliminates code duplication and provides a cleaner, more maintainable solution. - Added DebuggerHelper.cs with lazy-initialized IsAttached property - Refactored LaunchOrderDetector to use DebuggerHelper - Refactored UnpackagedDetector to use DebuggerHelper - Removed nullable bool pattern in favor of Lazy<bool>
This commit is contained in:
18
src/ElectronNET.API/Runtime/Helpers/DebuggerHelper.cs
Normal file
18
src/ElectronNET.API/Runtime/Helpers/DebuggerHelper.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
namespace ElectronNET.Runtime.Helpers
|
||||
{
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
/// <summary>
|
||||
/// Helper class for debugger detection with lazy initialization.
|
||||
/// </summary>
|
||||
internal static class DebuggerHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets whether a debugger is attached. This value is cached for performance.
|
||||
/// </summary>
|
||||
public static bool IsAttached => _isAttached.Value;
|
||||
|
||||
private static readonly Lazy<bool> _isAttached = new Lazy<bool>(() => Debugger.IsAttached);
|
||||
}
|
||||
}
|
||||
@@ -7,9 +7,6 @@
|
||||
|
||||
internal class LaunchOrderDetector
|
||||
{
|
||||
// Cache debugger state to avoid multiple expensive checks
|
||||
private static bool? _debuggerAttached;
|
||||
|
||||
public static bool CheckIsLaunchedByDotNet()
|
||||
{
|
||||
var tests = new List<Func<bool?>>();
|
||||
@@ -64,13 +61,7 @@
|
||||
|
||||
private static bool? CheckIsDotNetStartup3()
|
||||
{
|
||||
// Cache debugger state to avoid multiple expensive checks
|
||||
if (_debuggerAttached == null)
|
||||
{
|
||||
_debuggerAttached = Debugger.IsAttached;
|
||||
}
|
||||
|
||||
if (_debuggerAttached.Value)
|
||||
if (DebuggerHelper.IsAttached)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -8,9 +8,6 @@
|
||||
|
||||
internal class UnpackagedDetector
|
||||
{
|
||||
// Cache debugger state to avoid multiple expensive checks
|
||||
private static bool? _debuggerAttached;
|
||||
|
||||
public static bool CheckIsUnpackaged()
|
||||
{
|
||||
var tests = new List<Func<bool?>>();
|
||||
@@ -85,13 +82,7 @@
|
||||
|
||||
private static bool? CheckUnpackaged3()
|
||||
{
|
||||
// Cache debugger state to avoid multiple expensive checks
|
||||
if (_debuggerAttached == null)
|
||||
{
|
||||
_debuggerAttached = Debugger.IsAttached;
|
||||
}
|
||||
|
||||
if (_debuggerAttached.Value)
|
||||
if (DebuggerHelper.IsAttached)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user