Skip to content

Commit 7fdc18e

Browse files
authored
Merge pull request #309 from CommunityToolkit/dev/fix-fields-this-qualifier
Add "this." prefix to all field accesses
2 parents a872a43 + 03644c9 commit 7fdc18e

File tree

23 files changed

+87
-87
lines changed

23 files changed

+87
-87
lines changed

.editorconfig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:silent
6262
dotnet_style_parentheses_in_other_operators = never_if_unnecessary:silent
6363
dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:silent
6464

65-
# Modifier preferences
66-
dotnet_style_require_accessibility_modifiers = for_non_interface_members:warning
65+
# Modifier preferences (set to silent until https://github.com/dotnet/roslyn/issues/52904 is resolved)
66+
dotnet_style_require_accessibility_modifiers = for_non_interface_members:silent
6767

6868
# Code block preferences
6969
dotnet_style_allow_multiple_blank_lines_experimental = false:warning

CommunityToolkit.Common/Deferred/DeferredEventArgs.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,19 @@ public class DeferredEventArgs : EventArgs
1919
/// </summary>
2020
public static new DeferredEventArgs Empty => new();
2121

22-
private readonly object _eventDeferralLock = new();
22+
private readonly object eventDeferralLock = new();
2323

24-
private EventDeferral? _eventDeferral;
24+
private EventDeferral? eventDeferral;
2525

2626
/// <summary>
2727
/// Returns an <see cref="EventDeferral"/> which can be completed when deferred event is ready to continue.
2828
/// </summary>
2929
/// <returns><see cref="EventDeferral"/> instance.</returns>
3030
public EventDeferral GetDeferral()
3131
{
32-
lock (_eventDeferralLock)
32+
lock (this.eventDeferralLock)
3333
{
34-
return _eventDeferral ??= new EventDeferral();
34+
return this.eventDeferral ??= new EventDeferral();
3535
}
3636
}
3737

