-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
38 lines (32 loc) · 983 Bytes
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
using System.Runtime.InteropServices;
using System.Text.Json.Serialization;
using Extism;
namespace Plugin;
public class Program
{
public static void Main()
{
// Note: a `Main` method is required for the app to compile
}
[UnmanagedCallersOnly(EntryPoint = "greet")]
public static int Greet()
{
var name = Pdk.GetInputString();
var greeting = $"Hello, {name}!";
Pdk.SetOutput(greeting);
return 0;
}
[UnmanagedCallersOnly(EntryPoint = "add")]
public static int Add()
{
var parameters = Pdk.GetInputJson(SourceGenerationContext.Default.Add);
var sum = new Sum(parameters.a + parameters.b);
Pdk.SetOutputJson(sum, SourceGenerationContext.Default.Sum);
return 0;
}
}
[JsonSerializable(typeof(Add))]
[JsonSerializable(typeof(Sum))]
public partial class SourceGenerationContext : JsonSerializerContext {}
public record Add(int a, int b);
public record Sum(int Result);