Skip to content
Discussion options

You must be logged in to vote

I'm guessing what you want is a IObjectConverter.

[Fact]
public void Test()
{
    var engine = new Engine(o => o.AddObjectConverter(new ExternalLocaleStringConverter()));

    engine.SetValue("locale", new ExternalLocaleString());
    Assert.Equal("English", engine.Evaluate("locale['en']").AsString());
    Assert.Equal("Dutch", engine.Evaluate("locale['nl']").AsString());
}

public class ExternalLocaleStringConverter : IObjectConverter
{
    public bool TryConvert(Engine engine, object value, [NotNullWhen(true)] out JsValue result)
    {
        if (value is ExternalLocaleString localeString)
        {
            result = JsValue.FromObject(engine, new ExternalLocaleStringWrapper(localeS…

Replies: 4 comments 5 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@lahma
Comment options

lahma Mar 3, 2023
Collaborator

Comment options

You must be logged in to vote
2 replies
@Genteure
Comment options

@KoalaBear84
Comment options

Comment options

You must be logged in to vote
2 replies
@KoalaBear84
Comment options

@KoalaBear84
Comment options

Answer selected by KoalaBear84
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants