Description
Background and Motivation
As part of #46227 we are removing the default regex constraint from the set of constraints available when CreateSlimBuilder(...)
is used. The reason for this is that including regular expression support on constraints pulls in about 800K of extra file size. We still include the regex constraint resolver when CreateBuilder(...)
is used.
However ... there is an opportunity for people to continue to use regular expressions for router parameters if they implement their own route constraints and provided they know what the regular expression is in advance they can take advantage of source generated regular expressions. We want an analyzer which detects the use of regex constraints and adds a warning which links to documentation on how to create a custom route constraint that uses source generated regex.
Proposed Analyzer
Analyzer Behavior and Message
When a route pattern is used that includes a regex constraint, we would output the following info message:
INFO: Recommend use of custom reoute constraint with source generated regular expressions. See https://aka.ms/aspet/tba for more details.
Note, if we detect that we are using CreateSlimBuilder (won't always be possible) then we can increase this to a warning?
Category
- Design
- Documentation
- Globalization
- Interoperability
- Maintainability
- Naming
- Performance
- Reliability
- Security
- Style
- Usage
Severity Level
- Error
- Warning
- Info
- Hidden
Usage Scenarios
app.MapGet("/products/{productId:regex(...)}", (string productId) => {});
Risks
To discuss.