Last active
February 22, 2020 19:59
-
-
Save gsscoder/59ad83929d5483832184edfb0296e950 to your computer and use it in GitHub Desktop.
C# draft of Azure Pipelines conditions with ExpressionEngine
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Immutable; | |
using System.Linq; | |
using ExpressionEngine; | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var context = new Context(); | |
context.SetFunction("always", () => true); | |
context.SetFunction("eq", x => x[0].Equals(x[1])); | |
context.SetFunction("ne", x => !x[0].Equals(x[1])); | |
context.SetFunction("and", x => | |
ImmutableArray.Create<object>(x).Aggregate<bool, object>( | |
true, (res, next) => res = res && (bool)next)); | |
context.SetFunction("or", x => | |
ImmutableArray.Create<object>(x).Aggregate<bool, object>( | |
true, (res, next) => res = res || (bool)next)); | |
var result = context.EvaluateAs<bool>("and(always(), or(ne(1, 2), eq(2, 1)))"); | |
Console.WriteLine(result); // outcome: True | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment