csla icon indicating copy to clipboard operation
csla copied to clipboard

Mark assembly as supported in the browser

Open kant2002 opened this issue 1 year ago • 4 comments

  • Mark unsupported API in the browser
  • Enforce future marking of unsupported in the browser API via editorconfig

Closes #1894

kant2002 avatar Jul 01 '24 07:07 kant2002

Wouldn't it make sense to create a helper class which encapsulates

#if NET8_0_OR_GREATER
      if (OperatingSystem.IsBrowser())
      {
        throw new PlatformNotSupportedException();
      }
#endif

and is used everywhere this code is now? Something like

internal static class PlatformHelper
{
  public void ThrowNotSupportedIfBrowser()
  {
#if NET8_0_OR_GREATER
      if (OperatingSystem.IsBrowser())
      {
        throw new PlatformNotSupportedException();
      }
#endif
  }
}

StefanOssendorf avatar Jul 01 '24 20:07 StefanOssendorf

Wouldn't it make sense to create a helper class

There is already a Csla.Runtime namespace/directory in the Csla project. It has an IRuntimeInfo service and implementation.

Perhaps that would be the place for any such helper code?

rockfordlhotka avatar Jul 01 '24 20:07 rockfordlhotka

Wouldn't it make sense to create a helper class

There is already a Csla.Runtime namespace/directory in the Csla project. It has an IRuntimeInfo service and implementation.

Perhaps that would be the place for any such helper code?

Even better.

StefanOssendorf avatar Jul 01 '24 21:07 StefanOssendorf

Dataflow analysis work on method body. if we put this If inside helper method, then we have to annotate everything with SupportedPlatform/UnsupportedPlatform

For example

PlatformHelper.ThrowNotSupportedIfBrowser()
// Data flow does not know that all code below unreacheable on browser.
// This will produce warning that WebClient is not supported on the browser platform.
var client = new WebClient();
if (OperatingSystem.IsBrowser())
{
  throw new PlatformNotSupportedException();
}

// Data flow analysis is happy and say hello to you. He knows that this code 
// never reachable on browser.
var client = new WebClient();

kant2002 avatar Jul 02 '24 03:07 kant2002

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

github-actions[bot] avatar Jul 05 '25 00:07 github-actions[bot]