C# Script Evaluate

Evaluates a C# expression and returns the result.

Version 1

HTTP Request
POST /ado/v1/csharpevaluate

Header

ParameterDescription
Ocp-Apim-Subscription-KeyThe subscription key you received when you purchased a plan.

Request Body

Mandatory

ParameterTypeDescription
expressionStringThe C# expression that will be executed.

Notes

This operation can be used to evaluate an expression, using C# syntax, and return the results.

This is a cut down version of the C# Script Execute operation but is bound by the same guard rails.

The main advantage of this operation is that there is no need for a return statement and it is very easy to execute calculations in a dynamic way by passing in a string that contains all of the required components.

Restricted Namespaces

The functionality made available is not all encompassing. Invocations originating from volatile and security conscious namespaces have been restricted and are not able to be made use of through this operation.

Examples of restricted invocations:

  • HTTP/Web calls – There should be no need to make such calls given the framework you are calling this operation from can perform those tasks for you.
  • Reflection – This would allow the calling application to dive deeper into the underlying framework. It would also allow calling applications to invoke methods on external assemblies and therefore, is not permitted.
  • File System Operations – The file system is of no great use to the calling application and it would also open up the framework to potential vulnerabilities, for that reason, file system operations are not permitted. However, System.IO.* operations that deal with streams is permitted.
  • Process Invocation – Spawning applications is not permitted. This would open up the framework to vulnerabilities and is not seen as being something that is seen to be required within the scope of the operation.

If you require the use of a method within a restricted namespace that you believe should be permitted, please contact us through our support channel and we will consider the request. However, we make no guarantees that your request will be successful.

Additional External Assemblies

This is not permitted.

Instantiating objects that are referenced from external assemblies is not made possible by the framework.

Built-in Using Directives

You, as the developer, do not have the ability to add or remove a using directives. Those that exist are outside the scope of the core script that you as the developer are able to provide and those that have been provided for are considered to be of high importance and high usage. Those directives are:

using System;
using System.Linq;

using System.Text;
using System.Threading.Tasks;
using System.Collections.Generic;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;

using Newtonsoft.Json.Linq

Given that be the case, any reference to a namespace or nested namespace that is not specified in the list above will need to be fully qualified.

Script Timeout

A script must have completed it’s execution within a 2 second period on the Basic pricing tier and within a 5 second period on the Standard pricing tier.

This limit does not include the time it takes to compile and validate the code for any restricted namespaces. It’s is merely the execution time that is monitored.

Examples

Equation

This basic example shows how you can provide an equation as a string and have it calculate the result.

Request

{
    "expression": "345 + 402 * 64"
}
Code language: JSON / JSON with Comments (json)

Response

{
    "result": 26073
}
Code language: JSON / JSON with Comments (json)