4
4
using System ;
5
5
using System . Collections . Generic ;
6
6
using System . Linq ;
7
+ using Microsoft . DotNet . Cli . Utils ;
7
8
8
9
namespace Microsoft . DotNet . Cli . Telemetry ;
9
10
@@ -33,8 +34,7 @@ public BooleanEnvironmentRule(params string[] variables)
33
34
34
35
public override bool IsMatch ( )
35
36
{
36
- return _variables . Any ( variable =>
37
- bool . TryParse ( Environment . GetEnvironmentVariable ( variable ) , out bool value ) && value ) ;
37
+ return _variables . Any ( variable => Env . GetEnvironmentVariableAsBool ( variable ) ) ;
38
38
}
39
39
}
40
40
@@ -81,12 +81,12 @@ public override bool IsMatch()
81
81
/// <typeparam name="T">The type of the result value.</typeparam>
82
82
internal class EnvironmentDetectionRuleWithResult < T > where T : class
83
83
{
84
- private readonly string [ ] _variables ;
84
+ private readonly EnvironmentDetectionRule _rule ;
85
85
private readonly T _result ;
86
86
87
- public EnvironmentDetectionRuleWithResult ( T result , params string [ ] variables )
87
+ public EnvironmentDetectionRuleWithResult ( T result , EnvironmentDetectionRule rule )
88
88
{
89
- _variables = variables ?? throw new ArgumentNullException ( nameof ( variables ) ) ;
89
+ _rule = rule ?? throw new ArgumentNullException ( nameof ( rule ) ) ;
90
90
_result = result ?? throw new ArgumentNullException ( nameof ( result ) ) ;
91
91
}
92
92
@@ -96,8 +96,8 @@ public EnvironmentDetectionRuleWithResult(T result, params string[] variables)
96
96
/// <returns>The result value if the rule matches; otherwise, null.</returns>
97
97
public T ? GetResult ( )
98
98
{
99
- return _variables . Any ( variable => ! string . IsNullOrEmpty ( Environment . GetEnvironmentVariable ( variable ) ) )
100
- ? _result
99
+ return _rule . IsMatch ( )
100
+ ? _result
101
101
: null ;
102
102
}
103
- }
103
+ }
0 commit comments