JSInProcessObjectReferenceExtensions.cs 1.2 KB

1234567891011121314151617181920212223242526272829
  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. /// <summary>
  7. /// Extension methods for <see cref="IJSInProcessObjectReference"/>.
  8. /// </summary>
  9. public static class JSInProcessObjectReferenceExtensions
  10. {
  11. /// <summary>
  12. /// Invokes the specified JavaScript function synchronously.
  13. /// </summary>
  14. /// <param name="jsObjectReference">The <see cref="IJSInProcessObjectReference"/>.</param>
  15. /// <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>
  16. /// <param name="args">JSON-serializable arguments.</param>
  17. public static void InvokeVoid(this IJSInProcessObjectReference jsObjectReference, string identifier, params object?[] args)
  18. {
  19. if (jsObjectReference == null)
  20. {
  21. throw new ArgumentNullException(nameof(jsObjectReference));
  22. }
  23. jsObjectReference.Invoke<object>(identifier, args);
  24. }
  25. }
  26. }