10
10
using Microsoft . EntityFrameworkCore . Metadata ;
11
11
using Microsoft . EntityFrameworkCore . Utilities ;
12
12
13
+ #nullable enable
14
+
13
15
namespace Microsoft . EntityFrameworkCore . Infrastructure
14
16
{
15
17
/// <summary>
@@ -23,7 +25,7 @@ namespace Microsoft.EntityFrameworkCore.Infrastructure
23
25
/// </summary>
24
26
public class Annotatable : IMutableAnnotatable
25
27
{
26
- private SortedDictionary < string , Annotation > _annotations ;
28
+ private SortedDictionary < string , Annotation > ? _annotations ;
27
29
28
30
/// <summary>
29
31
/// Gets all annotations on the current object.
@@ -37,7 +39,7 @@ public virtual IEnumerable<Annotation> GetAnnotations()
37
39
/// <param name="name"> The key of the annotation to be added. </param>
38
40
/// <param name="value"> The value to be stored in the annotation. </param>
39
41
/// <returns> The newly added annotation. </returns>
40
- public virtual Annotation AddAnnotation ( [ NotNull ] string name , [ CanBeNull ] object value )
42
+ public virtual Annotation AddAnnotation ( [ NotNull ] string name , [ CanBeNull ] object ? value )
41
43
{
42
44
Check . NotEmpty ( name , nameof ( name ) ) ;
43
45
@@ -70,7 +72,7 @@ protected virtual Annotation AddAnnotation([NotNull] string name, [NotNull] Anno
70
72
/// </summary>
71
73
/// <param name="name"> The key of the annotation to be added. </param>
72
74
/// <param name="value"> The value to be stored in the annotation. </param>
73
- public virtual void SetAnnotation ( string name , object value )
75
+ public virtual void SetAnnotation ( string name , object ? value )
74
76
{
75
77
var oldAnnotation = FindAnnotation ( name ) ;
76
78
if ( oldAnnotation != null
@@ -90,10 +92,10 @@ public virtual void SetAnnotation(string name, object value)
90
92
/// <param name="annotation"> The annotation to be set. </param>
91
93
/// <param name="oldAnnotation"> The annotation being replaced. </param>
92
94
/// <returns> The annotation that was set. </returns>
93
- protected virtual Annotation SetAnnotation (
95
+ protected virtual Annotation ? SetAnnotation (
94
96
[ NotNull ] string name ,
95
97
[ NotNull ] Annotation annotation ,
96
- [ CanBeNull ] Annotation oldAnnotation )
98
+ [ CanBeNull ] Annotation ? oldAnnotation )
97
99
{
98
100
if ( _annotations == null )
99
101
{
@@ -112,10 +114,10 @@ protected virtual Annotation SetAnnotation(
112
114
/// <param name="annotation"> The annotation set. </param>
113
115
/// <param name="oldAnnotation"> The old annotation. </param>
114
116
/// <returns> The annotation that was set. </returns>
115
- protected virtual Annotation OnAnnotationSet (
117
+ protected virtual Annotation ? OnAnnotationSet (
116
118
[ NotNull ] string name ,
117
- [ CanBeNull ] Annotation annotation ,
118
- [ CanBeNull ] Annotation oldAnnotation )
119
+ [ CanBeNull ] Annotation ? annotation ,
120
+ [ CanBeNull ] Annotation ? oldAnnotation )
119
121
=> annotation ;
120
122
121
123
/// <summary>
@@ -125,7 +127,7 @@ protected virtual Annotation OnAnnotationSet(
125
127
/// <returns>
126
128
/// The existing annotation if an annotation with the specified name already exists. Otherwise, <see langword="null" />.
127
129
/// </returns>
128
- public virtual Annotation FindAnnotation ( [ NotNull ] string name )
130
+ public virtual Annotation ? FindAnnotation ( [ NotNull ] string name )
129
131
{
130
132
Check . NotEmpty ( name , nameof ( name ) ) ;
131
133
@@ -141,7 +143,7 @@ public virtual Annotation FindAnnotation([NotNull] string name)
141
143
/// </summary>
142
144
/// <param name="name"> The annotation to remove. </param>
143
145
/// <returns> The annotation that was removed. </returns>
144
- public virtual Annotation RemoveAnnotation ( [ NotNull ] string name )
146
+ public virtual Annotation ? RemoveAnnotation ( [ NotNull ] string name )
145
147
{
146
148
Check . NotNull ( name , nameof ( name ) ) ;
147
149
@@ -151,7 +153,8 @@ public virtual Annotation RemoveAnnotation([NotNull] string name)
151
153
return null ;
152
154
}
153
155
154
- _annotations . Remove ( name ) ;
156
+ // TODO-NULLABLE: Put MemberNotNull on FindAnnotation when we target net5.0
157
+ _annotations ! . Remove ( name ) ;
155
158
156
159
if ( _annotations . Count == 0 )
157
160
{
@@ -171,7 +174,7 @@ public virtual Annotation RemoveAnnotation([NotNull] string name)
171
174
/// The value of the existing annotation if an annotation with the specified name already exists.
172
175
/// Otherwise, <see langword="null" />.
173
176
/// </returns>
174
- public virtual object this [ string name ]
177
+ public virtual object ? this [ string name ]
175
178
{
176
179
get => FindAnnotation ( name ) ? . Value ;
177
180
set
@@ -195,7 +198,7 @@ public virtual object this[string name]
195
198
/// <param name="name"> The key of the annotation. </param>
196
199
/// <param name="value"> The value to be stored in the annotation. </param>
197
200
/// <returns> The newly created annotation. </returns>
198
- protected virtual Annotation CreateAnnotation ( [ NotNull ] string name , [ CanBeNull ] object value )
201
+ protected virtual Annotation CreateAnnotation ( [ NotNull ] string name , [ CanBeNull ] object ? value )
199
202
=> new Annotation ( name , value ) ;
200
203
201
204
/// <inheritdoc />
@@ -205,17 +208,17 @@ IEnumerable<IAnnotation> IAnnotatable.GetAnnotations()
205
208
206
209
/// <inheritdoc />
207
210
[ DebuggerStepThrough ]
208
- IAnnotation IAnnotatable . FindAnnotation ( string name )
211
+ IAnnotation ? IAnnotatable . FindAnnotation ( string name )
209
212
=> FindAnnotation ( name ) ;
210
213
211
214
/// <inheritdoc />
212
215
[ DebuggerStepThrough ]
213
- IAnnotation IMutableAnnotatable . AddAnnotation ( string name , object value )
216
+ IAnnotation IMutableAnnotatable . AddAnnotation ( string name , object ? value )
214
217
=> AddAnnotation ( name , value ) ;
215
218
216
219
/// <inheritdoc />
217
220
[ DebuggerStepThrough ]
218
- IAnnotation IMutableAnnotatable . RemoveAnnotation ( string name )
221
+ IAnnotation ? IMutableAnnotatable . RemoveAnnotation ( string name )
219
222
=> RemoveAnnotation ( name ) ;
220
223
}
221
224
}
0 commit comments