I previously wrote on the difficulties of Aspect-Orientation in C#. The addition of Source Generators in C# 9 changes the possibilities considerably.
Source Generators are much more general than just AOP. They are essentially compile-time reflection. They allow us to use our own code (or any resource) as information to generate code. This allows programmers to leverage all kinds of relationships beyond what the language itself can piece together. There is also no significant performance hit, since everything is determined at compile-time.
The Roslyn team has a number of examples including
- Type serializers
- Automatic Diagnostic logging
- Inline table-driven methods and mappings
- Automatic implementations for mechanical interfaces (like INotifyPropertyChanged)
The community has already leveraged generators for relationships like
I also wrote a basic generator for extending property enums.
The same concepts could be applied for fast proxies, which enables AOP concerns like
- Declarative security (perhaps based on a config file)
- Centralized and transparent Retry policies
- Trivial and transparent remote communication wrappers
The authoring experience leaves much to be desired, but I have confidence it will improve over time.
All-in-all I think source generators are a big win for expressive designs in C#!