Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Source generator for better access of members from inherited components #1272

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

frosch95
Copy link

@frosch95 frosch95 commented Oct 5, 2023

A new source generator generates a partial class with all the inherited interfaces for a INukeBuild class.

The generator searches for all desendants from INukeBuilder that are:

  • a class
  • not abstract
  • partial

The generator creates a new partial class with all the interfaces (except INukeBuild) as property and respects the accessibility.

I confirm that the pull-request:

  • Follows the contribution guidelines
  • Is based on my own work
  • Is in compliance with my employer

@matkoch
Copy link
Member

matkoch commented Nov 19, 2023

Could you improve this to use SyntaxFactory?

continue;

// must be partial
if (!type.DeclaringSyntaxReferences.Any(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although build projects are probably small in size, GetSyntax is potentially expensive. Couldn't an optimization just check for DeclaringSyntaxReferences.Count to be greater 1 ?

foreach (var type in allTypes)
{
// must be a class
if (type.TypeKind != TypeKind.Class)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd move out all the filtering (class, INukeBuild, partial) to a relevantTypes variable.


internal partial class Build
{
protected IDisposable IDisposable => this;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not clear to me why IDisposable should show up here. I'd filter to interfaces that implement INukeBuild.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I didn't understood the issue correctly.

I thought each class (like Build) that inherits from INukeBuild should have all interfaces (no matter what they are inheriting) as members.

But maybe what you are expecting is that the IHazRepository of the example inherits INukeBuild and that is the reason, why IHazRepository should be a member of the Build class.

If this is the case, this wasn't clear to me, as I thought the INukeBuild is a marker for the Build class.

Maybe, you can extend the example and the description a little bit :-)

@matkoch
Copy link
Member

matkoch commented Nov 19, 2023

Left a couple of comments. Sorry, it's not as easy/straightforward as I thought (considering I added the good first-timer tag).

@frosch95
Copy link
Author

Left a couple of comments. Sorry, it's not as easy/straightforward as I thought (considering I added the good first-timer tag).

No problem, I will have a look in the next view days :-)

@matkoch matkoch force-pushed the develop branch 5 times, most recently from 0231425 to d806295 Compare December 15, 2023 23:12
@matkoch matkoch force-pushed the develop branch 3 times, most recently from 7066bbe to 985de83 Compare January 17, 2024 17:25
@matkoch matkoch force-pushed the develop branch 4 times, most recently from 0719711 to 6fe1e3b Compare March 20, 2024 01:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants