Add ScanStatic
extension method using C# Source Generators
#129
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is just an initial commit, I'm sure there are something things that could be done differently and better.
Basically source generation under the covers emits an extension method that looks a little like...
PopulateExtensions
is also emitted later based on theaction
that was sent to eachScanStatic
method.An example from the initial unit tests is like below. Basically we just piggy back off the fact that
CallerXyz
attributes are emitted at compile time, and we can get those values during source generation as well.The I'm currently using the precedence of
LineNumber
->FilePath
->MemberName
instead ofFilePath
->MemberName
->LineNumber
ScanStatic
will be called from the same file a few different times, requiring two jumps.void A(IServiceCollection services) { services.ScanStatic(z => z.FromAssemblies().AddClasses(); } void B(IServiceCollection services) { services.ScanStatic(z => z.FromAssemblies().AddClasses(); }
all on one line.Assuming all unique line numbers, then we only have to deal with one switch before we start adding services, hopefully this adds as little overhead as possible (compared to full assembly scanning anyway).
<T>
ortypeof()
Let me know what you think!