Skip to content

Commit 78d6908

Browse files
Use 'field'
1 parent 0a0d8ce commit 78d6908

File tree

3 files changed

+6
-8
lines changed

3 files changed

+6
-8
lines changed

src/Workspaces/Core/Portable/Recommendations/AbstractRecommendationService.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5+
using System;
56
using System.Collections.Generic;
67
using System.Collections.Immutable;
78
using System.Linq;
@@ -108,7 +109,7 @@ internal bool ShouldIncludeSymbol(ISymbol symbol)
108109
return symbol.IsOrContainsAccessibleAttribute(
109110
_context.SemanticModel.GetEnclosingNamedType(_context.LeftToken.SpanStart, _cancellationToken)!,
110111
_context.SemanticModel.Compilation.Assembly,
111-
_context.ValidAttributeTargets,
112+
_context.ValidAttributeTargets ?? AttributeTargets.All,
112113
_cancellationToken);
113114
}
114115

src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/Extensions/ContextQuery/CSharpSyntaxContext.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ internal sealed class CSharpSyntaxContext : SyntaxContext
4747

4848
public readonly ISet<SyntaxKind> PrecedingModifiers;
4949

50-
private AttributeTargets? _lazyValidAttributeTargets;
51-
5250
private CSharpSyntaxContext(
5351
Document document,
5452
SemanticModel semanticModel,
@@ -516,7 +514,7 @@ private static bool ComputeIsAwaitKeywordContext(
516514
return false;
517515
}
518516

519-
public override AttributeTargets ValidAttributeTargets => _lazyValidAttributeTargets ??= ComputeValidAttributeTargets();
517+
public override AttributeTargets? ValidAttributeTargets => field ??= ComputeValidAttributeTargets();
520518

521519
private AttributeTargets ComputeValidAttributeTargets()
522520
{

src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Extensions/ContextQuery/SyntaxContext.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,10 @@ internal abstract class SyntaxContext(
9898
public ImmutableArray<ITypeSymbol> InferredTypes { get; } = document.GetRequiredLanguageService<ITypeInferenceService>().InferTypes(semanticModel, position, cancellationToken);
9999

100100
/// <summary>
101-
/// Gets the valid attribute targets for the current attribute context.
102-
/// Returns <see cref="AttributeTargets.All"/> if not in an attribute context or if language-specific
103-
/// filtering is not implemented.
101+
/// Gets the valid attribute targets for the current attribute context. Returns <see langword="null"/> if not in an
102+
/// attribute context or if language-specific filtering is not implemented.
104103
/// </summary>
105-
public virtual AttributeTargets ValidAttributeTargets => AttributeTargets.All;
104+
public virtual AttributeTargets? ValidAttributeTargets => null;
106105

107106
public TService? GetLanguageService<TService>() where TService : class, ILanguageService
108107
=> Document.GetLanguageService<TService>();

0 commit comments

Comments
 (0)