Hey Demis,
just trying out sharp scripts. We are probably going to use it as our templating engine for different emails/messages.
Is it possible to call an async method from scriptsharp?
Given the following playground:
[Test]
public void RenderScriptWithAsyncReturnString()
{
var container = AppHost.Instance.Container;
var context = new ScriptContext()
{
ScanAssemblies = { typeof(I18nScript).Assembly },
Container = container,
}.Init();
Console.WriteLine(context.RenderScript("hello async {{ 'xxxxx' |> translate }}"));
}
And the following Script Method
public class I18nScript : ScriptMethods
{
private readonly I18NextNet _i18n;
public I18nScript(I18NextNet i18n)
{
_i18n = i18n;
}
public Task<string> Translate(string key)
{
return _i18n.TranslateAsync("x", "y", key);
}
}
The i18n library uses async.
The output is hello async System.Threading.Tasks.Task
1[System.String]`, but obviously should be the awaited result of the Task.
It also doesnt work if i do
public async Task<string> Translate(string key)
{
return await _i18n.TranslateAsync("language", "namespace", key);
}
How can this be achieved?
Maybe i was blind but I couldn’t figure it out in the docs. Sorry if i missed it there!