Skip to content

Commit a386b60

Browse files
Use auto properties
1 parent eafb789 commit a386b60

37 files changed

+403
-475
lines changed

src/Workspaces/Core/Portable/CodeActions/Operations/OpenDocumentOperation.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,13 @@ namespace Microsoft.CodeAnalysis.CodeActions;
1212
/// </summary>
1313
public sealed class OpenDocumentOperation(DocumentId documentId, bool activateIfAlreadyOpen = false) : CodeActionOperation
1414
{
15-
private readonly DocumentId _documentId = documentId ?? throw new ArgumentNullException(nameof(documentId));
16-
17-
public DocumentId DocumentId => _documentId;
15+
public DocumentId DocumentId { get; } = documentId ?? throw new ArgumentNullException(nameof(documentId));
1816

1917
public override void Apply(Workspace workspace, CancellationToken cancellationToken)
2018
{
2119
if (workspace.CanOpenDocuments)
2220
{
23-
workspace.OpenDocument(_documentId, activateIfAlreadyOpen);
21+
workspace.OpenDocument(DocumentId, activateIfAlreadyOpen);
2422
}
2523
}
2624
}

src/Workspaces/Core/Portable/CodeFixes/CodeFixContext.cs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@ namespace Microsoft.CodeAnalysis.CodeFixes;
1818
/// </summary>
1919
public readonly struct CodeFixContext
2020
{
21-
private readonly TextDocument _document;
22-
private readonly TextSpan _span;
23-
private readonly ImmutableArray<Diagnostic> _diagnostics;
24-
private readonly CancellationToken _cancellationToken;
2521
private readonly Action<CodeAction, ImmutableArray<Diagnostic>> _registerCodeFix;
2622

2723
/// <summary>
@@ -50,23 +46,23 @@ public Document Document
5046
/// code fixes that support non-source documents by providing a non-default value for
5147
/// <see cref="ExportCodeFixProviderAttribute.DocumentKinds"/>
5248
/// </summary>
53-
public TextDocument TextDocument => _document;
49+
public TextDocument TextDocument { get; }
5450

5551
/// <summary>
5652
/// Text span within the <see cref="Document"/> or <see cref="TextDocument"/> to fix.
5753
/// </summary>
58-
public TextSpan Span => _span;
54+
public TextSpan Span { get; }
5955

6056
/// <summary>
6157
/// Diagnostics to fix.
6258
/// NOTE: All the diagnostics in this collection have the same <see cref="Span"/>.
6359
/// </summary>
64-
public ImmutableArray<Diagnostic> Diagnostics => _diagnostics;
60+
public ImmutableArray<Diagnostic> Diagnostics { get; }
6561

6662
/// <summary>
6763
/// CancellationToken.
6864
/// </summary>
69-
public CancellationToken CancellationToken => _cancellationToken;
65+
public CancellationToken CancellationToken { get; }
7066

7167
/// <summary>
7268
/// Creates a code fix context to be passed into <see cref="CodeFixProvider.RegisterCodeFixesAsync(CodeFixContext)"/> method.
@@ -126,11 +122,11 @@ public CodeFixContext(
126122
{
127123
VerifyDiagnosticsArgument(diagnostics, span);
128124

129-
_document = document ?? throw new ArgumentNullException(nameof(document));
130-
_span = span;
131-
_diagnostics = diagnostics;
125+
TextDocument = document ?? throw new ArgumentNullException(nameof(document));
126+
Span = span;
127+
Diagnostics = diagnostics;
132128
_registerCodeFix = registerCodeFix ?? throw new ArgumentNullException(nameof(registerCodeFix));
133-
_cancellationToken = cancellationToken;
129+
CancellationToken = cancellationToken;
134130
}
135131

136132
/// <summary>
@@ -229,7 +225,7 @@ public void RegisterCodeFix(CodeAction action, ImmutableArray<Diagnostic> diagno
229225
throw new ArgumentNullException(nameof(action));
230226
}
231227

232-
VerifyDiagnosticsArgument(diagnostics, _span);
228+
VerifyDiagnosticsArgument(diagnostics, Span);
233229

234230
// TODO:
235231
// - Check that all diagnostics are unique (no duplicates).

src/Workspaces/Core/Portable/CodeStyle/CodeStyleOption.cs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,10 @@ internal interface ICodeStyleOption
2525
/// <inheritdoc cref="CodeStyleOption2{T}"/>
2626
public sealed class CodeStyleOption<T> : ICodeStyleOption, IEquatable<CodeStyleOption<T>>
2727
{
28-
private readonly CodeStyleOption2<T> _codeStyleOptionImpl;
2928
public static CodeStyleOption<T> Default => new(default!, NotificationOption.Silent);
3029

3130
internal CodeStyleOption(CodeStyleOption2<T> codeStyleOptionImpl)
32-
=> _codeStyleOptionImpl = codeStyleOptionImpl;
31+
=> UnderlyingOption = codeStyleOptionImpl;
3332

3433
public CodeStyleOption(T value, NotificationOption notification)
3534
: this(new CodeStyleOption2<T>(value, new NotificationOption2(notification.Severity, IsExplicitlySpecified: false)))
@@ -38,39 +37,39 @@ public CodeStyleOption(T value, NotificationOption notification)
3837

3938
public T Value
4039
{
41-
get => _codeStyleOptionImpl.Value;
40+
get => UnderlyingOption.Value;
4241

4342
[Obsolete("Modifying a CodeStyleOption<T> is not supported.", error: true)]
4443
set => throw new InvalidOperationException();
4544
}
4645

4746
object? ICodeStyleOption.Value => this.Value;
48-
NotificationOption2 ICodeStyleOption.Notification => _codeStyleOptionImpl.Notification;
47+
NotificationOption2 ICodeStyleOption.Notification => UnderlyingOption.Notification;
4948
ICodeStyleOption ICodeStyleOption.WithValue(object value) => new CodeStyleOption<T>((T)value, Notification);
5049
ICodeStyleOption ICodeStyleOption.WithNotification(NotificationOption2 notification) => new CodeStyleOption<T>(Value, (NotificationOption)notification);
5150

5251
public NotificationOption Notification
5352
{
54-
get => (NotificationOption)_codeStyleOptionImpl.Notification;
53+
get => (NotificationOption)UnderlyingOption.Notification;
5554

5655
[Obsolete("Modifying a CodeStyleOption<T> is not supported.", error: true)]
5756
set => throw new InvalidOperationException();
5857
}
5958

60-
internal CodeStyleOption2<T> UnderlyingOption => _codeStyleOptionImpl;
59+
internal CodeStyleOption2<T> UnderlyingOption { get; }
6160

62-
public XElement ToXElement() => _codeStyleOptionImpl.ToXElement();
61+
public XElement ToXElement() => UnderlyingOption.ToXElement();
6362

6463
public static CodeStyleOption<T> FromXElement(XElement element)
6564
=> new(CodeStyleOption2<T>.FromXElement(element));
6665

6766
public bool Equals(CodeStyleOption<T>? other)
68-
=> _codeStyleOptionImpl.Equals(other?._codeStyleOptionImpl);
67+
=> UnderlyingOption.Equals(other?.UnderlyingOption);
6968

7069
public override bool Equals(object? obj)
7170
=> obj is CodeStyleOption<T> option &&
7271
Equals(option);
7372

7473
public override int GetHashCode()
75-
=> _codeStyleOptionImpl.GetHashCode();
74+
=> UnderlyingOption.GetHashCode();
7675
}

src/Workspaces/Core/Portable/Differencing/Edit.cs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ namespace Microsoft.CodeAnalysis.Differencing;
1818
public readonly struct Edit<TNode> : IEquatable<Edit<TNode>>
1919
{
2020
private readonly TreeComparer<TNode> _comparer;
21-
private readonly EditKind _kind;
22-
private readonly TNode _oldNode;
2321
private readonly TNode _newNode;
2422

2523
internal Edit(EditKind kind, TreeComparer<TNode> comparer, TNode oldNode, TNode newNode)
@@ -33,12 +31,12 @@ internal Edit(EditKind kind, TreeComparer<TNode> comparer, TNode oldNode, TNode
3331
!comparer.TreesEqual(oldNode, newNode));
3432

3533
_comparer = comparer;
36-
_kind = kind;
37-
_oldNode = oldNode;
34+
Kind = kind;
35+
OldNode = oldNode;
3836
_newNode = newNode;
3937
}
4038

41-
public EditKind Kind => _kind;
39+
public EditKind Kind { get; }
4240

4341
/// <summary>
4442
/// Insert:
@@ -50,7 +48,7 @@ internal Edit(EditKind kind, TreeComparer<TNode> comparer, TNode oldNode, TNode
5048
/// Move, Update:
5149
/// Node in the old tree/sequence.
5250
/// </summary>
53-
public TNode OldNode => _oldNode;
51+
public TNode OldNode { get; }
5452

5553
/// <summary>
5654
/// Insert:
@@ -69,17 +67,17 @@ public override bool Equals(object obj)
6967

7068
public bool Equals(Edit<TNode> other)
7169
{
72-
return _kind == other._kind
73-
&& (_oldNode == null) ? other._oldNode == null : _oldNode.Equals(other._oldNode)
70+
return Kind == other.Kind
71+
&& (OldNode == null) ? other.OldNode == null : OldNode.Equals(other.OldNode)
7472
&& (_newNode == null) ? other._newNode == null : _newNode.Equals(other._newNode);
7573
}
7674

7775
public override int GetHashCode()
7876
{
79-
var hash = (int)_kind;
80-
if (_oldNode != null)
77+
var hash = (int)Kind;
78+
if (OldNode != null)
8179
{
82-
hash = Hash.Combine(_oldNode.GetHashCode(), hash);
80+
hash = Hash.Combine(OldNode.GetHashCode(), hash);
8381
}
8482

8583
if (_newNode != null)
@@ -97,17 +95,17 @@ internal string GetDebuggerDisplay()
9795
switch (Kind)
9896
{
9997
case EditKind.Delete:
100-
return result + " [" + _oldNode.ToString() + "]" + DisplayPosition(_oldNode);
98+
return result + " [" + OldNode.ToString() + "]" + DisplayPosition(OldNode);
10199

102100
case EditKind.Insert:
103101
return result + " [" + _newNode.ToString() + "]" + DisplayPosition(_newNode);
104102

105103
case EditKind.Update:
106-
return result + " [" + _oldNode.ToString() + "]" + DisplayPosition(_oldNode) + " -> [" + _newNode.ToString() + "]" + DisplayPosition(_newNode);
104+
return result + " [" + OldNode.ToString() + "]" + DisplayPosition(OldNode) + " -> [" + _newNode.ToString() + "]" + DisplayPosition(_newNode);
107105

108106
case EditKind.Move:
109107
case EditKind.Reorder:
110-
return result + " [" + _oldNode.ToString() + "]" + DisplayPosition(_oldNode) + " -> " + DisplayPosition(_newNode);
108+
return result + " [" + OldNode.ToString() + "]" + DisplayPosition(OldNode) + " -> " + DisplayPosition(_newNode);
111109
}
112110

113111
return result;

src/Workspaces/Core/Portable/Differencing/EditScript.cs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,11 @@ namespace Microsoft.CodeAnalysis.Differencing;
1515
/// </summary>
1616
public sealed partial class EditScript<TNode>
1717
{
18-
private readonly Match<TNode> _match;
1918
private readonly ImmutableArray<Edit<TNode>> _edits;
2019

2120
internal EditScript(Match<TNode> match)
2221
{
23-
_match = match;
22+
Match = match;
2423

2524
var edits = new List<Edit<TNode>>();
2625
AddUpdatesInsertsMoves(edits);
@@ -31,13 +30,13 @@ internal EditScript(Match<TNode> match)
3130

3231
public ImmutableArray<Edit<TNode>> Edits => _edits;
3332

34-
public Match<TNode> Match => _match;
33+
public Match<TNode> Match { get; }
3534

36-
private TreeComparer<TNode> Comparer => _match.Comparer;
35+
private TreeComparer<TNode> Comparer => Match.Comparer;
3736

38-
private TNode Root1 => _match.OldRoot;
37+
private TNode Root1 => Match.OldRoot;
3938

40-
private TNode Root2 => _match.NewRoot;
39+
private TNode Root2 => Match.NewRoot;
4140

4241
private void AddUpdatesInsertsMoves(List<Edit<TNode>> edits)
4342
{
@@ -86,7 +85,7 @@ private void ProcessNode(List<Edit<TNode>> edits, TNode x)
8685
//
8786
// NOTE:
8887
// If we needed z then we would need to be updating M' as we encounter insertions.
89-
var hasPartner = _match.TryGetPartnerInTree1(x, out var w);
88+
var hasPartner = Match.TryGetPartnerInTree1(x, out var w);
9089
var hasParent = Comparer.TryGetParent(x, out var y);
9190

9291
if (!hasPartner)
@@ -120,7 +119,7 @@ private void ProcessNode(List<Edit<TNode>> edits, TNode x)
120119
// If parents of w and x don't match, it's a move.
121120
// iii. if not (v, y) in M'
122121
// NOTE: The paper says (y, v) but that seems wrong since M': T1 -> T2 and w,v in T1 and x,y in T2.
123-
if (!_match.Contains(v, y))
122+
if (!Match.Contains(v, y))
124123
{
125124
// A. Let z be the partner of y in M'. (NOTE: z not needed)
126125
// B. k := FindPos(x)
@@ -154,7 +153,7 @@ private void AddDeletes(List<Edit<TNode>> edits)
154153

155154
foreach (var w in Comparer.GetDescendants(Root1))
156155
{
157-
if (!_match.HasPartnerInTree2(w))
156+
if (!Match.HasPartnerInTree2(w))
158157
{
159158
edits.Add(new Edit<TNode>(EditKind.Delete, Comparer, oldNode: w, newNode: default));
160159
}
@@ -183,7 +182,7 @@ private void AlignChildren(List<Edit<TNode>> edits, TNode w, TNode x)
183182
List<TNode> s1 = null;
184183
foreach (var e in wChildren)
185184
{
186-
if (_match.TryGetPartnerInTree2(e, out var pw) && Comparer.GetParent(pw).Equals(x))
185+
if (Match.TryGetPartnerInTree2(e, out var pw) && Comparer.GetParent(pw).Equals(x))
187186
{
188187
s1 ??= [];
189188

@@ -194,7 +193,7 @@ private void AlignChildren(List<Edit<TNode>> edits, TNode w, TNode x)
194193
List<TNode> s2 = null;
195194
foreach (var e in xChildren)
196195
{
197-
if (_match.TryGetPartnerInTree1(e, out var px) && Comparer.GetParent(px).Equals(w))
196+
if (Match.TryGetPartnerInTree1(e, out var px) && Comparer.GetParent(px).Equals(w))
198197
{
199198
s2 ??= [];
200199

@@ -210,7 +209,7 @@ private void AlignChildren(List<Edit<TNode>> edits, TNode w, TNode x)
210209
// Step 3, 4
211210
// Define the function Equal(a,b) to be true if and only if (a,c) in M'
212211
// Let S <- LCS(S1, S2, Equal)
213-
var lcs = new Match<TNode>.LongestCommonSubsequence(_match);
212+
var lcs = new Match<TNode>.LongestCommonSubsequence(Match);
214213
var s = lcs.GetMatchingNodes(s1, s2);
215214

216215
// Step 5
@@ -229,7 +228,7 @@ private void AlignChildren(List<Edit<TNode>> edits, TNode w, TNode x)
229228
// (a,b) in M
230229
// => b in S2 since S2 == { b | parent(b) == x && parent(partner(b)) == w }
231230
// (a,b) not in S
232-
if (_match.TryGetPartnerInTree2(a, out var b) &&
231+
if (Match.TryGetPartnerInTree2(a, out var b) &&
233232
Comparer.GetParent(b).Equals(x) &&
234233
!ContainsPair(s, a, b))
235234
{

0 commit comments

Comments
 (0)