Skip to content

Commit 145c93a

Browse files
now uses the generic version of Marshal.PtrToStructure and SizeOf
1 parent 78079b8 commit 145c93a

4 files changed

Lines changed: 8 additions & 6 deletions

File tree

CompressedFileViewer/PluginInfrastructure/GatewayDomain.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,15 +171,17 @@ private void _initNativeStruct()
171171
private void _readNativeStruct()
172172
{
173173
if (_ptrSciTextRange != nint.Zero)
174-
_sciTextRange = (Sci_TextRange)Marshal.PtrToStructure(_ptrSciTextRange, typeof(Sci_TextRange))!;
174+
_sciTextRange = Marshal.PtrToStructure<Sci_TextRange>(_ptrSciTextRange)!;
175175
}
176176

177177
public void Dispose()
178178
{
179179
if (!_disposed)
180180
{
181-
if (_sciTextRange.lpstrText != nint.Zero) Marshal.FreeHGlobal(_sciTextRange.lpstrText);
182-
if (_ptrSciTextRange != nint.Zero) Marshal.FreeHGlobal(_ptrSciTextRange);
181+
if (_sciTextRange.lpstrText != nint.Zero)
182+
Marshal.FreeHGlobal(_sciTextRange.lpstrText);
183+
if (_ptrSciTextRange != nint.Zero)
184+
Marshal.FreeHGlobal(_ptrSciTextRange);
183185
_disposed = true;
184186
}
185187
}

CompressedFileViewer/PluginInfrastructure/NppPluginNETHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public class FuncItems : IDisposable
5050
public FuncItems()
5151
{
5252
Items = [];
53-
_sizeFuncItem = Marshal.SizeOf(typeof(FuncItem));
53+
_sizeFuncItem = Marshal.SizeOf<FuncItem>();
5454
_shortCutKeys = [];
5555
}
5656

CompressedFileViewer/PluginInfrastructure/Scintilla_iface.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3027,7 +3027,7 @@ private void _initNativeStruct()
30273027
private void _readNativeStruct()
30283028
{
30293029
if (_ptrSciTextToFind != nint.Zero)
3030-
_sciTextToFind = (Sci_TextToFind)Marshal.PtrToStructure(_ptrSciTextToFind, typeof(Sci_TextToFind))!;
3030+
_sciTextToFind = Marshal.PtrToStructure<Sci_TextToFind>(_ptrSciTextToFind)!;
30313031
}
30323032

30333033
private void _freeNativeString()

CompressedFileViewer/PluginInfrastructure/UnmanagedExports.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public static nint GetName()
4040
[UnmanagedCallersOnly(EntryPoint = "beNotified", CallConvs = [typeof(CallConvCdecl)])]
4141
public static void BeNotified(nint notifyCode)
4242
{
43-
ScNotification notification = (ScNotification)Marshal.PtrToStructure(notifyCode, typeof(ScNotification))!;
43+
ScNotification notification = Marshal.PtrToStructure<ScNotification>(notifyCode)!;
4444
if (notification.Header.Code == (uint)NppMsg.NPPN_TBMODIFICATION)
4545
{
4646
PluginBase._funcItems.RefreshItems();

0 commit comments

Comments
 (0)