79540253

Date: 2025-03-28 00:05:54
Score: 2.5
Natty:
Report link

Yes you can. Making the attribute is easy enough.

The tricky part is telling Visual Studio (or Rider or whatever IDE) what to inform the user when a class is found that will need to implement the method in future versions. You can do this with Roslyn analysers. You can even, optionally, make a "code fix" to automatically suggest a default implementation of the member. Roslyn isn't easy in my experience, but there is a good tutorial to get started here:

https://learn.microsoft.com/en-us/dotnet/csharp/roslyn-sdk/tutorials/how-to-write-csharp-analyzer-code-fix

And a video series here.

https://youtube.com/playlist?list=PLmoVFE4i0sTXwx750dJbWE577uWmEGVxY&si=9UGQIhbESMjdQ4TR

Before you start though, you should consider how this analyser will get deployed to the consumer of your library. I guess you'll bundle the analyser into a Nuget package that also contains your regular library. But that will be finicky so make a proof of concept of that part first before you put lots of effort into building the bit that analyses syntax and symbols and outputs the diagnostic.

The effort involved in that proof of concept will inform whether you want to go ahead.

Reasons:
  • Blacklisted phrase (1): youtube.com
  • Blacklisted phrase (1.5): a good tutorial
  • Long answer (-0.5):
  • No code block (0.5):
Posted by: benjamin