Skip to content

Commit

Permalink
Correct mismatch between interops
Browse files Browse the repository at this point in the history
  • Loading branch information
moreal committed May 23, 2023
1 parent bf0d3dd commit 97ce7c4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
13 changes: 13 additions & 0 deletions Lib9c.Wasm/JsonUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,19 @@ public static object ConvertJsonElementTo(JsonElement element, Type targetType)
return Enum.Parse(targetType, element.GetString());
}

if (element.ValueKind == JsonValueKind.Object &&
!targetType.IsAssignableTo(typeof(Nekoyume.Model.State.IState)) &&
targetType.GetConstructors().Where(ctr =>
ctr.GetParameters().Length > 0 &&
!(ctr.GetParameters().Length == 1 && typeof(Bencodex.Types.IValue).IsAssignableFrom(ctr.GetParameters().First().ParameterType)) &&
!(ctr.GetParameters().Length == 2 && ctr.GetParameters().First().ParameterType == typeof(SerializationInfo) && ctr.GetParameters().Skip(1).First().ParameterType == typeof(StreamingContext))
).OrderByDescending(x => x.GetParameters().Length).FirstOrDefault() is { } constructor)
{
return constructor.Invoke(constructor.GetParameters().Select(parameter => {
return ConvertJsonElementTo(element.GetProperty(parameter.Name), parameter.ParameterType);
}).ToArray());
}

if (element.ValueKind == JsonValueKind.Object)
{
var instance = Activator.CreateInstance(targetType);
Expand Down
3 changes: 1 addition & 2 deletions Lib9c.Wasm/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ bool IsIgnoredType(Type type)
// Combine the TypeScript types into a single object type
var typeInfo = "{" + string.Join(", ", inputs) + "}";

return typeInfo;

return ResolveType(actionType);
}

[JSInvokable]
Expand Down

0 comments on commit 97ce7c4

Please sign in to comment.