44 lines
1.2 KiB
C#
44 lines
1.2 KiB
C#
// Copyright (c) .NET Foundation. All rights reserved.
|
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
|
|
|
using System;
|
|
using System.Text;
|
|
using WebAssembly;
|
|
|
|
namespace MonoSanityClient
|
|
{
|
|
public static class Examples
|
|
{
|
|
public static string AddNumbers(int a, int b)
|
|
=> (a + b).ToString();
|
|
|
|
public static string RepeatString(string str, int count)
|
|
{
|
|
var result = new StringBuilder();
|
|
|
|
for (var i = 0; i < count; i++)
|
|
{
|
|
result.Append(str);
|
|
}
|
|
|
|
return result.ToString();
|
|
}
|
|
|
|
public static void TriggerException(string message)
|
|
{
|
|
throw new InvalidOperationException(message);
|
|
}
|
|
|
|
public static string EvaluateJavaScript(string expression)
|
|
{
|
|
var result = Runtime.InvokeJS<string, object, object, string>(out var exceptionMessage, "evaluateJsExpression", expression, null, null);
|
|
if (exceptionMessage != null)
|
|
{
|
|
return $".NET got exception: {exceptionMessage}";
|
|
}
|
|
|
|
return $".NET received: {(result ?? "(NULL)")}";
|
|
}
|
|
}
|
|
}
|