Skip to content

Conversation

simonrozsival
Copy link
Member

@simonrozsival simonrozsival commented Sep 17, 2025

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:

  • moves parsing and conversion logic from Color to ColorUtils so that it can be easily shared between Graphics and SourceGen projects
  • simplifies the source gen color converter by using ColorUtils + instead of keeping its own list of known colors, it scans the static fields of the Colors class

@Copilot Copilot AI review requested due to automatic review settings September 17, 2025 16:19
@simonrozsival simonrozsival added the area-xaml XAML, CSS, Triggers, Behaviors label Sep 17, 2025
Copy link
Contributor

@Copilot Copilot AI left a 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" />
Copy link
Contributor

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 ?

Copy link
Member Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-xaml XAML, CSS, Triggers, Behaviors
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants