Skip to content

Commit 7604371

Browse files
authored
Updated code to use the field keyword (#8335)
1 parent 9db9f01 commit 7604371

File tree

7 files changed

+36
-54
lines changed

7 files changed

+36
-54
lines changed

src/HotChocolate/Fusion-vnext/src/Fusion.Execution.Types/FusionComplexTypeDefinition.cs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ public abstract class FusionComplexTypeDefinition : IComplexTypeDefinition
1313
{
1414
private FusionDirectiveCollection _directives = default!;
1515
private FusionInterfaceTypeDefinitionCollection _implements = default!;
16-
private ISourceComplexTypeCollection<ISourceComplexType> _sources = default!;
17-
private IFeatureCollection _features = FeatureCollection.Empty;
1816
private bool _completed;
1917

2018
protected FusionComplexTypeDefinition(
@@ -95,7 +93,7 @@ IReadOnlyFieldDefinitionCollection<IOutputFieldDefinition> IComplexTypeDefinitio
9593
/// </value>
9694
public ISourceComplexTypeCollection<ISourceComplexType> Sources
9795
{
98-
get => _sources;
96+
get;
9997
private protected set
10098
{
10199
if (_completed)
@@ -104,13 +102,13 @@ private protected set
104102
"The type definition is sealed and cannot be modified.");
105103
}
106104

107-
_sources = value;
105+
field = value;
108106
}
109-
}
107+
} = default!;
110108

111109
public IFeatureCollection Features
112110
{
113-
get => _features;
111+
get;
114112
private protected set
115113
{
116114
if (_completed)
@@ -119,9 +117,9 @@ private protected set
119117
"The type definition is sealed and cannot be modified.");
120118
}
121119

122-
_features = value;
120+
field = value;
123121
}
124-
}
122+
} = FeatureCollection.Empty;
125123

