Skip to content

Generate property accessors in FiggleFonts class#39

Closed
drewnoakes wants to merge 1 commit intomasterfrom
generate-figgle-fonts-class-properties
Closed

Generate property accessors in FiggleFonts class#39
drewnoakes wants to merge 1 commit intomasterfrom
generate-figgle-fonts-class-properties

Conversation

@drewnoakes
Copy link
Copy Markdown
Owner

Uses a T4 template to generate property accessors for bundled fonts. Reduces the chance that this gets out of sync, especially if we add more fonts (#2).

Because several file names are not valid C# identifiers, or because they're really composite names, we add Aliases.csv as a mechanism to override the default name that would otherwise be calculated.


I'm of two minds about this approach. It avoids having to manually keep the file up to date, which is good. It also allows us to do other kinds of generation in future (such as enumerating all fonts without reflection over properties).

The downside is that T4 is a VS-only thing. A source generator would be better, but it feels overkill to make one just for this single usage.

Doing this gave me another idea, which I filed as #38. That idea would be hard to achieve with T4 though.

Uses a T4 template to generate property accessors for bundled fonts. Reduces the chance that this gets out of sync.

Because several file names are not valid C# identifiers, or because they're really composite names, we add `Aliases.csv` as a mechanism to override the default name that would otherwise be calculated.
@drewnoakes drewnoakes requested a review from jonathanou June 6, 2025 01:03
@jonathanou
Copy link
Copy Markdown
Collaborator

I don't think it would be too hard to create an internal source generator to generate the fonts from the csv—we just need to include the csv as an additional file (we could also hardcode the generator to look for Aliases.csv since it's an internal thing).

Using a source generator should then make it easy to also implement #38 which I think is a really cool idea.

Do you mind keeping this PR open while I take a stab at an internal source generator first?

@drewnoakes
Copy link
Copy Markdown
Owner Author

Go for it! I'm not married to this approach and a source generator would be better in every way :)

@drewnoakes
Copy link
Copy Markdown
Owner Author

Obsolete with the superior approach in #41.

@drewnoakes drewnoakes closed this Jun 7, 2025
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.

2 participants