You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/csharp/language-reference/compiler-messages/partial-declarations.md
+12-2Lines changed: 12 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -47,6 +47,8 @@ f1_keywords:
47
47
- "CS9257"
48
48
- "CS9258"
49
49
- "CS9263"
50
+
- "CS9264"
51
+
- "CS9266"
50
52
helpviewer_keywords:
51
53
- "CS0260"
52
54
- "CS0261"
@@ -93,7 +95,8 @@ helpviewer_keywords:
93
95
- "CS9257"
94
96
- "CS9258"
95
97
- "CS9263"
96
-
ms.date: 11/01/2024
98
+
- "CS9266"
99
+
ms.date: 11/06/2024
97
100
---
98
101
# Errors and warnings related to `partial` type and `partial` member declarations
99
102
@@ -148,6 +151,11 @@ That's by design. The text closely matches the text of the compiler error / warn
148
151
-[**CS9258**](#field-backed-properties): *In this language version, the '`field`' keyword binds to a synthesized backing field for the property. To avoid generating a synthesized backing field, and to refer to the existing member, use '`this.field`' or '`@field`' instead.*
149
152
-[**CS9263**](#field-backed-properties): *A partial property cannot have an initializer on both the definition and implementation.*
150
153
154
+
The following warnings can be generated for field backed properties:
155
+
156
+
-[**CS9264**](#field-backed-properties): *Non-nullable property must contain a non-null value when exiting constructor. Consider adding the 'required' modifier, or declaring the property as nullable, or adding '`[field: MaybeNull, AllowNull]`' attributes.**
157
+
-[**CS9266**](#field-backed-properties): *One accessor of property should use '`field`' because the other accessor is using it.*
158
+
151
159
The following sections explain the cause and fixes for these errors and warnings.
152
160
153
161
## Partial types
@@ -245,9 +253,11 @@ public partial int ImplementingDeclaration { get => field; set; }
245
253
246
254
-**CS9258**: *In this language version, the '`field`' keyword binds to a synthesized backing field for the property. To avoid generating a synthesized backing field, and to refer to the existing member, use '`this.field`' or '`@field`' instead.*
247
255
-**CS9263**: *A partial property cannot have an initializer on both the definition and implementation.*
256
+
-**CS9264**: *Non-nullable property must contain a non-null value when exiting constructor. Consider adding the 'required' modifier, or declaring the property as nullable, or adding '`[field: MaybeNull, AllowNull]`' attributes.**
257
+
-**CS9266**: *One accessor of property should use '`field`' because the other accessor is using it.*
Beginning with C# 13, the preview feature, `field` backed properties allows you to access the compiler synthesized backing field for a property. **CS9258** indicates that you have a variable named `field`, which can be hidden by the contextual keyword `field`.
252
262
253
-
**CS9263** indicates that your declaring declaration includes an implementation. That implementation might be accessing the compiler synthesized backing field for that property.
263
+
**CS9263** indicates that your declaring declaration includes an implementation. That implementation might be accessing the compiler synthesized backing field for that property.**CS9264** indicates that the your use of `field` assumes a non-nullable backing field while the property declaration is nullable. The compiler assumes both the backing field and the property have the same nullability. You need to add the `[field:MaybeNull, AllowNull]` attribute to the property declaration to indicate that the `field` value should be considered nullable. **CS9266** indicates that one of a properties accessors uses the `field` keyword, but the other uses a hand-declared backing field. The warning indicates you may have done that by accident.
0 commit comments