44using System ;
55using System . Collections . Generic ;
66using System . Linq ;
7+ using Microsoft . DotNet . Cli . Utils ;
78
89namespace Microsoft . DotNet . Cli . Telemetry ;
910
@@ -33,8 +34,7 @@ public BooleanEnvironmentRule(params string[] variables)
3334
3435 public override bool IsMatch ( )
3536 {
36- return _variables . Any ( variable =>
37- bool . TryParse ( Environment . GetEnvironmentVariable ( variable ) , out bool value ) && value ) ;
37+ return _variables . Any ( variable => Env . GetEnvironmentVariableAsBool ( variable ) ) ;
3838 }
3939}
4040
@@ -81,12 +81,12 @@ public override bool IsMatch()
8181/// <typeparam name="T">The type of the result value.</typeparam>
8282internal class EnvironmentDetectionRuleWithResult < T > where T : class
8383{
84- private readonly string [ ] _variables ;
84+ private readonly EnvironmentDetectionRule _rule ;
8585 private readonly T _result ;
8686
87- public EnvironmentDetectionRuleWithResult ( T result , params string [ ] variables )
87+ public EnvironmentDetectionRuleWithResult ( T result , EnvironmentDetectionRule rule )
8888 {
89- _variables = variables ?? throw new ArgumentNullException ( nameof ( variables ) ) ;
89+ _rule = rule ?? throw new ArgumentNullException ( nameof ( rule ) ) ;
9090 _result = result ?? throw new ArgumentNullException ( nameof ( result ) ) ;
9191 }
9292
@@ -96,8 +96,8 @@ public EnvironmentDetectionRuleWithResult(T result, params string[] variables)
9696 /// <returns>The result value if the rule matches; otherwise, null.</returns>
9797 public T ? GetResult ( )
9898 {
99- return _variables . Any ( variable => ! string . IsNullOrEmpty ( Environment . GetEnvironmentVariable ( variable ) ) )
100- ? _result
99+ return _rule . IsMatch ( )
100+ ? _result
101101 : null ;
102102 }
103- }
103+ }
0 commit comments