3
3
4
4
using System ;
5
5
using System . Collections . Generic ;
6
+ using System . Diagnostics . CodeAnalysis ;
6
7
using System . Linq ;
7
8
using System . Linq . Expressions ;
8
9
using System . Text ;
@@ -84,10 +85,10 @@ static Mock()
84
85
serialNumberCounter = 0 ;
85
86
}
86
87
87
- T instance ;
88
+ T ? instance ;
88
89
List < Type > additionalInterfaces ;
89
- Dictionary < Type , object > configuredDefaultValues ;
90
- object [ ] constructorArguments ;
90
+ Dictionary < Type , object ? > configuredDefaultValues ;
91
+ object ? [ ] constructorArguments ;
91
92
DefaultValueProvider defaultValueProvider ;
92
93
EventHandlerCollection eventHandlers ;
93
94
InvocationCollection invocations ;
@@ -110,6 +111,7 @@ internal Mock(bool skipInitialize)
110
111
// The skipInitialize parameter is not used at all, and it's
111
112
// just to differentiate this ctor that should do nothing
112
113
// from the regular ones which initializes the proxy, etc.
114
+ // TODO: How should nullable references be handled here?
113
115
}
114
116
115
117
/// <summary>
@@ -176,7 +178,7 @@ public Mock(MockBehavior behavior, params object?[]? args)
176
178
177
179
this . additionalInterfaces = new List < Type > ( ) ;
178
180
this . behavior = behavior ;
179
- this . configuredDefaultValues = new Dictionary < Type , object > ( ) ;
181
+ this . configuredDefaultValues = new Dictionary < Type , object ? > ( ) ;
180
182
this . constructorArguments = args ;
181
183
this . defaultValueProvider = DefaultValueProvider . Empty ;
182
184
this . eventHandlers = new EventHandlerCollection ( ) ;
@@ -248,9 +250,9 @@ public override bool CallBase
248
250
}
249
251
}
250
252
251
- internal override object [ ] ConstructorArguments => this . constructorArguments ;
253
+ internal override object ? [ ] ConstructorArguments => this . constructorArguments ;
252
254
253
- internal override Dictionary < Type , object > ConfiguredDefaultValues => this . configuredDefaultValues ;
255
+ internal override Dictionary < Type , object ? > ConfiguredDefaultValues => this . configuredDefaultValues ;
254
256
255
257
/// <summary>
256
258
/// Gets or sets the <see cref="DefaultValueProvider"/> instance that will be used
@@ -295,6 +297,9 @@ public override string ToString()
295
297
return this . Name ;
296
298
}
297
299
300
+ #if NET
301
+ [ MemberNotNull ( nameof ( instance ) ) ]
302
+ #endif
298
303
void InitializeInstance ( )
299
304
{
300
305
// Determine the set of interfaces that the proxy object should additionally implement.
@@ -623,7 +628,7 @@ public Mock<T> SetupProperty<TProperty>(Expression<Func<T, TProperty>> property)
623
628
/// Assert.Equal(6, v.Value);
624
629
/// </code>
625
630
/// </example>
626
- public Mock < T > SetupProperty < TProperty > ( Expression < Func < T , TProperty > > property , TProperty initialValue )
631
+ public Mock < T > SetupProperty < TProperty > ( Expression < Func < T , TProperty > > property , TProperty ? initialValue )
627
632
{
628
633
Mock . SetupProperty ( this , property , initialValue ) ;
629
634
return this ;
0 commit comments