55using System . Reflection ;
66using JetBrains . Annotations ;
77
8+ #nullable enable
9+
810namespace BenchmarkDotNet . Characteristics
911{
1012 // TODO: better naming.
@@ -17,15 +19,15 @@ public abstract class CharacteristicObject
1719 DynamicallyAccessedMemberTypes . PublicProperties | DynamicallyAccessedMemberTypes . NonPublicProperties
1820 | DynamicallyAccessedMemberTypes . PublicFields | DynamicallyAccessedMemberTypes . NonPublicFields ;
1921
20- protected static string ResolveId ( CharacteristicObject obj , string actual )
22+ protected static string ResolveId ( CharacteristicObject obj , string ? actual )
2123 {
2224 if ( ! string . IsNullOrEmpty ( actual ) && actual != IdCharacteristic . FallbackValue )
23- return actual ;
25+ return actual ! ;
2426
2527 string result = CharacteristicSetPresenter . Display . ToPresentation ( obj ) ;
2628
2729 if ( result . Length == 0 )
28- result = IdCharacteristic . FallbackValue ;
30+ result = IdCharacteristic . FallbackValue ! ;
2931
3032 return result ;
3133 }
@@ -44,7 +46,7 @@ protected CharacteristicObject()
4446 sharedValues = new Dictionary < Characteristic , object > ( ) ;
4547 }
4648
47- protected CharacteristicObject ( string ? id ) : this ( )
49+ protected CharacteristicObject ( string id ) : this ( )
4850 {
4951 if ( ! string . IsNullOrEmpty ( id ) )
5052 {
@@ -79,7 +81,7 @@ private void AssertIsNonFrozenRoot()
7981 AssertIsRoot ( ) ;
8082 }
8183
82- private static void AssertIsAssignable ( Characteristic characteristic , object value )
84+ private static void AssertIsAssignable ( Characteristic characteristic , object ? value )
8385 {
8486 if ( ReferenceEquals ( value , Characteristic . EmptyValue ) || ReferenceEquals ( value , null ) )
8587 {
@@ -140,53 +142,53 @@ public bool HasValue(Characteristic characteristic)
140142 return false ;
141143 }
142144
143- internal T GetValue < [ DynamicallyAccessedMembers ( CharacteristicMemberTypes ) ] T > ( Characteristic < T > characteristic )
145+ internal T ? GetValue < [ DynamicallyAccessedMembers ( CharacteristicMemberTypes ) ] T > ( Characteristic < T > characteristic )
144146 {
145- return ( T ) GetValue ( ( Characteristic ) characteristic ) ;
147+ return ( T ? ) GetValue ( ( Characteristic ) characteristic ) ;
146148 }
147149
148- internal object GetValue ( Characteristic characteristic )
150+ internal object ? GetValue ( Characteristic characteristic )
149151 {
150152 if ( ! sharedValues . TryGetValue ( characteristic , out var result ) )
151153 result = Characteristic . EmptyValue ;
152154
153155 return ResolveCore ( characteristic , result ) ;
154156 }
155157
156- private object ResolveCore ( Characteristic characteristic , object result )
158+ private object ? ResolveCore ( Characteristic characteristic , object result )
157159 {
158160 return characteristic . ResolveValueCore ( this , result ) ;
159161 }
160162 #endregion
161163
162164 #region Resolve
163- public T ResolveValue < [ DynamicallyAccessedMembers ( CharacteristicMemberTypes ) ] T > ( Characteristic < T > characteristic , IResolver resolver )
165+ public T ? ResolveValue < [ DynamicallyAccessedMembers ( CharacteristicMemberTypes ) ] T > ( Characteristic < T > characteristic , IResolver resolver )
164166 {
165167 return resolver . Resolve ( this , characteristic ) ;
166168 }
167169
168- public T ResolveValue < [ DynamicallyAccessedMembers ( CharacteristicMemberTypes ) ] T > ( Characteristic < T > characteristic , IResolver resolver , T defaultValue )
170+ public T ? ResolveValue < [ DynamicallyAccessedMembers ( CharacteristicMemberTypes ) ] T > ( Characteristic < T > characteristic , IResolver resolver , T defaultValue )
169171 {
170172 return resolver . Resolve ( this , characteristic , defaultValue ) ;
171173 }
172174
173- public object ResolveValue ( Characteristic characteristic , IResolver resolver )
175+ public object ? ResolveValue ( Characteristic characteristic , IResolver resolver )
174176 {
175177 return resolver . Resolve ( this , characteristic ) ;
176178 }
177179
178- public object ResolveValue ( Characteristic characteristic , IResolver resolver , object defaultValue )
180+ public object ? ResolveValue ( Characteristic characteristic , IResolver resolver , object defaultValue )
179181 {
180182 return resolver . Resolve ( this , characteristic , defaultValue ) ;
181183 }
182184
183- public T ResolveValue < [ DynamicallyAccessedMembers ( CharacteristicObject . CharacteristicMemberTypes ) ] T > ( Characteristic < T > characteristic , T defaultValue )
185+ public T ? ResolveValue < [ DynamicallyAccessedMembers ( CharacteristicObject . CharacteristicMemberTypes ) ] T > ( Characteristic < T > characteristic , T defaultValue )
184186 {
185- return HasValue ( characteristic ) ? GetValue ( characteristic ) : ( T ) characteristic . ResolveValueCore ( this , defaultValue ) ;
187+ return HasValue ( characteristic ) ? GetValue ( characteristic ) : ( T ? ) characteristic . ResolveValueCore ( this , defaultValue ! ) ;
186188 }
187189
188190 [ PublicAPI ]
189- public object ResolveValue ( Characteristic characteristic , object defaultValue )
191+ public object ? ResolveValue ( Characteristic characteristic , object defaultValue )
190192 {
191193 return HasValue ( characteristic ) ? GetValue ( characteristic ) : characteristic . ResolveValueCore ( this , defaultValue ) ;
192194 }
@@ -203,16 +205,16 @@ public object ResolveValue(Characteristic characteristic, object defaultValue)
203205 SetValue ( ( Characteristic ) characteristic , value ) ;
204206 }
205207
206- internal void SetValue ( Characteristic characteristic , object value )
208+ internal void SetValue ( Characteristic characteristic , object ? value )
207209 {
208210 AssertNotFrozen ( ) ;
209211
210212 if ( characteristic . HasChildCharacteristics )
211213 {
212214 AssertIsAssignable ( characteristic , value ) ;
213215
214- var oldObjectValue = ( CharacteristicObject ) GetValue ( characteristic ) ;
215- var newObjectValue = ( CharacteristicObject ) ResolveCore ( characteristic , value ) ;
216+ var oldObjectValue = ( CharacteristicObject ? ) GetValue ( characteristic ) ;
217+ var newObjectValue = ( CharacteristicObject ? ) ResolveCore ( characteristic , value ! ) ;
216218
217219 if ( ! ReferenceEquals ( oldObjectValue , newObjectValue ) )
218220 {
@@ -226,7 +228,7 @@ internal void SetValue(Characteristic characteristic, object value)
226228 }
227229 }
228230
229- private void SetValueCore ( Characteristic characteristic , object value )
231+ private void SetValueCore ( Characteristic characteristic , object ? value )
230232 {
231233 AssertIsAssignable ( characteristic , value ) ;
232234
@@ -243,7 +245,7 @@ private void SetValueCore(Characteristic characteristic, object value)
243245 $ "The current node { this } has value for { characteristic } already.",
244246 nameof ( characteristic ) ) ;
245247
246- var characteristicObject = ( CharacteristicObject ) ResolveCore ( characteristic , value ) ;
248+ var characteristicObject = ( CharacteristicObject ) ResolveCore ( characteristic , value ! ) ! ;
247249 characteristicObject . SetOwnerCore ( OwnerOrSelf ) ;
248250
249251 sharedValues [ characteristic ] = characteristicObject ;
@@ -321,7 +323,7 @@ private void SetValueOnAttach(Characteristic characteristic, object value)
321323 if ( characteristic . HasChildCharacteristics )
322324 {
323325 // DONTTOUCH: workaround on case there were no parent characteristic.
324- var characteristicObject = ( CharacteristicObject ) GetValue ( characteristic ) ;
326+ var characteristicObject = ( CharacteristicObject ? ) GetValue ( characteristic ) ;
325327 characteristicObject ? . DetachFromOwner ( characteristic ) ;
326328 }
327329
@@ -358,13 +360,13 @@ private CharacteristicObject ApplyCore(
358360 {
359361 if ( ! HasValue ( characteristic ) )
360362 {
361- var characteristicObject = ( CharacteristicObject ) ResolveCore ( characteristic , value ) ;
363+ var characteristicObject = ( CharacteristicObject ? ) ResolveCore ( characteristic , value ) ;
362364 if ( characteristicObject != null )
363365 {
364366 value = Activator . CreateInstance ( characteristicObject . GetType ( ) ) ;
365367 }
366368
367- SetValueCore ( characteristic , value ) ;
369+ SetValueCore ( characteristic , value ! ) ;
368370 }
369371 }
370372 else
@@ -399,20 +401,20 @@ protected CharacteristicObject UnfreezeCopyCore()
399401 {
400402 AssertIsRoot ( ) ;
401403
402- var newRoot = ( CharacteristicObject ) Activator . CreateInstance ( GetType ( ) ) ;
404+ var newRoot = ( CharacteristicObject ) Activator . CreateInstance ( GetType ( ) ) ! ;
403405 newRoot . ApplyCore ( this ) ;
404406
405407 // Preserve the IdCharacteristic of the original object
406408 if ( this . HasValue ( IdCharacteristic ) )
407409 {
408- newRoot . SetValue ( IdCharacteristic , this . GetValue ( IdCharacteristic ) ) ;
410+ newRoot . SetValue ( IdCharacteristic , this . GetValue ( IdCharacteristic ) ! ) ;
409411 }
410412
411413 return newRoot ;
412414 }
413415 #endregion
414416
415- public string Id => IdCharacteristic [ this ] ;
417+ public string Id => IdCharacteristic [ this ] ! ;
416418
417419 public override string ToString ( ) => Id ;
418420 }
0 commit comments