126124
private protected void Complete()
127125
{

src/HotChocolate/Mutable/src/Types.Mutable/MutableInputFieldDefinition.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public string Name
4343
/// </summary>
4444
public ITypeSystemMember? DeclaringMember
4545
{
46-
get => field;
46+
get;
4747
set
4848
{
4949
if (value is not MutableInputObjectTypeDefinition

src/HotChocolate/Mutable/src/Types.Mutable/MutableOutputFieldDefinition.cs

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace HotChocolate.Types.Mutable;
99
/// <summary>
1010
/// Represents a GraphQL output field definition.
1111
/// </summary>
12-
public class MutableOutputFieldDefinition
12+
public class MutableOutputFieldDefinition(string name, IOutputType? type = null)
1313
: INamedTypeSystemMemberDefinition<MutableOutputFieldDefinition>
1414
, IOutputFieldDefinition
1515
, IMutableFieldDefinition
@@ -19,25 +19,13 @@ public class MutableOutputFieldDefinition
1919
private string? _deprecationReason;
2020
private DirectiveCollection? _directives;
2121
private InputFieldDefinitionCollection? _arguments;
22-
private IOutputType _type;
23-
24-
/// <summary>
25-
/// Initializes a new instance of the <see cref="MutableOutputFieldDefinition"/> class.
26-
/// </summary>
27-
/// <param name="name">The name of the field.</param>
28-
/// <param name="type">The type of the field.</param>
29-
public MutableOutputFieldDefinition(string name, IOutputType? type = null)
30-
{
31-
Name = name;
32-
_type = type ?? NotSetType.Default;
33-
}
3422

3523
/// <inheritdoc cref="IMutableFieldDefinition.Name" />
3624
public string Name
3725
{
38-
get => field;
26+
get;
3927
set => field = value.EnsureGraphQLName();
40-
}
28+
} = name;
4129

4230
/// <inheritdoc cref="IMutableFieldDefinition.Description" />
4331
public string? Description { get; set; }
@@ -119,9 +107,9 @@ IReadOnlyFieldDefinitionCollection<IInputValueDefinition> IOutputFieldDefinition
119107
/// </value>
120108
public IOutputType Type
121109
{
122-
get => _type;
123-
set => _type = value.ExpectOutputType();
124-
}
110+
get;
111+
set => field = value.ExpectOutputType();
112+
} = type ?? NotSetType.Default;
125113

126114
public FieldFlags Flags { get; set; }
127115

src/HotChocolate/Mutable/src/Types.Mutable/MutableScalarTypeDefinition.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.Diagnostics.CodeAnalysis;
12
using HotChocolate.Features;
23
using HotChocolate.Language;
34
using HotChocolate.Utilities;
@@ -14,19 +15,17 @@ public class MutableScalarTypeDefinition(string name)
1415
, IMutableTypeDefinition
1516
, IFeatureProvider
1617
{
17-
private string _name = name.EnsureGraphQLName();
1818
private DirectiveCollection? _directives;
19-
private IFeatureCollection? _features;
2019

2120
/// <inheritdoc />
2221
public TypeKind Kind => TypeKind.Scalar;
2322

2423
/// <inheritdoc cref="IMutableTypeDefinition.Name" />
2524
public string Name
2625
{
27-
get => _name;
28-
set => _name = value.EnsureGraphQLName();
29-
}
26+
get;
27+
set => field = value.EnsureGraphQLName();
28+
} = name.EnsureGraphQLName();
3029

3130
/// <inheritdoc cref="IMutableTypeDefinition.Description" />
3231
public string? Description { get; set; }
@@ -46,8 +45,9 @@ IReadOnlyDirectiveCollection IDirectivesProvider.Directives
4645
=> _directives ?? EmptyCollections.Directives;
4746

4847
/// <inheritdoc />
48+
[field: AllowNull, MaybeNull]
4949
public IFeatureCollection Features
50-
=> _features ??= new FeatureCollection();
50+
=> field ??= new FeatureCollection();
5151

5252
/// <inheritdoc />
5353
public bool Equals(IType? other)

src/HotChocolate/Mutable/src/Types.Mutable/MutableSchemaDefinition.cs

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,6 @@ public class MutableSchemaDefinition
1414
, IFeatureProvider
1515
{
1616
private readonly List<SchemaCoordinate> _allDefinitionCoordinates = [];
17-
private MutableObjectTypeDefinition? _queryType;
18-
private MutableObjectTypeDefinition? _mutationType;
19-
private MutableObjectTypeDefinition? _subscriptionType;
20-
private TypeDefinitionCollection? _typeDefinitions;
21-
private DirectiveDefinitionCollection? _directiveDefinitions;
22-
private DirectiveCollection? _directives;
23-
private IFeatureCollection? _features;
2417

2518
/// <inheritdoc />
2619
public string Name { get; set; } = "default";
@@ -33,10 +26,10 @@ public class MutableSchemaDefinition
3326
/// </summary>
3427
public MutableObjectTypeDefinition? QueryType
3528
{
36-
get => _queryType;
29+
get;
3730
set
3831
{
39-
_queryType = value;
32+
field = value;
4033

4134
if (value is not null && !Types.Contains(value))
4235
{
@@ -53,10 +46,10 @@ IObjectTypeDefinition ISchemaDefinition.QueryType
5346
/// </summary>
5447
public MutableObjectTypeDefinition? MutationType
5548
{
56-
get => _mutationType;
49+
get;
5750
set
5851
{
59-
_mutationType = value;
52+
field = value;
6053

6154
if (value is not null && !Types.Contains(value))
6255
{
@@ -72,10 +65,10 @@ public MutableObjectTypeDefinition? MutationType
7265
/// </summary>
7366
public MutableObjectTypeDefinition? SubscriptionType
7467
{
75-
get => _subscriptionType;
68+
get;
7669
set
7770
{
78-
_subscriptionType = value;
71+
field = value;
7972

8073
if (value is not null && !Types.Contains(value))
8174
{
@@ -89,30 +82,34 @@ public MutableObjectTypeDefinition? SubscriptionType
8982
/// <summary>
9083
/// Gets the types that are defined in this schema.
9184
/// </summary>
85+
[field: AllowNull, MaybeNull]
9286
public TypeDefinitionCollection Types
93-
=> _typeDefinitions ??= new TypeDefinitionCollection(_allDefinitionCoordinates);
87+
=> field ??= new TypeDefinitionCollection(_allDefinitionCoordinates);
9488

9589
IReadOnlyTypeDefinitionCollection ISchemaDefinition.Types => Types;
9690

9791
/// <summary>
9892
/// Gets the directives that are defined in this schema.
9993
/// </summary>
94+
[field: AllowNull, MaybeNull]
10095
public DirectiveDefinitionCollection DirectiveDefinitions
101-
=> _directiveDefinitions ??= new DirectiveDefinitionCollection(_allDefinitionCoordinates);
96+
=> field ??= new DirectiveDefinitionCollection(_allDefinitionCoordinates);
10297

10398
IReadOnlyDirectiveDefinitionCollection ISchemaDefinition.DirectiveDefinitions => DirectiveDefinitions;
10499

105100
/// <summary>
106101
/// Gets the directives that are annotated to this schema.
107102
/// </summary>
103+
[field: AllowNull, MaybeNull]
108104
public DirectiveCollection Directives
109-
=> _directives ??= [];
105+
=> field ??= [];
110106

111107
IReadOnlyDirectiveCollection IDirectivesProvider.Directives => Directives;
112108

113109
/// <inheritdoc />
110+
[field: AllowNull, MaybeNull]
114111
public IFeatureCollection Features
115-
=> _features ??= new FeatureCollection();
112+
=> field ??= new FeatureCollection();
116113

117114
/// <summary>
118115
/// Tries to resolve a <see cref="ITypeSystemMember"/> by its <see cref="SchemaCoordinate"/>.

src/HotChocolate/Mutable/src/Types.Mutable/MutableUnionTypeDefinition.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public MutableUnionTypeDefinition(string name)
2929
/// <inheritdoc cref="IMutableTypeDefinition.Name" />
3030
public string Name
3131
{
32-
get => field;
32+
get;
3333
set => field = value.EnsureGraphQLName();
3434
}
3535

src/HotChocolate/Mutable/src/Types.Mutable/TypeMetadata.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@ namespace HotChocolate.Types.Mutable;
44

55
public sealed class TypeMetadata : ISealable
66
{
7-
private bool _isExtension;
87
private bool _isReadOnly;
98

109
public bool IsExtension
1110
{
12-
get => _isExtension;
11+
get;
1312
set
1413
{
1514
if (_isReadOnly)
@@ -18,7 +17,7 @@ public bool IsExtension
1817
"The metadata is sealed and cannot be modified.");
1918
}
2019

21-
_isExtension = value;
20+
field = value;
2221
}
2322
}
2423

0 commit comments

Comments
 (0)