Skip to content

Commit 5758964

Browse files
authored
Use InterceptorsNamespaces feature name instead of InterceptorsPreviewNamespaces (#74865)
1 parent 7c7a412 commit 5758964

27 files changed

+166
-114
lines changed

docs/features/interceptors.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -218,12 +218,14 @@ There is an experimental public API `GetInterceptorMethod(this SemanticModel, In
218218
219219
### User opt-in
220220

221-
To use interceptors, the user project must specify the property `<InterceptorsPreviewNamespaces>`. This is a list of namespaces which are allowed to contain interceptors.
221+
To use interceptors, the user project must specify the property `<InterceptorsNamespaces>`. This is a list of namespaces which are allowed to contain interceptors.
222222
```xml
223-
<InterceptorsPreviewNamespaces>$(InterceptorsPreviewNamespaces);Microsoft.AspNetCore.Http.Generated;MyLibrary.Generated</InterceptorsPreviewNamespaces>
223+
<InterceptorsNamespaces>$(InterceptorsNamespaces);Microsoft.AspNetCore.Http.Generated;MyLibrary.Generated</InterceptorsNamespaces>
224224
```
225225

226-
It's expected that each entry in the `InterceptorsPreviewNamespaces` list roughly corresponds to one source generator. Well-behaved components are expected to not insert interceptors into namespaces they do not own.
226+
It's expected that each entry in the `InterceptorsNamespaces` list roughly corresponds to one source generator. Well-behaved components are expected to not insert interceptors into namespaces they do not own.
227+
228+
For compatibility, the property `<InterceptorsPreviewNamespaces>` can be used as an alias for `<InterceptorsNamespaces>`. If both properties have non-empty values, they will be concatenated together in the order `$(InterceptorsNamespaces);$(InterceptorsPreviewNamespaces)` when passed to the compiler.
227229

228230
### Implementation strategy
229231

src/Compilers/CSharp/Portable/CSharpParseOptions.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public sealed class CSharpParseOptions : ParseOptions, IEquatable<CSharpParseOpt
2222
public static CSharpParseOptions Default { get; } = new CSharpParseOptions();
2323

2424
private ImmutableDictionary<string, string> _features;
25-
private ImmutableArray<ImmutableArray<string>> _interceptorsPreviewNamespaces;
25+
private ImmutableArray<ImmutableArray<string>> _interceptorsNamespaces;
2626

2727
/// <summary>
2828
/// Gets the effective language version, which the compiler uses to select the
@@ -177,21 +177,21 @@ public override IReadOnlyDictionary<string, string> Features
177177
}
178178
}
179179

180-
internal ImmutableArray<ImmutableArray<string>> InterceptorsPreviewNamespaces
180+
internal ImmutableArray<ImmutableArray<string>> InterceptorsNamespaces
181181
{
182182
get
183183
{
184-
if (!_interceptorsPreviewNamespaces.IsDefault)
184+
if (!_interceptorsNamespaces.IsDefault)
185185
{
186-
return _interceptorsPreviewNamespaces;
186+
return _interceptorsNamespaces;
187187
}
188188

189189
// e.g. [["System", "Threading"], ["System", "Collections"]]
190-
ImmutableArray<ImmutableArray<string>> previewNamespaces = Features.TryGetValue("InterceptorsPreviewNamespaces", out var namespaces) && namespaces.Length > 0
190+
ImmutableArray<ImmutableArray<string>> previewNamespaces = Features.TryGetValue("InterceptorsNamespaces", out var namespaces) && namespaces.Length > 0
191191
? makeNamespaces(namespaces)
192192
: ImmutableArray<ImmutableArray<string>>.Empty;
193193

194-
ImmutableInterlocked.InterlockedInitialize(ref _interceptorsPreviewNamespaces, previewNamespaces);
194+
ImmutableInterlocked.InterlockedInitialize(ref _interceptorsNamespaces, previewNamespaces);
195195
return previewNamespaces;
196196

197197
static ImmutableArray<ImmutableArray<string>> makeNamespaces(string namespaces)

src/Compilers/CSharp/Portable/CSharpResources.resx

+1-1
Original file line numberDiff line numberDiff line change
@@ -7609,7 +7609,7 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ
76097609
<value>A switch expression arm does not begin with a 'case' keyword.</value>
76107610
</data>
76117611
<data name="ERR_InterceptorsFeatureNotEnabled" xml:space="preserve">
7612-
<value>The 'interceptors' experimental feature is not enabled in this namespace. Add '{0}' to your project.</value>
7612+
<value>The 'interceptors' feature is not enabled in this namespace. Add '{0}' to your project.</value>
76137613
</data>
76147614
<data name="ERR_InterceptorGlobalNamespace" xml:space="preserve">
76157615
<value>An interceptor cannot be declared in the global namespace.</value>

src/Compilers/CSharp/Portable/CommandLine/CSharpCommandLineParser.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ internal sealed override CommandLineArguments CommonParse(IEnumerable<string> ar
267267
}
268268
else
269269
{
270-
// When a features value like "InterceptorsPreviewNamespaces=NS1;NS2" is provided,
270+
// When a features value like "InterceptorsNamespaces=NS1;NS2" is provided,
271271
// the build system will quote it so that splitting doesn't occur in the wrong layer.
272272
// We need to unquote here so that subsequent layers can properly identify the feature name and value.
273273
features.Add(value.Unquote());

src/Compilers/CSharp/Portable/Symbols/Source/SourceMethodSymbolWithAttributes.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1020,7 +1020,7 @@ private void DecodeInterceptsLocationChecksumBased(DecodeWellKnownAttributeArgum
10201020
return;
10211021
}
10221022

1023-
var interceptorsNamespaces = ((CSharpParseOptions)attributeNameSyntax.SyntaxTree.Options).InterceptorsPreviewNamespaces;
1023+
var interceptorsNamespaces = ((CSharpParseOptions)attributeNameSyntax.SyntaxTree.Options).InterceptorsNamespaces;
10241024
var thisNamespaceNames = getNamespaceNames(this);
10251025
var foundAnyMatch = interceptorsNamespaces.Any(static (ns, thisNamespaceNames) => isDeclaredInNamespace(thisNamespaceNames, ns), thisNamespaceNames);
10261026
if (!foundAnyMatch)
@@ -1149,7 +1149,7 @@ static void reportFeatureNotEnabled(BindingDiagnosticBag diagnostics, Location a
11491149
}
11501150
else
11511151
{
1152-
var recommendedProperty = $"<InterceptorsPreviewNamespaces>$(InterceptorsPreviewNamespaces);{string.Join(".", namespaceNames)}</InterceptorsPreviewNamespaces>";
1152+
var recommendedProperty = $"<InterceptorsNamespaces>$(InterceptorsNamespaces);{string.Join(".", namespaceNames)}</InterceptorsNamespaces>";
11531153
diagnostics.Add(ErrorCode.ERR_InterceptorsFeatureNotEnabled, attributeLocation, recommendedProperty);
11541154
}
11551155
}
@@ -1170,7 +1170,7 @@ private void DecodeInterceptsLocationAttributeExperimentalCompat(
11701170
const int lineNumberParameterIndex = 1;
11711171
const int characterNumberParameterIndex = 2;
11721172

1173-
var interceptorsNamespaces = ((CSharpParseOptions)attributeSyntax.SyntaxTree.Options).InterceptorsPreviewNamespaces;
1173+
var interceptorsNamespaces = ((CSharpParseOptions)attributeSyntax.SyntaxTree.Options).InterceptorsNamespaces;
11741174
var thisNamespaceNames = getNamespaceNames();
11751175
var foundAnyMatch = interceptorsNamespaces.Any(ns => isDeclaredInNamespace(thisNamespaceNames, ns));
11761176
if (!foundAnyMatch)
@@ -1362,7 +1362,7 @@ static void reportFeatureNotEnabled(BindingDiagnosticBag diagnostics, AttributeS
13621362
}
13631363
else
13641364
{
1365-
var recommendedProperty = $"<InterceptorsPreviewNamespaces>$(InterceptorsPreviewNamespaces);{string.Join(".", namespaceNames)}</InterceptorsPreviewNamespaces>";
1365+
var recommendedProperty = $"<InterceptorsNamespaces>$(InterceptorsNamespaces);{string.Join(".", namespaceNames)}</InterceptorsNamespaces>";
13661366
diagnostics.Add(ErrorCode.ERR_InterceptorsFeatureNotEnabled, attributeSyntax, recommendedProperty);
13671367
}
13681368
}

src/Compilers/CSharp/Portable/Symbols/Source/SourceModuleSymbol.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ void discoverInterceptors()
343343
var toVisit = ArrayBuilder<NamespaceOrTypeSymbol>.GetInstance();
344344

345345
// Search the namespaces which were indicated to contain interceptors.
346-
ImmutableArray<ImmutableArray<string>> interceptorsNamespaces = ((CSharpParseOptions)location.SourceTree.Options).InterceptorsPreviewNamespaces;
346+
ImmutableArray<ImmutableArray<string>> interceptorsNamespaces = ((CSharpParseOptions)location.SourceTree.Options).InterceptorsNamespaces;
347347
foreach (ImmutableArray<string> namespaceParts in interceptorsNamespaces)
348348
{
349349
if (namespaceParts is ["global"])

src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)