Skip to content

Commit 8f46188

Browse files
Update JSCallResultTypeHelper.cs (#25628)
* Update JSCallResultTypeHelper.cs and PublicAPI.Unshipped.txt * CR feedback. * Removed exception message
1 parent 43ef580 commit 8f46188

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed
Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,28 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

4+
using System.Reflection;
5+
46
namespace Microsoft.JSInterop
57
{
68
internal static class JSCallResultTypeHelper
79
{
10+
// We avoid using Assembly.GetExecutingAssembly() because this is shared code.
11+
private static readonly Assembly _currentAssembly = typeof(JSCallResultType).Assembly;
12+
813
public static JSCallResultType FromGeneric<TResult>()
9-
=> typeof(TResult) == typeof(IJSObjectReference)
10-
|| typeof(TResult) == typeof(IJSInProcessObjectReference)
11-
|| typeof(TResult) == typeof(IJSUnmarshalledObjectReference) ?
12-
JSCallResultType.JSObjectReference :
13-
JSCallResultType.Default;
14+
{
15+
if (typeof(TResult).Assembly == _currentAssembly
16+
&& (typeof(TResult) == typeof(IJSObjectReference)
17+
|| typeof(TResult) == typeof(IJSInProcessObjectReference)
18+
|| typeof(TResult) == typeof(IJSUnmarshalledObjectReference)))
19+
{
20+
return JSCallResultType.JSObjectReference;
21+
}
22+
else
23+
{
24+
return JSCallResultType.Default;
25+
}
26+
}
1427
}
1528
}

0 commit comments

Comments
 (0)