Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The node must be of type json object #1797

Closed

Conversation

hyzx86
Copy link
Contributor

@hyzx86 hyzx86 commented Mar 5, 2024

No description provided.

@hyzx86
Copy link
Contributor Author

hyzx86 commented Mar 5, 2024

relate : OrchardCMS/OrchardCore#15449

@hyzx86
Copy link
Contributor Author

hyzx86 commented Mar 5, 2024

use the following configuration to resolve

var engine = new Engine(options =>
{
// make JsonArray behave like JS array
options.Interop.WrapObjectHandler = static (e, target, type) =>
{
var wrapped = new ObjectWrapper(e, target);
if (target is JsonArray)
{
wrapped.Prototype = e.Intrinsics.Array.PrototypeObject;
}
return wrapped;
};
// we cannot access this[string] with anything else than JsonObject, otherwise itw will throw
options.Interop.TypeResolver = new TypeResolver
{
MemberFilter = static info =>
{
if (info.ReflectedType != typeof(JsonObject) && info.Name == "Item" && info is PropertyInfo p)
{
var parameters = p.GetIndexParameters();
return parameters.Length != 1 || parameters[0].ParameterType != typeof(string);
}
return true;
}
};
});

@hyzx86 hyzx86 closed this Mar 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant