csla
csla copied to clipboard
Create analyzer to ensure ObjectAuthorizationRules method is public
The Blazor wasm linker totally removes private static methods that aren't directly invoked in your code.
In the past, the per-type rules have been added using a private static method, and that method is now entirely removed before the code executes on the client, meaning that this method must now be public static.
For example:
[ObjectAuthorizationRules]
public static void AddPerTypeRules()
The alternative is that everyone creating a business library would need to create a linker xml file and explicitly list each of these methods to prevent the linker from removing them. That seems pretty impractical.
It might also be good for the analyzer to add
[EditorBrowsable(EditorBrowsableState.Never)]
to the method. Though in my case I have intellisense configured to always show all methods, so this has no effect, but maybe for some people it would be useful?
Creating this analyzer should be straightforward.
One idea to consider is that I think source generators can generate anything, not just C# code. So it may be possible for a SG to create a linker file for all the methods marked with [ObjectAuthorizationRules]. I'm not sure how that linker file is included in the .csproj file, so that may be a bit of a challenge if the linker needs it to be specified somehow in the project file.
Using a SG would be a .NET 5-only thing though.