-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathDefaultRuntimeEnvironmentInformation.cs
45 lines (41 loc) · 1.39 KB
/
DefaultRuntimeEnvironmentInformation.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
namespace Nancy
{
using System;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
/// <summary>
/// Default implementation of the <see cref="IRuntimeEnvironmentInformation"/> interface.
/// </summary>
public class DefaultRuntimeEnvironmentInformation : IRuntimeEnvironmentInformation
{
private readonly Lazy<bool> isDebug;
/// <summary>
/// Initializes a new instance of the <see cref="DefaultRuntimeEnvironmentInformation"/> class.
/// </summary>
/// <param name="typeCatalog">An <see cref="ITypeCatalog"/> instance.</param>
public DefaultRuntimeEnvironmentInformation(ITypeCatalog typeCatalog)
{
this.isDebug = new Lazy<bool>(() => GetDebugMode(typeCatalog));
}
/// <summary>
/// Gets a value indicating if the application is running in debug mode.
/// </summary>
/// <returns><see langword="true"/> if the application is running in debug mode, otherwise <see langword="false"/>.</returns>
public virtual bool IsDebug
{
get { return this.isDebug.Value; }
}
private static bool GetDebugMode(ITypeCatalog typeCatalog)
{
try
{
return Debugger.IsAttached;
}
catch
{
return false;
}
}
}
}