Description
Follow-up from the review of #130415 (#130415 (comment)).
That PR escapes keyword identifiers in member-access position and in model type FQNs, but the validator's namespace still flows into the generated code unescaped. ValidatorType.Namespace is built from ContainingNamespace.ToString() (Parser.cs, both for declared validators and in AddSynthesizedValidator), which does not escape keyword segments.
So an [OptionsValidator] type declared in a namespace containing a keyword segment, e.g.:
namespace @class.Options
{
[OptionsValidator]
public partial class MyOptionsValidator : IValidateOptions<MyOptions>;
}
still generates namespace class.Options { ... }, which does not compile. The same unescaped string is also used to build references to synthesized validators (global:: + Namespace + . + Name), so those call sites are affected the same way when a model type lives in such a namespace.
Expected behavior
Generated code compiles; keyword namespace segments are emitted with @ escaping (e.g. namespace @class.Options), for both the namespace declaration and synthesized validator references.
Notes
Description
Follow-up from the review of #130415 (#130415 (comment)).
That PR escapes keyword identifiers in member-access position and in model type FQNs, but the validator's namespace still flows into the generated code unescaped.
ValidatorType.Namespaceis built fromContainingNamespace.ToString()(Parser.cs, both for declared validators and inAddSynthesizedValidator), which does not escape keyword segments.So an
[OptionsValidator]type declared in a namespace containing a keyword segment, e.g.:still generates
namespace class.Options { ... }, which does not compile. The same unescaped string is also used to build references to synthesized validators (global:: + Namespace + . + Name), so those call sites are affected the same way when a model type lives in such a namespace.Expected behavior
Generated code compiles; keyword namespace segments are emitted with
@escaping (e.g.namespace @class.Options), for both the namespace declaration and synthesized validator references.Notes
options.{vm.Name}member accesses, that can be folded into this work as well.