Scan only declared methods for JS interop (#1320)
* Scan only declared methods for JS interop * Add DotNetDispatcher test for JS invokable method on base class
This commit is contained in:
parent
04427d2e28
commit
7a763fc4f6
|
|
@ -240,7 +240,11 @@ namespace Microsoft.JSInterop
|
||||||
var result = new Dictionary<string, (MethodInfo, Type[])>();
|
var result = new Dictionary<string, (MethodInfo, Type[])>();
|
||||||
var invokableMethods = GetRequiredLoadedAssembly(assemblyName)
|
var invokableMethods = GetRequiredLoadedAssembly(assemblyName)
|
||||||
.GetExportedTypes()
|
.GetExportedTypes()
|
||||||
.SelectMany(type => type.GetMethods())
|
.SelectMany(type => type.GetMethods(
|
||||||
|
BindingFlags.Public |
|
||||||
|
BindingFlags.DeclaredOnly |
|
||||||
|
BindingFlags.Instance |
|
||||||
|
BindingFlags.Static))
|
||||||
.Where(method => method.IsDefined(typeof(JSInvokableAttribute), inherit: false));
|
.Where(method => method.IsDefined(typeof(JSInvokableAttribute), inherit: false));
|
||||||
foreach (var method in invokableMethods)
|
foreach (var method in invokableMethods)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -155,6 +155,21 @@ namespace Microsoft.JSInterop.Test
|
||||||
Assert.True(targetInstance.DidInvokeMyInvocableInstanceVoid);
|
Assert.True(targetInstance.DidInvokeMyInvocableInstanceVoid);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public Task CanInvokeBaseInstanceVoidMethod() => WithJSRuntime(jsRuntime =>
|
||||||
|
{
|
||||||
|
// Arrange: Track some instance
|
||||||
|
var targetInstance = new DerivedClass();
|
||||||
|
jsRuntime.Invoke<object>("unimportant", new DotNetObjectRef(targetInstance));
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var resultJson = DotNetDispatcher.Invoke(null, "BaseClassInvokableInstanceVoid", 1, null);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.Null(resultJson);
|
||||||
|
Assert.True(targetInstance.DidInvokeMyBaseClassInvocableInstanceVoid);
|
||||||
|
});
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public Task CannotUseDotNetObjectRefAfterDisposal() => WithJSRuntime(jsRuntime =>
|
public Task CannotUseDotNetObjectRefAfterDisposal() => WithJSRuntime(jsRuntime =>
|
||||||
{
|
{
|
||||||
|
|
@ -376,6 +391,21 @@ namespace Microsoft.JSInterop.Test
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class BaseClass
|
||||||
|
{
|
||||||
|
public bool DidInvokeMyBaseClassInvocableInstanceVoid;
|
||||||
|
|
||||||
|
[JSInvokable]
|
||||||
|
public void BaseClassInvokableInstanceVoid()
|
||||||
|
{
|
||||||
|
DidInvokeMyBaseClassInvocableInstanceVoid = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class DerivedClass : BaseClass
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
public class TestDTO
|
public class TestDTO
|
||||||
{
|
{
|
||||||
public string StringVal { get; set; }
|
public string StringVal { get; set; }
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue