Skip to content
This repository was archived by the owner on Jul 26, 2023. It is now read-only.

Commit c2d9860

Browse files
committed
Use C# sizeof wherever possible
`sizeof(T)` is much faster than `Marshal.SizeOf<T>`, but it can only be safely used when `T` is a blittable type. This means all members are value types and have no `MarshalAs` attribute on them. This rule is recursive for all members. Closes #475
1 parent 51cba65 commit c2d9860

35 files changed

+52
-174
lines changed

src/BCrypt.Tests/BCryptFacts.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ public unsafe void MultiHash()
397397
using (hash)
398398
{
399399
var ops = new BCRYPT_MULTI_HASH_OPERATION[parallelism];
400-
int opsSize = parallelism * Marshal.SizeOf<BCRYPT_MULTI_HASH_OPERATION>();
400+
int opsSize = parallelism * sizeof(BCRYPT_MULTI_HASH_OPERATION);
401401
fixed (byte* dataPtr = data)
402402
{
403403
for (int i = 0; i < ops.Length; i++)

src/BCrypt/BCrypt+BCRYPT_AUTHENTICATED_CIPHER_MODE_INFO.cs

+1-5
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,7 @@ public static BCRYPT_AUTHENTICATED_CIPHER_MODE_INFO Create()
129129
{
130130
return new BCRYPT_AUTHENTICATED_CIPHER_MODE_INFO
131131
{
132-
#if NETSTANDARD2_0_ORLATER || NETFX_CORE
133-
cbSize = Marshal.SizeOf<BCRYPT_AUTHENTICATED_CIPHER_MODE_INFO>(),
134-
#else
135-
cbSize = Marshal.SizeOf(typeof(BCRYPT_AUTHENTICATED_CIPHER_MODE_INFO)),
136-
#endif
132+
cbSize = sizeof(BCRYPT_AUTHENTICATED_CIPHER_MODE_INFO),
137133
dwInfoVersion = BCRYPT_AUTHENTICATED_CIPHER_MODE_INFO_VERSION,
138134
};
139135
}

src/BCrypt/BCrypt+BCRYPT_KEY_DATA_BLOB_HEADER.cs

+2-6
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,9 @@ public static byte[] InsertBeforeKey(byte[] keyMaterial)
7676
return header.AddHeaderToKey(keyMaterial);
7777
}
7878

79-
private byte[] AddHeaderToKey(byte[] keyMaterial)
79+
private unsafe byte[] AddHeaderToKey(byte[] keyMaterial)
8080
{
81-
#if NETSTANDARD2_0_ORLATER || NETFX_CORE
82-
int headerLength = Marshal.SizeOf<BCRYPT_KEY_DATA_BLOB_HEADER>();
83-
#else
84-
int headerLength = Marshal.SizeOf(typeof(BCRYPT_KEY_DATA_BLOB_HEADER));
85-
#endif
81+
int headerLength = sizeof(BCRYPT_KEY_DATA_BLOB_HEADER);
8682
byte[] keyWithHeader = new byte[headerLength + keyMaterial.Length];
8783
Array.Copy(BitConverter.GetBytes((uint)this.dwMagic), keyWithHeader, sizeof(uint));
8884
Array.Copy(BitConverter.GetBytes(this.dwVersion), 0, keyWithHeader, sizeof(uint), sizeof(uint));

src/CfgMgr32.Tests/CfgMgr32Facts.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class CfgMgr32Facts
1717
[Fact]
1818
public void CM_NOTIFY_FILTER_Test()
1919
{
20-
Assert.Equal(0x1a0, Marshal.SizeOf<CM_NOTIFY_FILTER>());
20+
Assert.Equal(0x1a0, CM_NOTIFY_FILTER.Create().cbSize);
2121
}
2222

2323
[Fact]

src/Fusion/MSCorEE+ASSEMBLY_INFO.cs

+1-7
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,7 @@ public unsafe partial struct ASSEMBLY_INFO
4646
/// with the <see cref="cbAssemblyInfo"/> field initialized.
4747
/// </summary>
4848
/// <returns>The newly initialized struct.</returns>
49-
public static ASSEMBLY_INFO Create()
50-
{
51-
return new ASSEMBLY_INFO
52-
{
53-
cbAssemblyInfo = (uint)Marshal.SizeOf(typeof(ASSEMBLY_INFO)),
54-
};
55-
}
49+
public static ASSEMBLY_INFO Create() => new ASSEMBLY_INFO { cbAssemblyInfo = (uint)sizeof(ASSEMBLY_INFO) };
5650
}
5751
}
5852
}

src/Hid/Hid+HiddAttributes.cs

+1-6
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,7 @@ public struct HiddAttributes
3535
/// </summary>
3636
public ushort VersionNumber;
3737

38-
public static HiddAttributes Create()
39-
{
40-
var result = default(HiddAttributes);
41-
result.Size = Marshal.SizeOf(result);
42-
return result;
43-
}
38+
public unsafe static HiddAttributes Create() => new HiddAttributes { Size = sizeof(HiddAttributes) };
4439
}
4540
}
4641
}

src/IPHlpApi.Tests/IPHlpApiFacts.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
public class IPHlpApiFacts
1212
{
1313
[Fact]
14-
public void StructSizeTest()
14+
public unsafe void StructSizeTest()
1515
{
16-
Assert.Equal(0x04, Marshal.SizeOf<IPHlpApi.MIB_TCPTABLE_OWNER_PID>());
17-
Assert.Equal(0x18, Marshal.SizeOf<IPHlpApi.MIB_TCPROW_OWNER_PID>());
16+
Assert.Equal(0x04, sizeof(IPHlpApi.MIB_TCPTABLE_OWNER_PID));
17+
Assert.Equal(0x18, sizeof(IPHlpApi.MIB_TCPROW_OWNER_PID));
1818
}
1919

2020
[Fact]
@@ -32,7 +32,7 @@ public unsafe void GetExtendedTcpTableTest()
3232
if (IPHlpApi.GetExtendedTcpTable(tcpTablePtr, ref tcpTableLength, bOrder: true, AddressFamily.InterNetwork, IPHlpApi.TCP_TABLE_CLASS.TCP_TABLE_OWNER_PID_ALL, 0) == Win32ErrorCode.ERROR_SUCCESS)
3333
{
3434
IPHlpApi.MIB_TCPTABLE_OWNER_PID* tcpTable = (IPHlpApi.MIB_TCPTABLE_OWNER_PID*)tcpTablePtr;
35-
var tableSize = Marshal.SizeOf<IPHlpApi.MIB_TCPTABLE_OWNER_PID>();
35+
var tableSize = sizeof(IPHlpApi.MIB_TCPTABLE_OWNER_PID);
3636

3737
IPHlpApi.MIB_TCPROW_OWNER_PID* tcpRow = (IPHlpApi.MIB_TCPROW_OWNER_PID*)(tcpTablePtr + tableSize);
3838

src/Kernel32/Kernel32+OSVERSIONINFOEX.cs

+1-8
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,7 @@ public unsafe partial struct OSVERSIONINFOEX
8282
/// the right pre-initialization for <see cref="dwOSVersionInfoSize"/>
8383
/// </summary>
8484
/// <returns>A newly initialzed instance of <see cref="OSVERSIONINFOEX"/></returns>
85-
public static OSVERSIONINFOEX Create() => new OSVERSIONINFOEX
86-
{
87-
#if NETSTANDARD2_0_ORLATER || NETFX_CORE
88-
dwOSVersionInfoSize = Marshal.SizeOf<OSVERSIONINFOEX>()
89-
#else
90-
dwOSVersionInfoSize = Marshal.SizeOf(typeof(OSVERSIONINFOEX))
91-
#endif
92-
};
85+
public static OSVERSIONINFOEX Create() => new OSVERSIONINFOEX { dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX) };
9386
}
9487
}
9588
}

src/Kernel32/Kernel32+SECURITY_ATTRIBUTES.cs

+1-11
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,7 @@ public struct SECURITY_ATTRIBUTES
4444
/// Initializes a new instance of the <see cref="SECURITY_ATTRIBUTES"/> struct.
4545
/// </summary>
4646
/// <returns>A new instance of <see cref="SECURITY_ATTRIBUTES"/>.</returns>
47-
public static SECURITY_ATTRIBUTES Create()
48-
{
49-
return new SECURITY_ATTRIBUTES
50-
{
51-
#if NETSTANDARD2_0_ORLATER || NETFX_CORE
52-
nLength = Marshal.SizeOf<SECURITY_ATTRIBUTES>(),
53-
#else
54-
nLength = Marshal.SizeOf(typeof(SECURITY_ATTRIBUTES)),
55-
#endif
56-
};
57-
}
47+
public static unsafe SECURITY_ATTRIBUTES Create() => new SECURITY_ATTRIBUTES { nLength = sizeof(SECURITY_ATTRIBUTES) };
5848
}
5949
}
6050
}

src/Kernel32/Kernel32.cs

+3-2
Original file line numberDiff line numberDiff line change
@@ -639,8 +639,9 @@ public static extern unsafe SafeObjectHandle CreateMutex(
639639
/// </summary>
640640
/// <param name="lpVersionInformation">
641641
/// A pointer to an OSVERSIONINFOEX structure containing the operating system version requirements to compare. The <paramref name="dwTypeMask"/>
642-
/// parameter indicates the members of this structure that contain information to compare.You must set the
643-
/// <see cref="OSVERSIONINFOEX.dwOSVersionInfoSize"/> member of this structure to <code>Marshal.SizeOf(typeof(OSVERSIONINFOEX))</code>. You must
642+
/// parameter indicates the members of this structure that contain information to compare. You must set the
643+
/// <see cref="OSVERSIONINFOEX.dwOSVersionInfoSize"/> member of this structure to <code>Marshal.SizeOf(typeof(OSVERSIONINFOEX))</code>
644+
/// or create it with <see cref="OSVERSIONINFOEX.Create"/>. You must
644645
/// also specify valid data for the members indicated by <paramref name="dwTypeMask"/>. The function ignores structure members for which the
645646
/// corresponding <paramref name="dwTypeMask"/> bit is not set
646647
/// </param>

src/Kernel32/storebanned/Kernel32+MODULEENTRY32.cs

+1-5
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,7 @@ public static MODULEENTRY32 Create()
111111
{
112112
return new MODULEENTRY32
113113
{
114-
#if NETSTANDARD2_0_ORLATER
115-
dwSize = Marshal.SizeOf<MODULEENTRY32>(),
116-
#else
117-
dwSize = Marshal.SizeOf(typeof(MODULEENTRY32)),
118-
#endif
114+
dwSize = sizeof(MODULEENTRY32),
119115
th32ModuleID = 1,
120116
};
121117
}

src/Kernel32/storebanned/Kernel32+PROCESSENTRY32.cs

+1-11
Original file line numberDiff line numberDiff line change
@@ -104,17 +104,7 @@ public string ExeFile
104104
/// with <see cref="dwSize" /> set to the correct value.
105105
/// </summary>
106106
/// <returns>An instance of <see cref="PROCESSENTRY32"/>.</returns>
107-
public static PROCESSENTRY32 Create()
108-
{
109-
return new PROCESSENTRY32
110-
{
111-
#if NETSTANDARD2_0_ORLATER
112-
dwSize = Marshal.SizeOf<PROCESSENTRY32>(),
113-
#else
114-
dwSize = Marshal.SizeOf(typeof(PROCESSENTRY32)),
115-
#endif
116-
};
117-
}
107+
public static PROCESSENTRY32 Create() => new PROCESSENTRY32 { dwSize = sizeof(PROCESSENTRY32) };
118108
}
119109
}
120110
}

src/Kernel32/storebanned/Kernel32+StartupInfo.cs

+1-11
Original file line numberDiff line numberDiff line change
@@ -134,17 +134,7 @@ public unsafe partial struct STARTUPINFO
134134
/// Initializes a new instance of the <see cref="STARTUPINFO"/> struct.
135135
/// </summary>
136136
/// <returns>An initialized instance of the struct.</returns>
137-
public static STARTUPINFO Create()
138-
{
139-
return new STARTUPINFO
140-
{
141-
#if NETSTANDARD2_0_ORLATER
142-
cb = Marshal.SizeOf<STARTUPINFO>(),
143-
#else
144-
cb = Marshal.SizeOf(typeof(STARTUPINFO)),
145-
#endif
146-
};
147-
}
137+
public static STARTUPINFO Create() => new STARTUPINFO { cb = sizeof(STARTUPINFO) };
148138
}
149139
}
150140
}

src/Magnification.Tests/MagnificationFacts.cs

+8-2
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,12 @@ public void InitializeThenDeinitialize()
1717
}
1818

1919
[Fact]
20-
public void MAGCOLOREFFECT_IsRightSize()
20+
public unsafe void MAGCOLOREFFECT_IsRightSize()
2121
{
2222
Assert.Equal(sizeof(float) * 5 * 5, Marshal.SizeOf<MAGCOLOREFFECT>());
23+
#pragma warning disable xUnit2000 // Constants and literals should be the expected argument
24+
Assert.Equal(sizeof(float) * 5 * 5, sizeof(MAGCOLOREFFECT));
25+
#pragma warning restore xUnit2000 // Constants and literals should be the expected argument
2326
}
2427

2528
[Fact]
@@ -43,9 +46,12 @@ public void MAGCOLOREFFECT_MultidimensionalArray()
4346
}
4447

4548
[Fact]
46-
public void MAGTRANSFORM_IsRightSize()
49+
public unsafe void MAGTRANSFORM_IsRightSize()
4750
{
4851
Assert.Equal(sizeof(float) * 3 * 3, Marshal.SizeOf<MAGTRANSFORM>());
52+
#pragma warning disable xUnit2000 // Constants and literals should be the expected argument
53+
Assert.Equal(sizeof(float) * 3 * 3, sizeof(MAGTRANSFORM));
54+
#pragma warning restore xUnit2000 // Constants and literals should be the expected argument
4955
}
5056

5157
[Fact]

src/NCrypt/NCrypt+NCRYPT_KEY_BLOB_HEADER.cs

+1-11
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,7 @@ public enum MagicNumber : uint
5252
/// with the <see cref="cbSize"/> field set appropriately.
5353
/// </summary>
5454
/// <returns>An initialized instance of the struct.</returns>
55-
public static NCRYPT_KEY_BLOB_HEADER Create()
56-
{
57-
return new NCRYPT_KEY_BLOB_HEADER
58-
{
59-
#if NETSTANDARD2_0_ORLATER || NETFX_CORE
60-
cbSize = Marshal.SizeOf<NCRYPT_KEY_BLOB_HEADER>(),
61-
#else
62-
cbSize = Marshal.SizeOf(typeof(NCRYPT_KEY_BLOB_HEADER)),
63-
#endif
64-
};
65-
}
55+
public unsafe static NCRYPT_KEY_BLOB_HEADER Create() => new NCRYPT_KEY_BLOB_HEADER { cbSize = sizeof(NCRYPT_KEY_BLOB_HEADER) };
6656
}
6757
}
6858
}

src/NTDll/NTDll+OBJECT_ATTRIBUTES.cs

+1-7
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,7 @@ public enum ObjectHandleAttributes
108108
/// Initializes a new instance of the <see cref="OBJECT_ATTRIBUTES"/> structure.
109109
/// </summary>
110110
/// <returns>An <see cref="OBJECT_ATTRIBUTES"/> instance with <see cref="Length"/> initialized.</returns>
111-
public static OBJECT_ATTRIBUTES Create()
112-
{
113-
return new OBJECT_ATTRIBUTES
114-
{
115-
Length = Marshal.SizeOf(typeof(OBJECT_ATTRIBUTES)),
116-
};
117-
}
111+
public static OBJECT_ATTRIBUTES Create() => new OBJECT_ATTRIBUTES { Length = sizeof(OBJECT_ATTRIBUTES) };
118112
}
119113
}
120114
}

src/SetupApi/SetupApi+SP_DEVICE_INTERFACE_DATA.cs

+2-6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
namespace PInvoke
55
{
66
using System;
7+
using System.Runtime.CompilerServices;
78
using System.Runtime.InteropServices;
89

910
/// <content>
@@ -43,12 +44,7 @@ public struct SP_DEVICE_INTERFACE_DATA
4344
/// Create an instance with <see cref="Size" /> set to the correct value.
4445
/// </summary>
4546
/// <returns>An instance of <see cref="SP_DEVICE_INTERFACE_DATA" /> with it's <see cref="Size" /> member set.</returns>
46-
public static SP_DEVICE_INTERFACE_DATA Create()
47-
{
48-
var result = default(SP_DEVICE_INTERFACE_DATA);
49-
result.Size = Marshal.SizeOf(result);
50-
return result;
51-
}
47+
public static unsafe SP_DEVICE_INTERFACE_DATA Create() => new SP_DEVICE_INTERFACE_DATA { Size = sizeof(SP_DEVICE_INTERFACE_DATA) };
5248
}
5349
}
5450
}

src/SetupApi/SetupApi+SP_DEVINFO_DATA.cs

+1-7
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,7 @@ public struct SP_DEVINFO_DATA
5353
/// with <see cref="cbSize" /> set to the correct value.
5454
/// </summary>
5555
/// <returns>An instance of <see cref="SP_DEVINFO_DATA"/>.</returns>
56-
public static SP_DEVINFO_DATA Create()
57-
{
58-
return new SP_DEVINFO_DATA
59-
{
60-
cbSize = Marshal.SizeOf(typeof(SP_DEVINFO_DATA)),
61-
};
62-
}
56+
public static unsafe SP_DEVINFO_DATA Create() => new SP_DEVINFO_DATA { cbSize = sizeof(SP_DEVINFO_DATA) };
6357
}
6458
}
6559
}

src/SetupApi/SetupApi+SP_DEVINSTALL_PARAMS.cs

+1-7
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,7 @@ public string DriverPathString
101101
/// with <see cref="cbSize" /> set to the correct value.
102102
/// </summary>
103103
/// <returns>An instance of <see cref="SP_DEVINSTALL_PARAMS"/>.</returns>
104-
public static SP_DEVINSTALL_PARAMS Create()
105-
{
106-
return new SP_DEVINSTALL_PARAMS
107-
{
108-
cbSize = Marshal.SizeOf(typeof(SP_DEVINSTALL_PARAMS)),
109-
};
110-
}
104+
public static SP_DEVINSTALL_PARAMS Create() => new SP_DEVINSTALL_PARAMS { cbSize = sizeof(SP_DEVINSTALL_PARAMS) };
111105
}
112106
}
113107
}

src/SetupApi/SetupApi+SP_DRVINFO_DATA.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public unsafe struct SP_DRVINFO_DATA
6969
/// with <see cref="cbSize" /> set to the correct value.
7070
/// </summary>
7171
/// <returns>An instance of <see cref="SP_DRVINFO_DATA"/>.</returns>
72-
public static SP_DRVINFO_DATA Create() => new SP_DRVINFO_DATA { cbSize = Marshal.SizeOf(typeof(SP_DRVINFO_DATA)) };
72+
public static SP_DRVINFO_DATA Create() => new SP_DRVINFO_DATA { cbSize = sizeof(SP_DRVINFO_DATA) };
7373
}
7474
}
7575
}

src/User32.Tests/User32Facts.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ public void SetWindowLongPtr_Test()
150150
}
151151

