{
//Consult https://github.com/Esri/arcade-expressions/ and
//https://developers.arcgis.com/arcade/ for more examples
//and arcade reference
// Note: the following should be embedded in a QueuedTask.Run() statement
{
//construct an expression
var query = @"Count($layer)";//count of features in "layer"
//construct a CIMExpressionInfo
var arcade_expr = new CIMExpressionInfo()
{
Expression = query.ToString(),
//Return type can be string, numeric, or default
//When set to default, add-in is responsible for determining
//the return type
ReturnType = ExpressionReturnType.Default
};
//Construct an evaluator
//select the relevant profile - it must support Pro and it must
//contain any profile variables you are using in your expression.
//Consult: https://developers.arcgis.com/arcade/profiles/
using var arcade = ArcadeScriptEngine.Instance.CreateEvaluator(
arcade_expr, ArcadeProfile.Popups);
//Provision values for any profile variables referenced...
//in our case '$layer'
var variables = new List<KeyValuePair<string, object>>() {
new("$layer", featureLayer)
};
//evaluate the expression
try
{
var result = arcade.Evaluate(variables).GetResult();
System.Diagnostics.Debug.WriteLine($"Result: {result}");
}
//handle any exceptions
catch (InvalidProfileVariableException)
{
//something wrong with the profile variable specified
//TODO...
}
catch (EvaluationException)
{
//something wrong with the query evaluation
//TODO...
}
}
}