JSInProcessObjectReferenceExtensions.cs 1.1 KB

1234567891011121314151617181920212223242526
  1. // Copyright (c) .NET Foundation. All rights reserved.
  2. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
  3. using System;
  4. namespace Microsoft.JSInterop
  5. {
  6. public static class JSInProcessObjectReferenceExtensions
  7. {
  8. /// <summary>
  9. /// Invokes the specified JavaScript function synchronously.
  10. /// </summary>
  11. /// <param name="jsObjectReference">The <see cref="IJSInProcessObjectReference"/>.</param>
  12. /// <param name="identifier">An identifier for the function to invoke. For example, the value <c>"someScope.someFunction"</c> will invoke the function <c>someScope.someFunction</c> on the target instance.</param>
  13. /// <param name="args">JSON-serializable arguments.</param>
  14. public static void InvokeVoid(this IJSInProcessObjectReference jsObjectReference, string identifier, params object?[] args)
  15. {
  16. if (jsObjectReference == null)
  17. {
  18. throw new ArgumentNullException(nameof(jsObjectReference));
  19. }
  20. jsObjectReference.Invoke<object>(identifier, args);
  21. }
  22. }
  23. }