Skip to content

Instantly share code, notes, and snippets.

@gsscoder
Last active February 22, 2020 19:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gsscoder/59ad83929d5483832184edfb0296e950 to your computer and use it in GitHub Desktop.
Save gsscoder/59ad83929d5483832184edfb0296e950 to your computer and use it in GitHub Desktop.
C# draft of Azure Pipelines conditions with ExpressionEngine
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