dotnet-installer/scripts/Microsoft.DotNet.Cli.Build.Framework/TargetConditions/BuildPlatformsAttribute.cs
Bryan Thornbury 6d8b622451 Add Conditional Target capabilities to the build scripts
Make Attribute properties immutable

PR Feedback, bugfixes

PR Feedback
2016-02-24 16:55:11 -08:00

41 lines
No EOL
1.1 KiB
C#

using System;
using System.Collections.Generic;
namespace Microsoft.DotNet.Cli.Build.Framework
{
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
public class BuildPlatformsAttribute : TargetConditionAttribute
{
private IEnumerable<BuildPlatform> _buildPlatforms;
public BuildPlatformsAttribute(params BuildPlatform[] platforms)
{
if (platforms == null)
{
throw new ArgumentNullException("platforms");
}
_buildPlatforms = platforms;
}
public override bool EvaluateCondition()
{
var currentPlatform = CurrentPlatform.Current;
if (currentPlatform == default(BuildPlatform))
{
throw new Exception("Unrecognized Platform.");
}
foreach (var platform in _buildPlatforms)
{
if (platform == currentPlatform)
{
return true;
}
}
return false;
}
}
}