Skip to content

Commit dfaed34

Browse files
committed
switch to field keyword
1 parent e68ed5a commit dfaed34

8 files changed

Lines changed: 28 additions & 54 deletions

File tree

samples/AspNetCore.Samples/Validation/MaybeBound.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,13 @@ namespace Thinktecture.Validation;
99
where TKey : IParsable<TKey>
1010
where TValidationError : class, IValidationError<TValidationError>
1111
{
12-
private readonly T? _value;
13-
public T? Value => Error is null ? _value : throw new ValidationException(Error);
12+
public T? Value => Error is null ? field : throw new ValidationException(Error);
1413

1514
public string? Error { get; }
1615

1716
private MaybeBound(T? value, string? error)
1817
{
19-
_value = value;
18+
Value = value;
2019
Error = error;
2120
}
2221

samples/EntityFrameworkCore.Samples/Product.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ public class Product
1616
public required DayMonth ScheduledDeliveryDate { get; set; }
1717
public required TextOrNumberSerializable TextOrNumber { get; set; }
1818

19-
private Boundary? _boundary;
20-
public Boundary Boundary => _boundary ?? throw new InvalidOperationException("Boundary is not loaded.");
19+
public Boundary Boundary => field ?? throw new InvalidOperationException("Boundary is not loaded.");
2120

2221
[SetsRequiredMembers]
2322
private Product(
@@ -50,6 +49,6 @@ public Product(
5049
OpenEndDate endDate = default)
5150
: this(id, name, category, productType, endDate, scheduledDeliveryDate, textOrNumber)
5251
{
53-
_boundary = boundary;
52+
Boundary = boundary;
5453
}
5554
}

src/Thinktecture.Runtime.Extensions.EntityFrameworkCore.Sources/EntityFrameworkCore/Infrastructure/ThinktectureDbContextOptionsExtension.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ namespace Thinktecture.EntityFrameworkCore.Infrastructure;
1010

1111
internal sealed class ThinktectureDbContextOptionsExtension : IDbContextOptionsExtension
1212
{
13-
private DbContextOptionsExtensionInfo? _info;
14-
public DbContextOptionsExtensionInfo Info => _info ??= new ThinktectureDbContextOptionsExtensionInfo(this);
13+
public DbContextOptionsExtensionInfo Info => field ??= new ThinktectureDbContextOptionsExtensionInfo(this);
1514

1615
public ThinktectureValueConverterSettings Settings { get; private set; }
1716

@@ -59,8 +58,7 @@ private sealed class ThinktectureDbContextOptionsExtensionInfo : DbContextOption
5958
private readonly ThinktectureDbContextOptionsExtension _extension;
6059
public override bool IsDatabaseProvider => false;
6160

62-
private string? _logFragment;
63-
public override string LogFragment => _logFragment ??= CreateLogFragment();
61+
public override string LogFragment => field ??= CreateLogFragment();
6462

6563
private string CreateLogFragment()
6664
{

src/Thinktecture.Runtime.Extensions.Swashbuckle/Swashbuckle/Internal/JsonSerializerOptionsResolver.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,13 @@ public class JsonSerializerOptionsResolver
1414
{
1515
private readonly IServiceProvider _serviceProvider;
1616

17-
private JsonSerializerOptions? _options;
18-
1917
/// <summary>
2018
/// This is an internal API that supports the Thinktecture.Runtime.Extensions infrastructure and not subject to
2119
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
2220
/// any release. You should only use it directly in your code with extreme caution and knowing that
2321
/// doing so can result in application failures when updating to a new Thinktecture.Runtime.Extensions release.
2422
/// </summary>
25-
public JsonSerializerOptions JsonSerializerOptions => _options ??= ResolveOptions();
23+
public JsonSerializerOptions JsonSerializerOptions => field ??= ResolveOptions();
2624

2725
/// <summary>
2826
/// This is an internal API that supports the Thinktecture.Runtime.Extensions infrastructure and not subject to

src/Thinktecture.Runtime.Extensions/Collections/SingleItemEnumerator.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,15 @@ namespace Thinktecture.Collections;
44

55
internal sealed class SingleItemEnumerator<T> : IEnumerator<T>
66
{
7-
private readonly T _item;
8-
97
private int _index;
108

11-
public T Current => _index == 1 ? _item : default!;
9+
public T Current => _index == 1 ? field : default!;
1210

1311
object IEnumerator.Current => Current!;
1412

1513
public SingleItemEnumerator(T item)
1614
{
17-
_item = item;
15+
Current = item;
1816
}
1917

2018
public bool MoveNext()

src/Thinktecture.Runtime.Extensions/SmartEnumAttribute.cs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,14 @@ public sealed class SmartEnumAttribute<TKey> : Attribute
5656
/// </summary>
5757
public MemberKind KeyMemberKind { get; set; }
5858

59-
private string? _keyMemberName;
60-
6159
/// <summary>
6260
/// The name of the key member.
6361
/// Default: <c>_key</c> if the key member is a private field; otherwise <c>Key</c>.
6462
/// </summary>
6563
public string KeyMemberName
6664
{
67-
get => _keyMemberName ?? (KeyMemberAccessModifier == AccessModifier.Private && KeyMemberKind == MemberKind.Field ? "_key" : "Key");
68-
set => _keyMemberName = value;
65+
get => field ?? (KeyMemberAccessModifier == AccessModifier.Private && KeyMemberKind == MemberKind.Field ? "_key" : "Key");
66+
set;
6967
}
7068

7169
/// <summary>
@@ -116,8 +114,6 @@ public bool SkipISpanParsable
116114
/// </summary>
117115
public OperatorsGeneration ComparisonOperators { get; set; }
118116

119-
private OperatorsGeneration _equalityComparisonOperators;
120-
121117
/// <summary>
122118
/// Indication whether and how the generator should generate the implementation of <see cref="IEqualityOperators{TSelf,TOther,TResult}"/>.
123119
///
@@ -126,8 +122,8 @@ public bool SkipISpanParsable
126122
/// </summary>
127123
public OperatorsGeneration EqualityComparisonOperators
128124
{
129-
get => ComparisonOperators > _equalityComparisonOperators ? ComparisonOperators : _equalityComparisonOperators;
130-
set => _equalityComparisonOperators = value;
125+
get => ComparisonOperators > field ? ComparisonOperators : field;
126+
set;
131127
}
132128

133129
/// <summary>

src/Thinktecture.Runtime.Extensions/ValueObjectAttribute.cs

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,14 @@ public sealed class ValueObjectAttribute<TKey> : ValueObjectAttributeBase
2626
/// </summary>
2727
public MemberKind KeyMemberKind { get; set; }
2828

29-
private string? _keyMemberName;
30-
3129
/// <summary>
3230
/// The name of the key member.
3331
/// Default: <c>_value</c> if the key member is a private field; otherwise <c>Value</c>.
3432
/// </summary>
3533
public string KeyMemberName
3634
{
37-
get => _keyMemberName ?? (KeyMemberAccessModifier == AccessModifier.Private && KeyMemberKind == MemberKind.Field ? "_value" : "Value");
38-
set => _keyMemberName = value;
35+
get => field ?? (KeyMemberAccessModifier == AccessModifier.Private && KeyMemberKind == MemberKind.Field ? "_value" : "Value");
36+
set;
3937
}
4038

4139
/// <summary>
@@ -46,8 +44,6 @@ public string KeyMemberName
4644
/// </summary>
4745
public bool SkipKeyMember { get; set; }
4846

49-
private bool _nullInFactoryMethodsYieldsNull;
50-
5147
/// <summary>
5248
/// By default, providing <c>null</c> to methods "Create", "Validate" and "TryCreate" is not allowed.
5349
/// If this property is set to <c>true</c>, then providing a <c>null</c> will return <c>null</c>.
@@ -60,8 +56,8 @@ public string KeyMemberName
6056
/// </remarks>
6157
public bool NullInFactoryMethodsYieldsNull
6258
{
63-
get => _nullInFactoryMethodsYieldsNull || EmptyStringInFactoryMethodsYieldsNull;
64-
set => _nullInFactoryMethodsYieldsNull = value;
59+
get => field || EmptyStringInFactoryMethodsYieldsNull;
60+
set;
6561
}
6662

6763
/// <summary>
@@ -157,8 +153,6 @@ public bool SkipISpanParsable
157153
/// </remarks>
158154
public OperatorsGeneration DivisionOperators { get; set; }
159155

160-
private OperatorsGeneration _comparisonOperators;
161-
162156
/// <summary>
163157
/// Indication whether and how the generator should generate the implementation of <see cref="IComparisonOperators{TSelf,TOther,TResult}"/>.
164158
///
@@ -172,12 +166,10 @@ public bool SkipISpanParsable
172166
/// </remarks>
173167
public OperatorsGeneration ComparisonOperators
174168
{
175-
get => SkipEqualityComparison ? OperatorsGeneration.None : _comparisonOperators;
176-
set => _comparisonOperators = value;
169+
get => SkipEqualityComparison ? OperatorsGeneration.None : field;
170+
set;
177171
}
178172

179-
private OperatorsGeneration _equalityComparisonOperators;
180-
181173
/// <summary>
182174
/// Indication whether and how the generator should generate the implementation of <see cref="IEqualityOperators{TSelf,TOther,TResult}"/>.
183175
/// </summary>
@@ -193,11 +185,11 @@ public OperatorsGeneration EqualityComparisonOperators
193185
if (SkipEqualityComparison)
194186
return OperatorsGeneration.None;
195187

196-
return ComparisonOperators > _equalityComparisonOperators
188+
return ComparisonOperators > field
197189
? ComparisonOperators
198-
: _equalityComparisonOperators;
190+
: field;
199191
}
200-
set => _equalityComparisonOperators = value;
192+
set;
201193
}
202194

203195
/// <summary>

src/Thinktecture.Runtime.Extensions/ValueObjectAttributeBase.cs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,22 @@ public abstract class ValueObjectAttributeBase : Attribute
1616
/// </summary>
1717
public AccessModifier ConstructorAccessModifier { get; set; }
1818

19-
private string? _createFactoryMethodName;
20-
2119
/// <summary>
2220
/// The name of the factory method "Create".
2321
/// </summary>
2422
public string CreateFactoryMethodName
2523
{
26-
get => _createFactoryMethodName ?? "Create";
27-
set => _createFactoryMethodName = String.IsNullOrWhiteSpace(value) ? null : value.Trim();
24+
get => field ?? "Create";
25+
set => field = String.IsNullOrWhiteSpace(value) ? null : value.Trim();
2826
}
2927

30-
private string? _tryCreateFactoryMethodName;
31-
3228
/// <summary>
3329
/// The name of the factory method "TryCreate".
3430
/// </summary>
3531
public string TryCreateFactoryMethodName
3632
{
37-
get => _tryCreateFactoryMethodName ?? "TryCreate";
38-
set => _tryCreateFactoryMethodName = String.IsNullOrWhiteSpace(value) ? null : value.Trim();
33+
get => field ?? "TryCreate";
34+
set => field = String.IsNullOrWhiteSpace(value) ? null : value.Trim();
3935
}
4036

4137
/// <summary>
@@ -52,8 +48,6 @@ public string TryCreateFactoryMethodName
5248
/// </summary>
5349
public bool AllowDefaultStructs { get; set; }
5450

55-
private string? _defaultInstancePropertyName;
56-
5751
/// <summary>
5852
/// The name of the static property containing the <c>default</c> instance of the struct.
5953
/// Default name is "Empty" (analogous to <c>Guid.Empty</c>).
@@ -63,8 +57,8 @@ public string TryCreateFactoryMethodName
6357
/// </summary>
6458
public string DefaultInstancePropertyName
6559
{
66-
get => _defaultInstancePropertyName ?? "Empty";
67-
set => _defaultInstancePropertyName = value;
60+
get => field ?? "Empty";
61+
set;
6862
}
6963

7064
/// <summary>

0 commit comments

Comments
 (0)