@@ -14,12 +14,9 @@ namespace System.Windows.Forms.ComponentModel.Com2Interop;
14
14
/// </summary>
15
15
internal sealed unsafe class Com2PictureConverter : Com2DataTypeToManagedDataTypeConverter
16
16
{
17
- // If the first call to ConvertManagedToNative happened to be passing managedValue: null, we want
18
- // cancelSet to be false.
19
- // So we start _lastManaged default value to a unique object.
20
- private object ? _lastManaged = new ( ) ;
17
+ private object ? _lastManaged ;
21
18
22
- private OLE_HANDLE ? _lastNativeHandle ;
19
+ private OLE_HANDLE _lastNativeHandle ;
23
20
24
21
private Type _pictureType = typeof ( Bitmap ) ;
25
22
@@ -51,7 +48,7 @@ public Com2PictureConverter(Com2PropertyDescriptor property)
51
48
52
49
picture . Value ->get_Handle ( out OLE_HANDLE handle ) . ThrowOnFailure ( ) ;
53
50
54
- if ( _lastManaged is not null && _lastNativeHandle . HasValue && handle == _lastNativeHandle . Value )
51
+ if ( _lastManaged is not null && handle == _lastNativeHandle )
55
52
{
56
53
return _lastManaged ;
57
54
}
@@ -90,7 +87,7 @@ public Com2PictureConverter(Com2PropertyDescriptor property)
90
87
91
88
public override VARIANT ConvertManagedToNative ( object ? managedValue , Com2PropertyDescriptor property , ref bool cancelSet )
92
89
{
93
- if ( managedValue == _lastManaged )
90
+ if ( managedValue is not null && managedValue == _lastManaged )
94
91
{
95
92
// There should be no point in setting the same object back for this property.
96
93
cancelSet = true ;
@@ -123,16 +120,15 @@ public override VARIANT ConvertManagedToNative(object? managedValue, Com2Propert
123
120
using ComScope < IPicture > picture = new ( null ) ;
124
121
PInvokeCore . OleCreatePictureIndirect ( & pictdesc , IID . Get < IPicture > ( ) , own , picture ) . ThrowOnFailure ( ) ;
125
122
_lastManaged = managedValue ;
126
- picture . Value ->get_Handle ( out var nativeHandle ) . ThrowOnFailure ( ) ;
127
- _lastNativeHandle = nativeHandle ;
123
+ picture . Value ->get_Handle ( out _lastNativeHandle ) . ThrowOnFailure ( ) ;
128
124
IUnknown * unknown ;
129
125
picture . Value ->QueryInterface ( IID . Get < IUnknown > ( ) , ( void * * ) & unknown ) . ThrowOnFailure ( ) ;
130
126
return ( VARIANT ) unknown ;
131
127
}
132
128
else
133
129
{
134
130
_lastManaged = null ;
135
- _lastNativeHandle = null ;
131
+ _lastNativeHandle = default ;
136
132
return VARIANT . Empty ;
137
133
}
138
134
}
0 commit comments