This repository has been archived by the owner on Oct 29, 2024. It is now read-only.
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.
Contributes to #309 (2-4).
This PR has 4 commits, I suggests reviewing them one-by-one, ignoring whitespace changes.
Use Roslyn instead of reflection for Component Generator
This commit updates
ComponentWrapperGenerator
project to use Roslyn instead of reflection. In order to be able to use Roslyn, I create Roslyn Workspace inProgram.cs
.I've tried to preserve the output exactly same as before, and to make as few changes as possible to
ComponentWrapperGenerator.cs
to make review easier.Add Component source generator project
In this commit I moved most of the generator classes to separate project
Microsoft.MobileBlazorBindings.ComponentGenerator
. I've addedSourceGenerator
class, which implementsISourceGenerator
, and invokesComponentWrapperGenerator
for each required type.ComponentWrapperGenerator
class is updated to return(string HintName, string Source)
for generated files instead of writing them to disk.Source generator retrieves settings (namespace, types to generate) from 'component-generator.json' file in the project. Adding nuget dependencies to analyzers/source-generators is a bit troublesome, so I decided to parse json file using couple of regexes (at least for now, when json file is quite simple).
Updated
ComponentWrapperGenerator
project to retain same functionality as before by adding reference toComponentGenerator
project and adding writing files to disk there.Update generator to better support third party components
Minor updates to
ComponentWrapperGenerator
class to better support third party components. Add missing usings, add alias for element's namespace. If generator does not know how to handle property type, and it is not ignored, then it fallbacks to AttributeHelper.ObjectToDelegate / AttributeHelper.DelegateToObject.Add generator to Weather sample
Add project
Microsoft.MobileBlazorBindings.PancakeView.SourceGenerator
, and use generator there to create component wrapper for PancakeView.Note that it is possible to use generator directly in Razor project, but it requires using .NET5 SDK, while MBB requires 3.1 (in global.json).
Naming is a bit confusing now - we have Source Generator project
Microsoft.MobileBlazorBindings.ComponentGenerator
(which should be published to nuget), and console projectComponentWrapperGenerator
(for internal usage, at least for now).Feel free to ask whatever questions you have!
Visual Studio screenshot