-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[XSG] Simplify ColorConverter #31660
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
base: net10.0
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR simplifies the ColorConverter source generator by leveraging the existing Color.TryParse
method instead of maintaining custom parsing logic. The change eliminates redundant code that was reimplementing color format support.
- Removes 60+ lines of custom color parsing logic including regex patterns and named color constants
- Replaces multiple parsing approaches with a single
Color.TryParse
call - Updates generated code to use optimized float constructor with invariant formatting
|
||
<ItemGroup> | ||
<ProjectReference Include="..\BindingSourceGen\Controls.BindingSourceGen.csproj" /> | ||
<ProjectReference Include="..\..\..\Graphics\src\Graphics\Graphics.csproj" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nope
we don't want to have dependencies. can we replace that with a Compile-Include ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to do this real quick and it turns out to be challenging because Color.cs
as is pulls in a bunch of other classes and one of them requires MathF which is not netstandard2.0. I will look into this tomorrow and I'll see if I can easily move the parsing logic to a separate file which could be shared between the two projects.
Description of Change
Color.TryParse already implements all the supported formats, no need to reinvent the wheel. Also, the compiled value uses the most optimal constructor - all floats.
This PR:
Color
toColorUtils
so that it can be easily shared between Graphics and SourceGen projectsColors
class