-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Back to old invokeUnmarshalled call, no callback, no serialization (#105
) * Fixes #104 - Back to old invokeUnmarshalled call, no callback, no serialization * Remove unused class * Remove unused class * Remove unused js members * Update setup extensions with fail early.Removed console outputs. Demo projects yield and v2.1. version up * Update readme
- Loading branch information
Showing
15 changed files
with
231 additions
and
179 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
using Microsoft.JSInterop; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Reflection; | ||
using System.Text; | ||
|
||
namespace Blazor.FileReader | ||
{ | ||
internal static class IJSRuntimeExtensions | ||
{ | ||
private readonly static Type WebAssemblyJSRuntime | ||
= Type.GetType("Mono.WebAssembly.Interop.MonoWebAssemblyJSRuntime, Mono.WebAssembly.Interop"); | ||
|
||
private readonly static MethodInfo _invokeUnmarshalled = GetInvokeUnmarshalled(); | ||
private readonly static Dictionary<string, MethodInfo> _genericinvokeUnmarshalledMethods | ||
= new Dictionary<string, MethodInfo>(); | ||
|
||
public static bool IsInvokeUnmarshalledSupported() | ||
{ | ||
return _invokeUnmarshalled != null; | ||
} | ||
|
||
public static TReturn InvokeUnmarshalled<TParam, TReturn>(this IJSRuntime jsRuntime, string methodName, TParam parameter) | ||
{ | ||
var cacheKey = $"{typeof(TReturn)}|{typeof(TParam)}"; | ||
if (!_genericinvokeUnmarshalledMethods.TryGetValue(cacheKey, out var genericMethodInfo)) | ||
{ | ||
genericMethodInfo = _invokeUnmarshalled.MakeGenericMethod(typeof(TParam), typeof(TReturn)); | ||
_genericinvokeUnmarshalledMethods.Add(cacheKey, genericMethodInfo); | ||
} | ||
|
||
return (TReturn)genericMethodInfo.Invoke(jsRuntime, new object[] { methodName, parameter }); | ||
} | ||
|
||
private static MethodInfo GetInvokeUnmarshalled() | ||
{ | ||
if (WebAssemblyJSRuntime == null) | ||
{ | ||
System.Diagnostics.Debug.WriteLine($"{nameof(IJSRuntimeExtensions)} : MonoWebAssemblyJSRuntime not found."); | ||
return null; | ||
} | ||
|
||
foreach (var methodInfo in WebAssemblyJSRuntime.GetMethods()) | ||
{ | ||
if (methodInfo.Name == "InvokeUnmarshalled" && methodInfo.GetParameters().Length == 2) | ||
{ | ||
return methodInfo; | ||
} | ||
} | ||
|
||
System.Diagnostics.Debug.WriteLine($"{nameof(IJSRuntimeExtensions)} : MonoWebAssemblyJSRuntime.InvokeUnmarshalled method not found."); | ||
|
||
return null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using System.Runtime.InteropServices; | ||
|
||
namespace Blazor.FileReader | ||
{ | ||
|
||
[StructLayout(LayoutKind.Explicit)] | ||
struct ReadFileParams | ||
{ | ||
[FieldOffset(0)] | ||
public byte[] Buffer; | ||
[FieldOffset(4)] | ||
internal long BufferOffset; | ||
[FieldOffset(12)] | ||
internal int Count; | ||
[FieldOffset(16)] | ||
internal int FileRef; | ||
[FieldOffset(20)] | ||
public long Position; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.