152152
[Fact]
153-
public void MENUBARINFO_MarshalSizeAsExpected()
153+
public unsafe void MENUBARINFO_MarshalSizeAsExpected()
154154
{
155155
MENUBARINFO info = default;
156156
int expectedSize = IntPtr.Size == 4 ? 0x20 : 0x30;

src/User32/PublicAPI.Unshipped.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ PInvoke.User32.MENUBARINFO.hMenu -> System.IntPtr
102102
PInvoke.User32.MENUBARINFO.hwndMenu -> System.IntPtr
103103
PInvoke.User32.MENUBARINFO.rcBar -> PInvoke.RECT
104104
PInvoke.User32.MENUINFO
105-
PInvoke.User32.MENUINFO.Create() -> PInvoke.User32.MENUINFO
106105
PInvoke.User32.MENUINFO.MENUINFO() -> void
107106
PInvoke.User32.MENUINFO.cbSize -> int
108107
PInvoke.User32.MENUINFO.cyMax -> uint
@@ -215,6 +214,7 @@ static PInvoke.User32.LoadCursor(System.IntPtr hInstance, char[] lpCursorName) -
215214
static PInvoke.User32.LoadImage(System.IntPtr hInst, System.IntPtr name, PInvoke.User32.ImageType type, int cx, int cy, PInvoke.User32.LoadImageFlags fuLoad) -> System.IntPtr
216215
static PInvoke.User32.LoadImage(System.IntPtr hInst, char[] name, PInvoke.User32.ImageType type, int cx, int cy, PInvoke.User32.LoadImageFlags fuLoad) -> System.IntPtr
217216
static PInvoke.User32.MENUBARINFO.Create() -> PInvoke.User32.MENUBARINFO
217+
static PInvoke.User32.MENUINFO.Create() -> PInvoke.User32.MENUINFO
218218
static PInvoke.User32.MsgWaitForMultipleObjectsEx(uint nCount, System.IntPtr pHandles, uint dwMilliseconds, PInvoke.User32.WakeMask dwWakeMask, PInvoke.User32.MsgWaitForMultipleObjectsExFlags dwFlags) -> uint
219219
static PInvoke.User32.MsgWaitForMultipleObjectsEx(uint nCount, System.IntPtr[] pHandles, uint dwMilliseconds, PInvoke.User32.WakeMask dwWakeMask, PInvoke.User32.MsgWaitForMultipleObjectsExFlags dwFlags) -> uint
220220
static PInvoke.User32.SetMenuItemInfo(System.IntPtr hMenu, uint uItem, bool fByPosition, PInvoke.User32.MENUITEMINFO lpmii) -> bool
@@ -281,4 +281,4 @@ static readonly PInvoke.User32.DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2 -> Sys
281281
static readonly PInvoke.User32.DPI_AWARENESS_CONTEXT_SYSTEM_AWARE -> System.IntPtr
282282
static readonly PInvoke.User32.DPI_AWARENESS_CONTEXT_UNAWARE -> System.IntPtr
283283
static readonly PInvoke.User32.DPI_AWARENESS_CONTEXT_UNAWARE_GDISCALED -> System.IntPtr
284-
static readonly PInvoke.User32.SafeCursorHandle.Null -> PInvoke.User32.SafeCursorHandle
284+
static readonly PInvoke.User32.SafeCursorHandle.Null -> PInvoke.User32.SafeCursorHandle

src/User32/USer32+HELPINFO.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public struct HELPINFO
2020
public uint dwContextId;
2121
public POINT MousePos;
2222

23-
public static HELPINFO Create() => new HELPINFO { cbSize = Marshal.SizeOf(typeof(HELPINFO)) };
23+
public static unsafe HELPINFO Create() => new HELPINFO { cbSize = sizeof(HELPINFO) };
2424
}
2525
}
2626
}

src/User32/User32+CURSORINFO.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public struct CURSORINFO
4343
/// <returns>
4444
/// An instance of the structure.
4545
/// </returns>
46-
public static CURSORINFO Create() => new CURSORINFO { cbSize = Marshal.SizeOf(typeof(CURSORINFO)) };
46+
public static unsafe CURSORINFO Create() => new CURSORINFO { cbSize = sizeof(CURSORINFO) };
4747
}
4848
}
4949
}

src/User32/User32+DISPLAY_DEVICE.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public unsafe struct DISPLAY_DEVICE
5252
/// <returns>
5353
/// An instance of the structure.
5454
/// </returns>
55-
public static DISPLAY_DEVICE Create() => new DISPLAY_DEVICE { cb = (uint)Marshal.SizeOf(typeof(DISPLAY_DEVICE)) };
55+
public static DISPLAY_DEVICE Create() => new DISPLAY_DEVICE { cb = (uint)sizeof(DISPLAY_DEVICE) };
5656
}
5757
}
5858
}

src/User32/User32+FLASHWINFO.cs

+1-7
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,7 @@ public struct FLASHWINFO
3737
/// Create a new instance of <see cref="FLASHWINFO"/> with <see cref="cbSize"/> set to the correct value.
3838
/// </summary>
3939
/// <returns>A new instance of <see cref="FLASHWINFO"/> with <see cref="cbSize"/> set to the correct value.</returns>
40-
public static FLASHWINFO Create()
41-
{
42-
return new FLASHWINFO
43-
{
44-
cbSize = Marshal.SizeOf(typeof(FLASHWINFO))
45-
};
46-
}
40+
public static unsafe FLASHWINFO Create() => new FLASHWINFO { cbSize = sizeof(FLASHWINFO) };
4741
}
4842
}
4943
}

0 commit comments

Comments
 (0)