MarimerLLC / csla

A home for your business logic in any .NET application.
https://cslanet.com
MIT License
1.23k stars 394 forks source link

Mark assembly as supported in the browser #4072

Open kant2002 opened 2 days ago

kant2002 commented 2 days ago

Closes #1894

StefanOssendorf commented 2 days ago

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
  }
}
rockfordlhotka commented 2 days ago

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?

StefanOssendorf commented 1 day ago

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.

kant2002 commented 1 day ago

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();