Add Conditional Target capabilities to the build scripts

Make Attribute properties immutable

PR Feedback, bugfixes

PR Feedback
This commit is contained in:
Bryan Thornbury 2016-02-19 17:00:41 -08:00 committed by Bryan
parent adc6aa7eff
commit 6d8b622451
16 changed files with 415 additions and 116 deletions

View file

@ -0,0 +1,41 @@
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;
}
}
}