Skip to content

Commit 60ace6a

Browse files
committed
Address review comment
1 parent 569baea commit 60ace6a

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

src/System.Windows.Forms/System/Windows/Forms/ComponentModel/COM2Interop/COM2PictureConverter.cs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,9 @@ namespace System.Windows.Forms.ComponentModel.Com2Interop;
1414
/// </summary>
1515
internal sealed unsafe class Com2PictureConverter : Com2DataTypeToManagedDataTypeConverter
1616
{
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;
2118

22-
private OLE_HANDLE? _lastNativeHandle;
19+
private OLE_HANDLE _lastNativeHandle;
2320

2421
private Type _pictureType = typeof(Bitmap);
2522

@@ -51,7 +48,7 @@ public Com2PictureConverter(Com2PropertyDescriptor property)
5148

5249
picture.Value->get_Handle(out OLE_HANDLE handle).ThrowOnFailure();
5350

54-
if (_lastManaged is not null && _lastNativeHandle.HasValue && handle == _lastNativeHandle.Value)
51+
if (_lastManaged is not null && handle == _lastNativeHandle)
5552
{
5653
return _lastManaged;
5754
}
@@ -90,7 +87,7 @@ public Com2PictureConverter(Com2PropertyDescriptor property)
9087

9188
public override VARIANT ConvertManagedToNative(object? managedValue, Com2PropertyDescriptor property, ref bool cancelSet)
9289
{
93-
if (managedValue == _lastManaged)
90+
if (managedValue is not null && managedValue == _lastManaged)
9491
{
9592
// There should be no point in setting the same object back for this property.
9693
cancelSet = true;
@@ -123,16 +120,15 @@ public override VARIANT ConvertManagedToNative(object? managedValue, Com2Propert
123120
using ComScope<IPicture> picture = new(null);
124121
PInvokeCore.OleCreatePictureIndirect(&pictdesc, IID.Get<IPicture>(), own, picture).ThrowOnFailure();
125122
_lastManaged = managedValue;
126-
picture.Value->get_Handle(out var nativeHandle).ThrowOnFailure();
127-
_lastNativeHandle = nativeHandle;
123+
picture.Value->get_Handle(out _lastNativeHandle).ThrowOnFailure();
128124
IUnknown* unknown;
129125
picture.Value->QueryInterface(IID.Get<IUnknown>(), (void**)&unknown).ThrowOnFailure();
130126
return (VARIANT)unknown;
131127
}
132128
else
133129
{
134130
_lastManaged = null;
135-
_lastNativeHandle = null;
131+
_lastNativeHandle = default;
136132
return VARIANT.Empty;
137133
}
138134
}

0 commit comments

Comments
 (0)