Skip to content

Use Source Generation #33

@RichiCoder1

Description

@RichiCoder1

Ideally it'd be excellent to see this PDK support writing more idiomatic .NET Code via source generation.

For example, turning the Getting Started example from:

using System;
using System.Runtime.InteropServices;
using System.Text.Json;
using Extism;

namespace MyPlugin;
public class Functions
{
    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;
    }
}

to

using Extism;

namespace MyPlugin;

public partial class Functions
{
	[WasmExport(Name = "greet")]
    public static string Greet(string name)
    {
		return $"Hello, {name}";
    }
}

with something like this being generated under the covers:

namespace MyPlugin;
public partial class Functions
{
    public static void Main() { }

    [UnmanagedCallersOnly(EntryPoint = "greet")]
    public static int <>__Greet0()
    {
        var name = global::Extism::Pdk.GetInputString();
		var output = Functions::Greet(name);
        global::Extism::Pdk.SetOutput(output);

        return 0;
    }
}

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions