Skip to content

Commit

Permalink
fix(runtime/dotnet): Correctly map callback results
Browse files Browse the repository at this point in the history
Use the type data available on the deputy object to determine the
relevant JSII type for the result of callbacks, instead of trying to map
into `PrimitiveType.Any`.

Fixes #290
Fixes aws/aws-cdk#1027
  • Loading branch information
RomainMuller committed Nov 2, 2018
1 parent 927f50e commit 6066e1c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ static object InvokeMethod(InvokeRequest request, IReferenceMap referenceMap, ou
throw new InvalidOperationException($"Received callback for {deputy.GetType().Name}.{request.Method} getter, but this method does not exist");
}

returnType = methodInfo.GetCustomAttribute<JsiiMethodAttribute>()?.Returns;
JsiiMethodAttribute attribute = methodInfo.GetCustomAttribute<JsiiMethodAttribute>();
returnType = attribute?.Returns;

return methodInfo.Invoke(deputy, request.Arguments);
}
Expand All @@ -92,14 +93,15 @@ static object InvokeGetter(GetRequest request, IReferenceMap referenceMap, out T
throw new InvalidOperationException($"Received callback for {deputy.GetType().Name}.{request.Property} getter, but this property does not exist");
}

JsiiPropertyAttribute attribute = propertyInfo.GetCustomAttribute<JsiiPropertyAttribute>();
returnType = attribute?.Type;

MethodInfo methodInfo = propertyInfo.GetGetMethod();
if (methodInfo == null)
{
throw new InvalidOperationException($"Received callback for {deputy.GetType().Name}.{request.Property} getter, but this property does not have a getter");
}

returnType = methodInfo.GetCustomAttribute<JsiiPropertyAttribute>()?.Type;

return methodInfo.Invoke(deputy, new object[] { });
}

Expand Down
Binary file not shown.

0 comments on commit 6066e1c

Please sign in to comment.