Partial properties are destined for support in C# 13. When that happens, we should utilize them in the regex generator (we wanted this experience from the get-go).
This will entail:
- Updating
GeneratedRegexAttribute to target properties:
-[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
+[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, AllowMultiple = false, Inherited = false)]
public sealed class GeneratedRegexAttribute : Attribute
- Updating the generator to support instance and static get-only properties, e.g. if a user writes:
[GeneratedRegex("...")]
private partial Regex MyProp1 { get; }
[GeneratedRegex("...")]
public static partial Regex MyProp2 { get; }
the generator emits:
private partial global::System.Text.RegularExpressions.Regex MyProp1 => global::System.Text.RegularExpressions.Generated.MyProp1_0.Instance;
public static partial global::System.Text.RegularExpressions.Regex MyProp2 => global::System.Text.RegularExpressions.Generated.MyProp2_0.Instance;
We will only support get-only auto props. Others will result in an error diagnostic.
Partial properties are destined for support in C# 13. When that happens, we should utilize them in the regex generator (we wanted this experience from the get-go).
This will entail:
GeneratedRegexAttributeto target properties:the generator emits:
We will only support get-only auto props. Others will result in an error diagnostic.