namespace Bts.BooleanExpressions.Arguments; static class ArgumentExtensions { public static IArgument Cast(this IArgument argument) => new Argument(env => { var obj = argument.GetValue(env); return obj is T t ? t : throw new Exception( $"Expected argument.GetValue to return instance of type {typeof(T)} " + $"(actually {obj?.GetType()})"); }); }