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

Add RegexGenerator to System.ComponentModel.TypeConverter. #62325

Merged
merged 8 commits into from
Feb 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions eng/generators.targets
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,19 @@
and @(ProjectReference->AnyHaveMetadataValue('Identity', '$(CoreLibProject)'))))" Include="$(LibrariesProjectRoot)Common\src\System\Runtime\InteropServices\ArrayMarshaller.cs" />
</ItemGroup>

<ItemGroup>
<EnabledGenerators Include="RegexGenerator" Condition="'$(EnableRegexGenerator)' == 'true'" />
Copy link
Member

Choose a reason for hiding this comment

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

@jkoritzinsky what is the reasoning behind having an explicit path and an implicit path for adding the DLLImport generator? Is that reason also applicable to the RegexGenerator? Basically my question is: for the regexgenerator should we just simplify and only enable it whenever EnableRegexGenerator property is set to true?

Copy link
Member

Choose a reason for hiding this comment

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

We needed the ItemGroup-based path to allow us to filter adding the generator ProjectReference based on referenced projects. With MSBuild static graph (which we use for our restore functionality), we can't add a ProjectReference in a target, so we're limited to evaluation time. Since properties are evaluated before items, we needed to do the generator reference add based on an item. The property was added for simplicity.

Once we aren't adding sources to builds (and all of the APIs the generator uses are approved) then we can significantly simplify this file.

Copy link
Member

Choose a reason for hiding this comment

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

@jkoritzinsky it sounds like you wanted to make it automatic always and you see the property as less desirable, where @joperezr was saying the property is simpler. I do think a property is more WYSIWYG, and it seems acceptable for construction of the shared framework where we are more careful about layering/dependencies.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, we wanted to make DllImportGenerator enabled automatically and the property was a fallback. We wanted to enable our generator automatically since we're consuming it throughout the runtime, including CoreLib. @stephentoub expressed a desire for us to enable it for all projects (including tests) and not even having a property for opt-in/out, but until we get all of our APIs approved, that's a little difficult.

</ItemGroup>

<!-- Use this complex ItemGroup-based filtering to add the ProjectReference to make sure dotnet/runtime stays compatible with NuGet Static Graph Restore. -->
<ItemGroup Condition="'@(EnabledGenerators)' != ''
and @(EnabledGenerators->AnyHaveMetadataValue('Identity', 'RegexGenerator'))">
<ProjectReference
Include="$(LibrariesProjectRoot)System.Text.RegularExpressions/gen/System.Text.RegularExpressions.Generator.csproj"
OutputItemType="Analyzer"
ReferenceOutputAssembly="false" />
</ItemGroup>

<Target Name="ConfigureGenerators"
DependsOnTargets="ConfigureDllImportGenerator"
BeforeTargets="CoreCompile" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<IsPartialFacadeAssembly>true</IsPartialFacadeAssembly>
<TargetFrameworks>$(NetCoreAppCurrent)</TargetFrameworks>
<Nullable>enable</Nullable>
<EnableRegexGenerator>true</EnableRegexGenerator>
</PropertyGroup>
<ItemGroup>
<ILLinkSubstitutionsXmls Include="$(ILLinkDirectory)ILLink.Substitutions.xml" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,25 @@ namespace System.ComponentModel.Design
/// <summary>
/// Represents a verb that can be executed by a component's designer.
/// </summary>
public class DesignerVerb : MenuCommand
public partial class DesignerVerb : MenuCommand
{
/// <summary>
/// Initializes a new instance of the <see cref='System.ComponentModel.Design.DesignerVerb'/> class.
/// </summary>
public DesignerVerb(string text, EventHandler handler) : base(handler, StandardCommands.VerbFirst)
{
Properties["Text"] = text == null ? null : Regex.Replace(text, @"\(\&.\)", "");
}
public DesignerVerb(string text, EventHandler handler) : this(text, handler, StandardCommands.VerbFirst) { }

/// <summary>
/// Initializes a new instance of the <see cref='System.ComponentModel.Design.DesignerVerb'/>
/// class.
/// </summary>
public DesignerVerb(string text, EventHandler handler, CommandID startCommandID) : base(handler, startCommandID)
{
Properties["Text"] = text == null ? null : Regex.Replace(text, @"\(\&.\)", "");
Properties["Text"] = text == null ? null : GetParameterReplacementRegex().Replace(text, "");
}

[RegexGenerator(@"\(\&.\)")]
private static partial Regex GetParameterReplacementRegex();

/// <summary>
/// Gets or sets the description of the menu item for the verb.
/// </summary>
Expand Down