@@ -45,11 +45,11 @@ public EventDeferral GetDeferral()
4545
[Obsolete("This is an internal only method to be used by EventHandler extension classes, public callers should call GetDeferral() instead.")]
4646
public EventDeferral? GetCurrentDeferralAndReset()
4747
{
48-
lock (_eventDeferralLock)
48+
lock (this.eventDeferralLock)
4949
{
50-
EventDeferral? eventDeferral = _eventDeferral;
50+
EventDeferral? eventDeferral = this.eventDeferral;
5151

52-
_eventDeferral = null;
52+
this.eventDeferral = null;
5353

5454
return eventDeferral;
5555
}

CommunityToolkit.Common/Deferred/EventDeferral.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ namespace CommunityToolkit.Common.Deferred;
1616
/// </summary>
1717
public class EventDeferral : IDisposable
1818
{
19-
//// TODO: If/when .NET 6 is base, we can upgrade to non-generic version
20-
private readonly TaskCompletionSource<object?> _taskCompletionSource = new();
19+
// TODO: If/when .NET 6 is base, we can upgrade to non-generic version
20+
private readonly TaskCompletionSource<object?> taskCompletionSource = new();
2121

2222
internal EventDeferral()
2323
{
@@ -26,7 +26,7 @@ internal EventDeferral()
2626
/// <summary>
2727
/// Call when finished with the Deferral.
2828
/// </summary>
29-
public void Complete() => _taskCompletionSource.TrySetResult(null);
29+
public void Complete() => this.taskCompletionSource.TrySetResult(null);
3030

3131
/// <summary>
3232
/// Waits for the <see cref="EventDeferral"/> to be completed by the event handler.
@@ -38,9 +38,9 @@ internal EventDeferral()
3838
[Obsolete("This is an internal only method to be used by EventHandler extension classes, public callers should call GetDeferral() instead on the DeferredEventArgs.")]
3939
public async Task WaitForCompletion(CancellationToken cancellationToken)
4040
{
41-
using (cancellationToken.Register(() => _taskCompletionSource.TrySetCanceled()))
41+
using (cancellationToken.Register(() => this.taskCompletionSource.TrySetCanceled()))
4242
{
43-
_ = await _taskCompletionSource.Task;
43+
_ = await this.taskCompletionSource.Task;
4444
}
4545
}
4646

CommunityToolkit.HighPerformance/Buffers/SpanOwner{T}.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public Span<T> Span
142142
get
143143
{
144144
#if NETCOREAPP3_1_OR_GREATER
145-
ref T r0 = ref array!.DangerousGetReference();
145+
ref T r0 = ref this.array!.DangerousGetReference();
146146

147147
return MemoryMarshal.CreateSpan(ref r0, this.length);
148148
#else
@@ -174,7 +174,7 @@ public ref T DangerousGetReference()
174174
[MethodImpl(MethodImplOptions.AggressiveInlining)]
175175
public ArraySegment<T> DangerousGetArray()
176176
{
177-
return new(array!, 0, this.length);
177+
return new(this.array!, 0, this.length);
178178
}
179179

180180
/// <summary>

CommunityToolkit.HighPerformance/Enumerables/RefEnumerable{T}.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ public readonly ref struct RefEnumerable<T>
5555
[MethodImpl(MethodImplOptions.AggressiveInlining)]
5656
internal RefEnumerable(ref T reference, int length, int step)
5757
{
58-
Span = MemoryMarshal.CreateSpan(ref reference, length);
59-
Step = step;
58+
this.Span = MemoryMarshal.CreateSpan(ref reference, length);
59+
this.Step = step;
6060
}
6161

6262
/// <summary>
@@ -94,10 +94,11 @@ public static RefEnumerable<T> DangerousCreate(ref T value, int length, int step
9494
[MethodImpl(MethodImplOptions.AggressiveInlining)]
9595
internal RefEnumerable(object? instance, IntPtr offset, int length, int step)
9696
{
97-
Instance = instance;
98-
Offset = offset;
97+
this.Instance = instance;
98+
this.Offset = offset;
99+
this.Step = step;
100+
99101
Length = length;
100-
Step = step;
101102
}
102103
#endif
103104

CommunityToolkit.HighPerformance/NullableRef{T}.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public readonly ref struct NullableRef<T>
3232
[MethodImpl(MethodImplOptions.AggressiveInlining)]
3333
public NullableRef(ref T value)
3434
{
35-
Span = MemoryMarshal.CreateSpan(ref value, 1);
35+
this.Span = MemoryMarshal.CreateSpan(ref value, 1);
3636
}
3737

3838
/// <summary>
@@ -42,7 +42,7 @@ public NullableRef(ref T value)
4242
[MethodImpl(MethodImplOptions.AggressiveInlining)]
4343
private NullableRef(Span<T> span)
4444
{
45-
Span = span;
45+
this.Span = span;
4646
}
4747

4848
/// <summary>
@@ -69,7 +69,7 @@ public unsafe bool HasValue
6969
// also account for the byte endianness of the current system),
7070
// and then reinterpret that value to a bool flag.
7171
// This results in a single movzx instruction on x86-64.
72-
byte length = unchecked((byte)Span.Length);
72+
byte length = unchecked((byte)this.Span.Length);
7373

7474
return *(bool*)&length;
7575
}
@@ -89,7 +89,7 @@ public ref T Value
8989
ThrowInvalidOperationException();
9090
}
9191

92-
return ref MemoryMarshal.GetReference(Span);
92+
return ref MemoryMarshal.GetReference(this.Span);
9393
}
9494
}
9595

CommunityToolkit.HighPerformance/ReadOnlyRef{T}.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public ReadOnlyRef(in T value)
3737
{
3838
ref T r0 = ref Unsafe.AsRef(value);
3939

40-
Span = MemoryMarshal.CreateReadOnlySpan(ref r0, 1);
40+
this.Span = MemoryMarshal.CreateReadOnlySpan(ref r0, 1);
4141
}
4242

4343
/// <summary>
@@ -56,7 +56,7 @@ public unsafe ReadOnlyRef(void* pointer)
5656
public ref readonly T Value
5757
{
5858
[MethodImpl(MethodImplOptions.AggressiveInlining)]
59-
get => ref MemoryMarshal.GetReference(Span);
59+
get => ref MemoryMarshal.GetReference(this.Span);
6060
}
6161

6262
/// <summary>

CommunityToolkit.HighPerformance/Ref{T}.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public readonly ref struct Ref<T>
3535
[MethodImpl(MethodImplOptions.AggressiveInlining)]
3636
public Ref(ref T value)
3737
{
38-
Span = MemoryMarshal.CreateSpan(ref value, 1);
38+
this.Span = MemoryMarshal.CreateSpan(ref value, 1);
3939
}
4040

4141
/// <summary>
@@ -54,7 +54,7 @@ public unsafe Ref(void* pointer)
5454
public ref T Value
5555
{
5656
[MethodImpl(MethodImplOptions.AggressiveInlining)]
57-
get => ref MemoryMarshal.GetReference(Span);
57+
get => ref MemoryMarshal.GetReference(this.Span);
5858
}
5959
#else
6060
/// <summary>
@@ -80,8 +80,8 @@ public ref T Value
8080
[MethodImpl(MethodImplOptions.AggressiveInlining)]
8181
public Ref(object owner, ref T value)
8282
{
83-
Owner = owner;
84-
Offset = ObjectMarshal.DangerousGetObjectDataByteOffset(owner, ref value);
83+
this.Owner = owner;
84+
this.Offset = ObjectMarshal.DangerousGetObjectDataByteOffset(owner, ref value);
8585
}
8686

8787
/// <summary>
@@ -90,7 +90,7 @@ public Ref(object owner, ref T value)
9090
public ref T Value
9191
{
9292
[MethodImpl(MethodImplOptions.AggressiveInlining)]
93-
get => ref ObjectMarshal.DangerousGetObjectDataReferenceAt<T>(Owner, Offset);
93+
get => ref ObjectMarshal.DangerousGetObjectDataReferenceAt<T>(this.Owner, this.Offset);
9494
}
9595
#endif
9696

CommunityToolkit.HighPerformance/Streams/MemoryStream{TSource}.Memory.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,8 @@ public sealed override int Read(Span<byte> buffer)
7979
{
8080
MemoryStream.ValidateDisposed(this.disposed);
8181

82-
int
83-
bytesAvailable = this.source.Length - this.position,
84-
bytesCopied = Math.Min(bytesAvailable, buffer.Length);
82+
int bytesAvailable = this.source.Length - this.position;
83+
int bytesCopied = Math.Min(bytesAvailable, buffer.Length);
8584

8685
Span<byte> source = this.source.Span.Slice(this.position, bytesCopied);
8786

CommunityToolkit.Mvvm.SourceGenerators/Helpers/HashCode.cs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -410,32 +410,32 @@ private static uint MixFinal(uint hash)
410410
private void Add(int value)
411411
{
412412
uint val = (uint)value;
413-
uint previousLength = length++;
413+
uint previousLength = this.length++;
414414
uint position = previousLength % 4;
415415

416416
if (position == 0)
417417
{
418-
queue1 = val;
418+
this.queue1 = val;
419419
}
420420
else if (position == 1)
421421
{
422-
queue2 = val;
422+
this.queue2 = val;
423423
}
424424
else if (position == 2)
425425
{
426-
queue3 = val;
426+
this.queue3 = val;
427427
}
428428
else
429429
{
430430
if (previousLength == 3)
431431
{
432-
Initialize(out v1, out v2, out v3, out v4);
432+
Initialize(out this.v1, out this.v2, out this.v3, out this.v4);
433433
}
434434

435-
v1 = Round(v1, queue1);
436-
v2 = Round(v2, queue2);
437-
v3 = Round(v3, queue3);
438-
v4 = Round(v4, val);
435+
this.v1 = Round(this.v1, this.queue1);
436+
this.v2 = Round(this.v2, this.queue2);
437+
this.v3 = Round(this.v3, this.queue3);
438+
this.v4 = Round(this.v4, val);
439439
}
440440
}
441441

@@ -447,21 +447,21 @@ public int ToHashCode()
447447
{
448448
uint length = this.length;
449449
uint position = length % 4;
450-
uint hash = length < 4 ? MixEmptyState() : MixState(v1, v2, v3, v4);
450+
uint hash = length < 4 ? MixEmptyState() : MixState(this.v1, this.v2, this.v3, this.v4);
451451

452452
hash += length * 4;
453453

454454
if (position > 0)
455455
{
456-
hash = QueueRound(hash, queue1);
456+
hash = QueueRound(hash, this.queue1);
457457

458458
if (position > 1)
459459
{
460-
hash = QueueRound(hash, queue2);
460+
hash = QueueRound(hash, this.queue2);
461461

462462
if (position > 2)
463463
{
464-
hash = QueueRound(hash, queue3);
464+
hash = QueueRound(hash, this.queue3);
465465
}
466466
}
467467
}

0 commit comments

Comments
 (0)