dotnet-installer/scripts/Microsoft.DotNet.Cli.Build.Framework/TargetConditions/EnvironmentAttribute.cs
Sridhar Periyasamy ae041c8f61 Address some PR feedback.
- Make the MSI scripts to use parameters instead of environment variables.
2016-03-08 23:31:14 +00:00

38 lines
1 KiB
C#

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;
private string[] _expectedVals;
public EnvironmentAttribute(string envVar, params string[] expectedVals)
{
if (string.IsNullOrEmpty(envVar))
{
throw new ArgumentNullException("envVar");
}
_envVar = envVar;
_expectedVals = expectedVals;
}
public override bool EvaluateCondition()
{
var actualVal = Environment.GetEnvironmentVariable(_envVar);
foreach (var expectedVal in _expectedVals)
{
if (string.Equals(actualVal, expectedVal, StringComparison.Ordinal))
{
return true;
}
}
return false;
}
}
}