2016-03-07 20:20:50 +00:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
namespace Microsoft.DotNet.Cli.Build.Framework
|
|
|
|
{
|
|
|
|
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true, Inherited = false)]
|
|
|
|
public class EnvironmentAttribute : TargetConditionAttribute
|
|
|
|
{
|
|
|
|
private string _envVar;
|
2016-03-07 22:52:41 +00:00
|
|
|
private string[] _expectedVals;
|
2016-03-07 20:20:50 +00:00
|
|
|
|
2016-03-07 22:52:41 +00:00
|
|
|
public EnvironmentAttribute(string envVar, params string[] expectedVals)
|
2016-03-07 20:20:50 +00:00
|
|
|
{
|
|
|
|
if (string.IsNullOrEmpty(envVar))
|
|
|
|
{
|
|
|
|
throw new ArgumentNullException("envVar");
|
|
|
|
}
|
|
|
|
|
|
|
|
_envVar = envVar;
|
2016-03-07 22:52:41 +00:00
|
|
|
_expectedVals = expectedVals;
|
2016-03-07 20:20:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public override bool EvaluateCondition()
|
|
|
|
{
|
|
|
|
var actualVal = Environment.GetEnvironmentVariable(_envVar);
|
|
|
|
|
2016-03-07 22:52:41 +00:00
|
|
|
foreach (var expectedVal in _expectedVals)
|
2016-03-07 20:20:50 +00:00
|
|
|
{
|
2016-03-07 22:52:41 +00:00
|
|
|
if (string.Equals(actualVal, expectedVal, StringComparison.Ordinal))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2016-03-07 20:20:50 +00:00
|
|
|
}
|
|
|
|
|
2016-03-07 22:52:41 +00:00
|
|
|
return false;
|
2016-03-07 20:20:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|