1
0
Fork 0
mirror of https://github.com/VSadov/Satori.git synced 2025-06-08 03:27:04 +09:00
Satori/src/mono/sample/wasm/browser/Program.cs
Pavel Savara 0d80733c26
[wasm] deprecate legacy JS API and propose new (#73068)
- Added new API methods to top level next to MONO and BINDING namespaces
- marked MONO and BINDING namespaces obsolete
- separated legacy API into dotnet-legacy.d.ts
- renamed snake_case to camelCase names

Co-authored-by: Marek Fišera <mara@neptuo.com>
Co-authored-by: Ankit Jain <radical@gmail.com>
2022-08-04 08:19:50 +02:00

47 lines
1.3 KiB
C#

// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices.JavaScript;
namespace Sample
{
public partial class Test
{
public static int Main(string[] args)
{
Console.WriteLine ("Hello, World!");
return 0;
}
[JSImport("Sample.Test.add", "main.js")]
internal static partial int Add(int a, int b);
[JSImport("Sample.Test.sub", "main.js")]
internal static partial int Sub(int a, int b);
[JSExport]
internal static int TestMeaning()
{
// call back to JS via imports
return Add(Sub(80, 40), 2);
}
[JSExport]
internal static bool IsPrime(int number)
{
if (number <= 1) return false;
if (number == 2) return true;
if (number % 2 == 0) return false;
var boundary = (int)Math.Floor(Math.Sqrt(number));
for (int i = 3; i <= boundary; i += 2)
if (number % i == 0)
return false;
return true;
}
}
}