diff --git a/src/System.Windows.Forms.Primitives/src/Interop/ComCtl32/Interop.TTOOLINFOW.cs b/src/System.Windows.Forms.Primitives/src/Interop/ComCtl32/Interop.TTOOLINFOW.cs index 413090c91a9..b78d5406002 100644 --- a/src/System.Windows.Forms.Primitives/src/Interop/ComCtl32/Interop.TTOOLINFOW.cs +++ b/src/System.Windows.Forms.Primitives/src/Interop/ComCtl32/Interop.TTOOLINFOW.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information. using System; +using System.Diagnostics.CodeAnalysis; using System.Runtime.InteropServices; internal static partial class Interop @@ -27,10 +28,11 @@ public struct ToolInfoWrapper where T : IHandle { public TTOOLINFOW Info; - public string Text { get; set; } + public string? Text { get; set; } + [MaybeNull] private readonly T _handle; - public unsafe ToolInfoWrapper(T handle, TTF flags = default, string text = null) + public unsafe ToolInfoWrapper(T handle, TTF flags = default, string? text = null) { Info = new TTOOLINFOW { @@ -42,7 +44,7 @@ public unsafe ToolInfoWrapper(T handle, TTF flags = default, string text = null) _handle = handle; } - public unsafe ToolInfoWrapper(T handle, IntPtr id, TTF flags = default, string text = null, RECT rect = default) + public unsafe ToolInfoWrapper(T handle, IntPtr id, TTF flags = default, string? text = null, RECT rect = default) { Info = new TTOOLINFOW { diff --git a/src/System.Windows.Forms.Primitives/src/Interop/Gdi32/Interop.BITMAPINFO.cs b/src/System.Windows.Forms.Primitives/src/Interop/Gdi32/Interop.BITMAPINFO.cs index 95c894032f5..311e3739f0f 100644 --- a/src/System.Windows.Forms.Primitives/src/Interop/Gdi32/Interop.BITMAPINFO.cs +++ b/src/System.Windows.Forms.Primitives/src/Interop/Gdi32/Interop.BITMAPINFO.cs @@ -16,7 +16,7 @@ public struct BITMAPINFO public BITMAPINFOHEADER bmiHeader; [MarshalAs(UnmanagedType.ByValArray, SizeConst = MaxColorSize * 4)] - public byte[] bmiColors; // RGBQUAD structs: repeating Blue-Green-Red-Reserved + public byte[]? bmiColors; // RGBQUAD structs: repeating Blue-Green-Red-Reserved } } } diff --git a/src/System.Windows.Forms.Primitives/src/Interop/Ole32/Interop.OLEVERB.cs b/src/System.Windows.Forms.Primitives/src/Interop/Ole32/Interop.OLEVERB.cs index e265d3e1655..4877b2a6467 100644 --- a/src/System.Windows.Forms.Primitives/src/Interop/Ole32/Interop.OLEVERB.cs +++ b/src/System.Windows.Forms.Primitives/src/Interop/Ole32/Interop.OLEVERB.cs @@ -13,7 +13,7 @@ public class OLEVERB { public OLEIVERB lVerb; [MarshalAs(UnmanagedType.LPWStr)] - public string lpszVerbName; + public string? lpszVerbName; public User32.MF fuFlags; public OLEVERBATTRIB grfAttribs; } diff --git a/src/System.Windows.Forms.Primitives/src/Interop/Ole32/Interop.QACONTAINER.cs b/src/System.Windows.Forms.Primitives/src/Interop/Ole32/Interop.QACONTAINER.cs index 0b37eed6373..fd22bf652d4 100644 --- a/src/System.Windows.Forms.Primitives/src/Interop/Ole32/Interop.QACONTAINER.cs +++ b/src/System.Windows.Forms.Primitives/src/Interop/Ole32/Interop.QACONTAINER.cs @@ -14,20 +14,20 @@ internal static partial class Ole32 public sealed class QACONTAINER { public uint cbSize; - public IOleClientSite pClientSite; - public IAdviseSink pAdviseSink; - public IPropertyNotifySink pPropertyNotifySink; + public IOleClientSite? pClientSite; + public IAdviseSink? pAdviseSink; + public IPropertyNotifySink? pPropertyNotifySink; [MarshalAs(UnmanagedType.Interface)] - public object pUnkEventSink; + public object? pUnkEventSink; public QACONTAINERFLAGS dwAmbientFlags; public uint colorFore; public uint colorBack; - public IFont pFont; + public IFont? pFont; public IntPtr pUndoMgr; public uint dwAppearance; public int lcid; public IntPtr hpal; - public IServiceProvider pBindHost; + public IServiceProvider? pBindHost; } } } diff --git a/src/System.Windows.Forms.Primitives/src/Interop/Ole32/Interop.STATSTG.cs b/src/System.Windows.Forms.Primitives/src/Interop/Ole32/Interop.STATSTG.cs index 705df8d4a53..5c56823fa7d 100644 --- a/src/System.Windows.Forms.Primitives/src/Interop/Ole32/Interop.STATSTG.cs +++ b/src/System.Windows.Forms.Primitives/src/Interop/Ole32/Interop.STATSTG.cs @@ -60,7 +60,7 @@ public struct STATSTG public uint grfStateBits; public uint reserved; - public string GetName() => Marshal.PtrToStringUni(pwcsName); + public string? GetName() => Marshal.PtrToStringUni(pwcsName); /// /// Caller is responsible for freeing the name memory. @@ -76,7 +76,7 @@ public void FreeName() /// /// Callee is repsonsible for allocating the name memory. /// - public void AllocName(string name) + public void AllocName(string? name) { pwcsName = Marshal.StringToCoTaskMemUni(name); } diff --git a/src/System.Windows.Forms.Primitives/src/Interop/Ole32/Interop.VARIANT.cs b/src/System.Windows.Forms.Primitives/src/Interop/Ole32/Interop.VARIANT.cs index c473e9c7526..90606cbcaea 100644 --- a/src/System.Windows.Forms.Primitives/src/Interop/Ole32/Interop.VARIANT.cs +++ b/src/System.Windows.Forms.Primitives/src/Interop/Ole32/Interop.VARIANT.cs @@ -42,7 +42,7 @@ public void Clear() ~VARIANT() => Clear(); - public object ToObject() + public object? ToObject() { IntPtr val = data1; long longVal; @@ -165,8 +165,8 @@ public object ToObject() return (val != IntPtr.Zero); case VARENUM.VARIANT: - VARIANT varStruct = Marshal.PtrToStructure(val); - return varStruct.ToObject(); + VARIANT? varStruct = Marshal.PtrToStructure(val); + return varStruct?.ToObject(); case VARENUM.CLSID: Guid guid = Marshal.PtrToStructure(val); diff --git a/src/System.Windows.Forms.Primitives/src/Interop/OleAut32/Interop.FONTDESC.cs b/src/System.Windows.Forms.Primitives/src/Interop/OleAut32/Interop.FONTDESC.cs index ec41290df97..462d969fbfa 100644 --- a/src/System.Windows.Forms.Primitives/src/Interop/OleAut32/Interop.FONTDESC.cs +++ b/src/System.Windows.Forms.Primitives/src/Interop/OleAut32/Interop.FONTDESC.cs @@ -13,7 +13,7 @@ internal static partial class Oleaut32 public struct FONTDESC { public uint cbSizeOfStruct; - public string lpstrName; + public string? lpstrName; public long cySize; public short sWeight; public short sCharset; diff --git a/src/System.Windows.Forms.Primitives/src/Interop/Shell32/Interop.DragQueryFileW.cs b/src/System.Windows.Forms.Primitives/src/Interop/Shell32/Interop.DragQueryFileW.cs index 06e0061fd41..eff5ec82ee8 100644 --- a/src/System.Windows.Forms.Primitives/src/Interop/Shell32/Interop.DragQueryFileW.cs +++ b/src/System.Windows.Forms.Primitives/src/Interop/Shell32/Interop.DragQueryFileW.cs @@ -11,7 +11,7 @@ internal static partial class Interop internal static partial class Shell32 { [DllImport(Libraries.Shell32, ExactSpelling = true, EntryPoint = "DragQueryFileW", CharSet = CharSet.Unicode)] - private static extern uint DragQueryFileWInternal(IntPtr hDrop, uint iFile, StringBuilder lpszFile, uint cch); + private static extern uint DragQueryFileWInternal(IntPtr hDrop, uint iFile, StringBuilder? lpszFile, uint cch); public static uint DragQueryFileW(IntPtr hDrop, uint iFile, StringBuilder lpszFile) { diff --git a/src/System.Windows.Forms.Primitives/src/Interop/Shell32/Interop.SHBrowseForFolder.cs b/src/System.Windows.Forms.Primitives/src/Interop/Shell32/Interop.SHBrowseForFolder.cs index bf5302b144d..ff14b01570d 100644 --- a/src/System.Windows.Forms.Primitives/src/Interop/Shell32/Interop.SHBrowseForFolder.cs +++ b/src/System.Windows.Forms.Primitives/src/Interop/Shell32/Interop.SHBrowseForFolder.cs @@ -34,15 +34,15 @@ public unsafe struct BROWSEINFO { public IntPtr hwndOwner; - public CoTaskMemSafeHandle pidlRoot; + public CoTaskMemSafeHandle? pidlRoot; public char* pszDisplayName; - public string lpszTitle; + public string? lpszTitle; public uint ulFlags; - public BrowseCallbackProc lpfn; + public BrowseCallbackProc? lpfn; public IntPtr lParam; diff --git a/src/System.Windows.Forms.Primitives/src/Interop/Shell32/Interop.SHGetPathFromIDListLongPath.cs b/src/System.Windows.Forms.Primitives/src/Interop/Shell32/Interop.SHGetPathFromIDListLongPath.cs index 3ce069b5548..c8b338eeb82 100644 --- a/src/System.Windows.Forms.Primitives/src/Interop/Shell32/Interop.SHGetPathFromIDListLongPath.cs +++ b/src/System.Windows.Forms.Primitives/src/Interop/Shell32/Interop.SHGetPathFromIDListLongPath.cs @@ -12,7 +12,7 @@ internal static partial class Shell32 [DllImport(Libraries.Shell32, ExactSpelling = true)] private static extern BOOL SHGetPathFromIDListEx(IntPtr pidl, IntPtr pszPath, int cchPath, int flags); - public static bool SHGetPathFromIDListLongPath(IntPtr pidl, out string path) + public static bool SHGetPathFromIDListLongPath(IntPtr pidl, out string? path) { IntPtr pszPath = Marshal.AllocHGlobal((Kernel32.MAX_PATH + 1) * sizeof(char)); int length = Kernel32.MAX_PATH; diff --git a/src/System.Windows.Forms.Primitives/src/Interop/User32/Interop.DEVMODEW.cs b/src/System.Windows.Forms.Primitives/src/Interop/User32/Interop.DEVMODEW.cs index a825ccfbe10..7f61dec940c 100644 --- a/src/System.Windows.Forms.Primitives/src/Interop/User32/Interop.DEVMODEW.cs +++ b/src/System.Windows.Forms.Primitives/src/Interop/User32/Interop.DEVMODEW.cs @@ -17,7 +17,7 @@ public struct DEVMODEW private const int CCHFORMNAME = 32; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = CCHDEVICENAME)] - public string dmDeviceName; + public string? dmDeviceName; public ushort dmSpecVersion; public ushort dmDriverVersion; public ushort dmSize; @@ -33,7 +33,7 @@ public struct DEVMODEW public short dmTTOption; public short dmCollate; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = CCHFORMNAME)] - public string dmFormName; + public string? dmFormName; public ushort dmLogPixels; public uint dmBitsPerPel; public uint dmPelsWidth; diff --git a/src/System.Windows.Forms.Primitives/src/Interop/User32/Interop.EnumChildWindows.cs b/src/System.Windows.Forms.Primitives/src/Interop/User32/Interop.EnumChildWindows.cs index 873c299fd85..5b62cc42c76 100644 --- a/src/System.Windows.Forms.Primitives/src/Interop/User32/Interop.EnumChildWindows.cs +++ b/src/System.Windows.Forms.Primitives/src/Interop/User32/Interop.EnumChildWindows.cs @@ -50,7 +50,7 @@ public static BOOL EnumChildWindows(HandleRef hwndParent, EnumChildWindowsCallba private static BOOL HandleEnumChildWindowsNativeCallback(IntPtr hWnd, IntPtr lParam) { - return ((EnumChildWindowsCallback)GCHandle.FromIntPtr(lParam).Target)(hWnd); + return ((EnumChildWindowsCallback)GCHandle.FromIntPtr(lParam).Target!)(hWnd); } } } diff --git a/src/System.Windows.Forms.Primitives/src/Interop/User32/Interop.EnumThreadWindows.cs b/src/System.Windows.Forms.Primitives/src/Interop/User32/Interop.EnumThreadWindows.cs index 7fc58de358f..6865efe11a9 100644 --- a/src/System.Windows.Forms.Primitives/src/Interop/User32/Interop.EnumThreadWindows.cs +++ b/src/System.Windows.Forms.Primitives/src/Interop/User32/Interop.EnumThreadWindows.cs @@ -36,7 +36,7 @@ public static BOOL EnumThreadWindows(uint dwThreadId, EnumThreadWindowsCallback private static BOOL HandleEnumThreadWindowsNativeCallback(IntPtr hWnd, IntPtr lParam) { - return ((EnumThreadWindowsCallback)GCHandle.FromIntPtr(lParam).Target)(hWnd); + return ((EnumThreadWindowsCallback)GCHandle.FromIntPtr(lParam).Target!)(hWnd); } } } diff --git a/src/System.Windows.Forms.Primitives/src/Interop/User32/Interop.EnumWindows.cs b/src/System.Windows.Forms.Primitives/src/Interop/User32/Interop.EnumWindows.cs index 22593def9d1..92d765cf2e3 100644 --- a/src/System.Windows.Forms.Primitives/src/Interop/User32/Interop.EnumWindows.cs +++ b/src/System.Windows.Forms.Primitives/src/Interop/User32/Interop.EnumWindows.cs @@ -36,7 +36,7 @@ public static BOOL EnumWindows(EnumWindowsCallback lpEnumFunc) private static BOOL HandleEnumWindowsNativeCallback(IntPtr hWnd, IntPtr lParam) { - return ((EnumWindowsCallback)GCHandle.FromIntPtr(lParam).Target)(hWnd); + return ((EnumWindowsCallback)GCHandle.FromIntPtr(lParam).Target!)(hWnd); } } } diff --git a/src/System.Windows.Forms.Primitives/src/Interop/User32/Interop.GetClipboardFormatNameW.cs b/src/System.Windows.Forms.Primitives/src/Interop/User32/Interop.GetClipboardFormatNameW.cs index 440ce5ad200..131fb04f74d 100644 --- a/src/System.Windows.Forms.Primitives/src/Interop/User32/Interop.GetClipboardFormatNameW.cs +++ b/src/System.Windows.Forms.Primitives/src/Interop/User32/Interop.GetClipboardFormatNameW.cs @@ -13,7 +13,7 @@ internal static partial class User32 [DllImport(Libraries.User32, ExactSpelling = true)] private static unsafe extern int GetClipboardFormatNameW(uint format, char* lpszFormatName, int cchMaxCount); - public static unsafe string GetClipboardFormatNameW(uint format) + public static unsafe string? GetClipboardFormatNameW(uint format) { // The max length of the name of clipboard formats is equal to the max length // of a Win32 Atom of 255 chars. An additional null terminator character is added, diff --git a/src/System.Windows.Forms.Primitives/src/System.Windows.Forms.Primitives.csproj b/src/System.Windows.Forms.Primitives/src/System.Windows.Forms.Primitives.csproj index d0f3929ac43..f8489af8aff 100644 --- a/src/System.Windows.Forms.Primitives/src/System.Windows.Forms.Primitives.csproj +++ b/src/System.Windows.Forms.Primitives/src/System.Windows.Forms.Primitives.csproj @@ -4,6 +4,7 @@ System.Windows.Forms.Primitives true true + enable $(NoWarn);618 true diff --git a/src/System.Windows.Forms.Primitives/src/System/ComponentModel/CompModSwitches.cs b/src/System.Windows.Forms.Primitives/src/System/ComponentModel/CompModSwitches.cs index 60e71c1319a..dd78fd8c0b8 100644 --- a/src/System.Windows.Forms.Primitives/src/System/ComponentModel/CompModSwitches.cs +++ b/src/System.Windows.Forms.Primitives/src/System/ComponentModel/CompModSwitches.cs @@ -8,39 +8,39 @@ namespace System.ComponentModel { internal static class CompModSwitches { - private static TraceSwitch activeX; - private static TraceSwitch flowLayout; - private static TraceSwitch dataCursor; - private static TraceSwitch dataGridCursor; - private static TraceSwitch dataGridEditing; - private static TraceSwitch dataGridKeys; - private static TraceSwitch dataGridLayout; - private static TraceSwitch dataGridPainting; - private static TraceSwitch dataGridParents; - private static TraceSwitch dataGridScrolling; - private static TraceSwitch dataGridSelection; - private static TraceSwitch dataObject; - private static TraceSwitch dataView; - private static TraceSwitch debugGridView; - private static TraceSwitch dgCaptionPaint; - private static TraceSwitch dgEditColumnEditing; - private static TraceSwitch dgRelationShpRowLayout; - private static TraceSwitch dgRelationShpRowPaint; - private static TraceSwitch dgRowPaint; - private static TraceSwitch dragDrop; - private static TraceSwitch imeMode; - private static TraceSwitch msaa; - private static TraceSwitch msoComponentManager; - private static TraceSwitch layoutPerformance; - private static TraceSwitch layoutSuspendResume; - private static TraceSwitch richLayout; - private static TraceSwitch setBounds; - - private static BooleanSwitch lifetimeTracing; - - private static TraceSwitch s_handleLeak; - private static BooleanSwitch s_traceCollect; - private static BooleanSwitch s_commonDesignerServices; + private static TraceSwitch? activeX; + private static TraceSwitch? flowLayout; + private static TraceSwitch? dataCursor; + private static TraceSwitch? dataGridCursor; + private static TraceSwitch? dataGridEditing; + private static TraceSwitch? dataGridKeys; + private static TraceSwitch? dataGridLayout; + private static TraceSwitch? dataGridPainting; + private static TraceSwitch? dataGridParents; + private static TraceSwitch? dataGridScrolling; + private static TraceSwitch? dataGridSelection; + private static TraceSwitch? dataObject; + private static TraceSwitch? dataView; + private static TraceSwitch? debugGridView; + private static TraceSwitch? dgCaptionPaint; + private static TraceSwitch? dgEditColumnEditing; + private static TraceSwitch? dgRelationShpRowLayout; + private static TraceSwitch? dgRelationShpRowPaint; + private static TraceSwitch? dgRowPaint; + private static TraceSwitch? dragDrop; + private static TraceSwitch? imeMode; + private static TraceSwitch? msaa; + private static TraceSwitch? msoComponentManager; + private static TraceSwitch? layoutPerformance; + private static TraceSwitch? layoutSuspendResume; + private static TraceSwitch? richLayout; + private static TraceSwitch? setBounds; + + private static BooleanSwitch? lifetimeTracing; + + private static TraceSwitch? s_handleLeak; + private static BooleanSwitch? s_traceCollect; + private static BooleanSwitch? s_commonDesignerServices; public static TraceSwitch ActiveX { diff --git a/src/System.Windows.Forms.Primitives/src/System/Windows/Forms/FileDialogCustomPlace.cs b/src/System.Windows.Forms.Primitives/src/System/Windows/Forms/FileDialogCustomPlace.cs index c10e0b37132..f2f97edcdce 100644 --- a/src/System.Windows.Forms.Primitives/src/System/Windows/Forms/FileDialogCustomPlace.cs +++ b/src/System.Windows.Forms.Primitives/src/System/Windows/Forms/FileDialogCustomPlace.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using System.Diagnostics.CodeAnalysis; using static Interop; namespace System.Windows.Forms @@ -18,7 +19,7 @@ public class FileDialogCustomPlace private string _path = string.Empty; private Guid _knownFolderGuid = Guid.Empty; - public FileDialogCustomPlace(string path) + public FileDialogCustomPlace(string? path) { Path = path; } @@ -28,6 +29,7 @@ public FileDialogCustomPlace(Guid knownFolderGuid) KnownFolderGuid = knownFolderGuid; } + [AllowNull] public string Path { get => _path ?? string.Empty; @@ -58,7 +60,7 @@ public override string ToString() /// to an actual filesystem directory. /// The caller is responsible for handling these situations. /// - internal FileDialogNative.IShellItem GetNativePath() + internal FileDialogNative.IShellItem? GetNativePath() { string filePathString; if (!string.IsNullOrEmpty(_path)) diff --git a/src/System.Windows.Forms.Primitives/src/System/Windows/Forms/FileDialogCustomPlacesCollection.cs b/src/System.Windows.Forms.Primitives/src/System/Windows/Forms/FileDialogCustomPlacesCollection.cs index 9ee2816c1aa..2742636796c 100644 --- a/src/System.Windows.Forms.Primitives/src/System/Windows/Forms/FileDialogCustomPlacesCollection.cs +++ b/src/System.Windows.Forms.Primitives/src/System/Windows/Forms/FileDialogCustomPlacesCollection.cs @@ -18,7 +18,7 @@ internal void Apply(FileDialogNative.IFileDialog dialog) try { - FileDialogNative.IShellItem shellItem = customPlace.GetNativePath(); + FileDialogNative.IShellItem? shellItem = customPlace.GetNativePath(); if (null != shellItem) { dialog.AddPlace(shellItem, 0); @@ -32,7 +32,7 @@ internal void Apply(FileDialogNative.IFileDialog dialog) } } - public void Add(string path) => Add(new FileDialogCustomPlace(path)); + public void Add(string? path) => Add(new FileDialogCustomPlace(path)); public void Add(Guid knownFolderGuid) => Add(new FileDialogCustomPlace(knownFolderGuid)); } diff --git a/src/System.Windows.Forms.Primitives/src/System/Windows/Forms/Internals/ClientUtils.cs b/src/System.Windows.Forms.Primitives/src/System/Windows/Forms/Internals/ClientUtils.cs index d73f0327537..92e3fdcb55e 100644 --- a/src/System.Windows.Forms.Primitives/src/System/Windows/Forms/Internals/ClientUtils.cs +++ b/src/System.Windows.Forms.Primitives/src/System/Windows/Forms/Internals/ClientUtils.cs @@ -4,6 +4,7 @@ using System.Collections; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.Numerics; @@ -146,7 +147,7 @@ public static int GetWordBoundaryStart(char[] text, int endIndex) #if DEBUG [ThreadStatic] - private static Hashtable enumValueInfo; + private static Hashtable? enumValueInfo; public const int MAXCACHE = 300; // we think we're going to get O(100) of these, put in a tripwire if it gets larger. private class SequentialEnumInfo @@ -157,7 +158,9 @@ public SequentialEnumInfo(Type t) int actualMaximum = int.MinValue; int countEnumVals = 0; +#pragma warning disable CS8605 // Unboxing a possibly null value. foreach (int iVal in Enum.GetValues(t)) +#pragma warning restore CS8605 // Unboxing a possibly null value. { actualMinimum = Math.Min(actualMinimum, iVal); actualMaximum = Math.Max(actualMaximum, iVal); @@ -184,7 +187,7 @@ private static void Debug_SequentialEnumIsDefinedCheck(Enum value, int minVal, i enumValueInfo = new Hashtable(); } - SequentialEnumInfo sequentialEnumInfo = null; + SequentialEnumInfo? sequentialEnumInfo = null; if (enumValueInfo.ContainsKey(t)) { @@ -218,7 +221,9 @@ private static void Debug_ValidateMask(Enum value, uint mask) { Type t = value.GetType(); uint newmask = 0; +#pragma warning disable CS8605 // Unboxing a possibly null value. foreach (int iVal in Enum.GetValues(t)) +#pragma warning restore CS8605 // Unboxing a possibly null value. { newmask |= (uint)iVal; } @@ -232,7 +237,9 @@ private static void Debug_NonSequentialEnumIsDefinedCheck(Enum value, int minVal int checkedValue = Convert.ToInt32(value, CultureInfo.InvariantCulture); int maxBitsFound = 0; bool foundValue = false; +#pragma warning disable CS8605 // Unboxing a possibly null value. foreach (int iVal in Enum.GetValues(t)){ +#pragma warning restore CS8605 // Unboxing a possibly null value. actualMinimum = Math.Min(actualMinimum, iVal); actualMaximum = Math.Max(actualMaximum, iVal); maxBitsFound = Math.Max(maxBitsFound, BitOperations.PopCount((uint)iVal)); @@ -295,7 +302,7 @@ public WeakRefCollection(int size) /// public int RefCheckThreshold { get; set; } = int.MaxValue; // this means this is disabled by default. - public object this[int index] + public object? this[int index] { get { @@ -315,7 +322,7 @@ public void ScavengeReferences() int currentCount = Count; for (int i = 0; i < currentCount; i++) { - object item = this[currentIndex]; + object? item = this[currentIndex]; if (item == null) { @@ -329,9 +336,9 @@ public void ScavengeReferences() } } - public override bool Equals(object obj) + public override bool Equals(object? obj) { - WeakRefCollection other = obj as WeakRefCollection; + WeakRefCollection? other = obj as WeakRefCollection; if (other == this) { return true; @@ -346,7 +353,7 @@ public override bool Equals(object obj) { if (InnerList[i] != other.InnerList[i]) { - if (InnerList[i] == null || !InnerList[i].Equals(other.InnerList[i])) + if (InnerList[i] == null || !InnerList[i]!.Equals(other.InnerList[i])) { return false; } @@ -359,7 +366,7 @@ public override bool Equals(object obj) public override int GetHashCode() { var hash = new HashCode(); - foreach (object o in InnerList) + foreach (object? o in InnerList) { hash.Add(o); } @@ -367,7 +374,8 @@ public override int GetHashCode() return hash.ToHashCode(); } - private WeakRefObject CreateWeakRefObject(object value) + [return: NotNullIfNotNull("value")] + private WeakRefObject? CreateWeakRefObject(object? value) { if (value == null) { @@ -416,7 +424,7 @@ public void RemoveByHashCode(object value) int hash = value.GetHashCode(); for (int idx = 0; idx < InnerList.Count; idx++) { - if (InnerList[idx] != null && InnerList[idx].GetHashCode() == hash) + if (InnerList[idx] != null && InnerList[idx]!.GetHashCode() == hash) { RemoveAt(idx); return; @@ -428,17 +436,17 @@ public void RemoveByHashCode(object value) public bool IsFixedSize => InnerList.IsFixedSize; - public bool Contains(object value) => InnerList.Contains(CreateWeakRefObject(value)); + public bool Contains(object? value) => InnerList.Contains(CreateWeakRefObject(value)); public void RemoveAt(int index) => InnerList.RemoveAt(index); - public void Remove(object value) => InnerList.Remove(CreateWeakRefObject(value)); + public void Remove(object? value) => InnerList.Remove(CreateWeakRefObject(value)); - public int IndexOf(object value) => InnerList.IndexOf(CreateWeakRefObject(value)); + public int IndexOf(object? value) => InnerList.IndexOf(CreateWeakRefObject(value)); - public void Insert(int index, object value) => InnerList.Insert(index, CreateWeakRefObject(value)); + public void Insert(int index, object? value) => InnerList.Insert(index, CreateWeakRefObject(value)); - public int Add(object value) + public int Add(object? value) { if (Count > RefCheckThreshold) { @@ -483,7 +491,7 @@ internal bool IsAlive get { return weakHolder.IsAlive; } } - internal object Target + internal object? Target { get { @@ -493,9 +501,9 @@ internal object Target public override int GetHashCode() => hash; - public override bool Equals(object obj) + public override bool Equals(object? obj) { - WeakRefObject other = obj as WeakRefObject; + WeakRefObject? other = obj as WeakRefObject; if (other == this) { diff --git a/src/System.Windows.Forms.Primitives/src/System/Windows/Forms/Internals/DpiHelper.cs b/src/System.Windows.Forms.Primitives/src/System/Windows/Forms/Internals/DpiHelper.cs index 5e4e2088271..63d3853bbf8 100644 --- a/src/System.Windows.Forms.Primitives/src/System/Windows/Forms/Internals/DpiHelper.cs +++ b/src/System.Windows.Forms.Primitives/src/System/Windows/Forms/Internals/DpiHelper.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using System.Diagnostics.CodeAnalysis; using System.Drawing; using System.Drawing.Drawing2D; using static Interop; @@ -288,7 +289,8 @@ public static Size LogicalToDeviceUnits(Size logicalSize, int deviceDpi = 0) /// /// The image to scale from logical units to device units /// The size to scale image to - public static Bitmap CreateResizedBitmap(Bitmap logicalImage, Size targetImageSize) + [return: NotNullIfNotNull("logicalImage")] + public static Bitmap? CreateResizedBitmap(Bitmap? logicalImage, Size targetImageSize) { if (logicalImage == null) { diff --git a/src/System.Windows.Forms.Primitives/src/System/Windows/Forms/Internals/FileDialog_Vista_Interop.cs b/src/System.Windows.Forms.Primitives/src/System/Windows/Forms/Internals/FileDialog_Vista_Interop.cs index 148cacf0a09..3da56211f49 100644 --- a/src/System.Windows.Forms.Primitives/src/System/Windows/Forms/Internals/FileDialog_Vista_Interop.cs +++ b/src/System.Windows.Forms.Primitives/src/System/Windows/Forms/Internals/FileDialog_Vista_Interop.cs @@ -12,7 +12,7 @@ internal static class FileDialogNative { internal static IShellItem GetShellItemForPath(string path) { - IShellItem ret = null; + IShellItem? ret = null; IntPtr pidl = IntPtr.Zero; uint zero = 0; if (UnsafeNativeMethods.Shell32.SHILCreateFromPath(path, out pidl, ref zero) >= 0) @@ -412,9 +412,9 @@ public enum SIGDN : uint public struct COMDLG_FILTERSPEC { [MarshalAs(UnmanagedType.LPWStr)] - public string pszName; + public string? pszName; [MarshalAs(UnmanagedType.LPWStr)] - public string pszSpec; + public string? pszSpec; } public enum CDCONTROLSTATE diff --git a/src/System.Windows.Forms.Primitives/src/System/Windows/Forms/Internals/MessageDecoder.cs b/src/System.Windows.Forms.Primitives/src/System/Windows/Forms/Internals/MessageDecoder.cs index 08caf7dc3fa..8062cf03fdf 100644 --- a/src/System.Windows.Forms.Primitives/src/System/Windows/Forms/Internals/MessageDecoder.cs +++ b/src/System.Windows.Forms.Primitives/src/System/Windows/Forms/Internals/MessageDecoder.cs @@ -17,9 +17,9 @@ internal static class MessageDecoder /// Returns the symbolic name of the msg value, or null if it isn't one of the /// existing constants. /// - private static string MsgToString(int msg) + private static string? MsgToString(int msg) { - string text; + string? text; switch (msg) { case (int)WM.NULL: @@ -839,7 +839,7 @@ private static string MsgToString(int msg) return text; } - private static string Parenthesize(string input) + private static string Parenthesize(string? input) { if (input == null) { diff --git a/src/System.Windows.Forms.Primitives/src/System/Windows/Forms/Internals/NativeMethods.cs b/src/System.Windows.Forms.Primitives/src/System/Windows/Forms/Internals/NativeMethods.cs index 827d62e8f68..b7075ba70c4 100644 --- a/src/System.Windows.Forms.Primitives/src/System/Windows/Forms/Internals/NativeMethods.cs +++ b/src/System.Windows.Forms.Primitives/src/System/Windows/Forms/Internals/NativeMethods.cs @@ -183,11 +183,11 @@ public class HH_AKLINK { internal int cbStruct = Marshal.SizeOf(); internal bool fReserved = false; - internal string pszKeywords = null; - internal string pszUrl = null; - internal string pszMsgText = null; - internal string pszMsgTitle = null; - internal string pszWindow = null; + internal string? pszKeywords = null; + internal string? pszUrl = null; + internal string? pszMsgText = null; + internal string? pszMsgTitle = null; + internal string? pszWindow = null; internal bool fIndexOnFail = false; } @@ -202,7 +202,7 @@ public class HH_POPUP internal int clrForeground = -1; internal int clrBackground = -1; internal RECT rcMargins = new RECT(-1, -1, -1, -1); // amount of space between edges of window and text, -1 for each member to ignore - internal string pszFont = null; + internal string? pszFont = null; } public const int HH_FTS_DEFAULT_PROXIMITY = -1; @@ -213,13 +213,13 @@ public class HH_FTS_QUERY internal int cbStruct = Marshal.SizeOf(); internal bool fUniCodeStrings = false; [MarshalAs(UnmanagedType.LPStr)] - internal string pszSearchQuery = null; + internal string? pszSearchQuery = null; internal int iProximity = NativeMethods.HH_FTS_DEFAULT_PROXIMITY; internal bool fStemmedSearch = false; internal bool fTitleOnly = false; internal bool fExecute = true; [MarshalAs(UnmanagedType.LPStr)] - internal string pszWindow = null; + internal string? pszWindow = null; } public delegate int EditStreamCallback(IntPtr dwCookie, IntPtr buf, int cb, out int transferred); @@ -229,7 +229,7 @@ public class EDITSTREAM { public IntPtr dwCookie = IntPtr.Zero; public int dwError = 0; - public EditStreamCallback pfnCallback = null; + public EditStreamCallback? pfnCallback = null; } [StructLayout(LayoutKind.Sequential)] @@ -266,11 +266,11 @@ public interface PRINTDLG IntPtr hInstance { get; set; } IntPtr lCustData { get; set; } - WndProc lpfnPrintHook { get; set; } - WndProc lpfnSetupHook { get; set; } + WndProc? lpfnPrintHook { get; set; } + WndProc? lpfnSetupHook { get; set; } - string lpPrintTemplateName { get; set; } - string lpSetupTemplateName { get; set; } + string? lpPrintTemplateName { get; set; } + string? lpSetupTemplateName { get; set; } IntPtr hPrintTemplate { get; set; } IntPtr hSetupTemplate { get; set; } @@ -297,11 +297,11 @@ public class PRINTDLG_32 : PRINTDLG IntPtr m_hInstance; IntPtr m_lCustData; - WndProc m_lpfnPrintHook; - WndProc m_lpfnSetupHook; + WndProc? m_lpfnPrintHook; + WndProc? m_lpfnSetupHook; - string m_lpPrintTemplateName; - string m_lpSetupTemplateName; + string? m_lpPrintTemplateName; + string? m_lpSetupTemplateName; IntPtr m_hPrintTemplate; IntPtr m_hSetupTemplate; @@ -324,11 +324,11 @@ public class PRINTDLG_32 : PRINTDLG public IntPtr hInstance { get { return m_hInstance; } set { m_hInstance = value; } } public IntPtr lCustData { get { return m_lCustData; } set { m_lCustData = value; } } - public WndProc lpfnPrintHook { get { return m_lpfnPrintHook; } set { m_lpfnPrintHook = value; } } - public WndProc lpfnSetupHook { get { return m_lpfnSetupHook; } set { m_lpfnSetupHook = value; } } + public WndProc? lpfnPrintHook { get { return m_lpfnPrintHook; } set { m_lpfnPrintHook = value; } } + public WndProc? lpfnSetupHook { get { return m_lpfnSetupHook; } set { m_lpfnSetupHook = value; } } - public string lpPrintTemplateName { get { return m_lpPrintTemplateName; } set { m_lpPrintTemplateName = value; } } - public string lpSetupTemplateName { get { return m_lpSetupTemplateName; } set { m_lpSetupTemplateName = value; } } + public string? lpPrintTemplateName { get { return m_lpPrintTemplateName; } set { m_lpPrintTemplateName = value; } } + public string? lpSetupTemplateName { get { return m_lpSetupTemplateName; } set { m_lpSetupTemplateName = value; } } public IntPtr hPrintTemplate { get { return m_hPrintTemplate; } set { m_hPrintTemplate = value; } } public IntPtr hSetupTemplate { get { return m_hSetupTemplate; } set { m_hSetupTemplate = value; } } @@ -355,11 +355,11 @@ public class PRINTDLG_64 : PRINTDLG IntPtr m_hInstance; IntPtr m_lCustData; - WndProc m_lpfnPrintHook; - WndProc m_lpfnSetupHook; + WndProc? m_lpfnPrintHook; + WndProc? m_lpfnSetupHook; - string m_lpPrintTemplateName; - string m_lpSetupTemplateName; + string? m_lpPrintTemplateName; + string? m_lpSetupTemplateName; IntPtr m_hPrintTemplate; IntPtr m_hSetupTemplate; @@ -382,11 +382,11 @@ public class PRINTDLG_64 : PRINTDLG public IntPtr hInstance { get { return m_hInstance; } set { m_hInstance = value; } } public IntPtr lCustData { get { return m_lCustData; } set { m_lCustData = value; } } - public WndProc lpfnPrintHook { get { return m_lpfnPrintHook; } set { m_lpfnPrintHook = value; } } - public WndProc lpfnSetupHook { get { return m_lpfnSetupHook; } set { m_lpfnSetupHook = value; } } + public WndProc? lpfnPrintHook { get { return m_lpfnPrintHook; } set { m_lpfnPrintHook = value; } } + public WndProc? lpfnSetupHook { get { return m_lpfnSetupHook; } set { m_lpfnSetupHook = value; } } - public string lpPrintTemplateName { get { return m_lpPrintTemplateName; } set { m_lpPrintTemplateName = value; } } - public string lpSetupTemplateName { get { return m_lpSetupTemplateName; } set { m_lpSetupTemplateName = value; } } + public string? lpPrintTemplateName { get { return m_lpPrintTemplateName; } set { m_lpPrintTemplateName = value; } } + public string? lpSetupTemplateName { get { return m_lpSetupTemplateName; } set { m_lpSetupTemplateName = value; } } public IntPtr hPrintTemplate { get { return m_hPrintTemplate; } set { m_hPrintTemplate = value; } } public IntPtr hSetupTemplate { get { return m_hSetupTemplate; } set { m_hSetupTemplate = value; } } @@ -418,9 +418,9 @@ public class PRINTDLGEX public IntPtr hInstance; [MarshalAs(UnmanagedType.LPStr)] - public string lpPrintTemplateName; + public string? lpPrintTemplateName; - public WndProc lpCallback = null; + public WndProc? lpCallback = null; public int nPropertyPages; @@ -448,14 +448,14 @@ public class NOTIFYICONDATA public int uCallbackMessage; public IntPtr hIcon; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)] - public string szTip; + public string? szTip; public int dwState = 0; public int dwStateMask = 0; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)] - public string szInfo; + public string? szInfo; public int uTimeoutOrVersion; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 64)] - public string szInfoTitle; + public string? szInfoTitle; public int dwInfoFlags; } @@ -464,7 +464,7 @@ public struct MSAAMENUINFO { public int dwMSAASignature; public int cchWText; - public string pszWText; + public string? pszWText; public MSAAMENUINFO(string text) { @@ -480,7 +480,7 @@ public class OPENFILENAME_I public int lStructSize = Marshal.SizeOf(); //ndirect.DllLib.sizeOf(this); public IntPtr hwndOwner; public IntPtr hInstance; - public string lpstrFilter; // use embedded nulls to separate filters + public string? lpstrFilter; // use embedded nulls to separate filters public IntPtr lpstrCustomFilter = IntPtr.Zero; public int nMaxCustFilter = 0; public int nFilterIndex; @@ -488,15 +488,15 @@ public class OPENFILENAME_I public int nMaxFile = Kernel32.MAX_PATH; public IntPtr lpstrFileTitle = IntPtr.Zero; public int nMaxFileTitle = Kernel32.MAX_PATH; - public string lpstrInitialDir; - public string lpstrTitle; + public string? lpstrInitialDir; + public string? lpstrTitle; public int Flags; public short nFileOffset = 0; public short nFileExtension = 0; - public string lpstrDefExt; + public string? lpstrDefExt; public IntPtr lCustData = IntPtr.Zero; - public WndProc lpfnHook; - public string lpTemplateName = null; + public WndProc? lpfnHook; + public string? lpTemplateName = null; public IntPtr pvReserved = IntPtr.Zero; public int dwReserved = 0; public int FlagsEx; diff --git a/src/System.Windows.Forms.Primitives/src/System/Windows/Forms/Internals/UnsafeNativeMethods.cs b/src/System.Windows.Forms.Primitives/src/System/Windows/Forms/Internals/UnsafeNativeMethods.cs index 872d8dff1f4..50cb79c4662 100644 --- a/src/System.Windows.Forms.Primitives/src/System/Windows/Forms/Internals/UnsafeNativeMethods.cs +++ b/src/System.Windows.Forms.Primitives/src/System/Windows/Forms/Internals/UnsafeNativeMethods.cs @@ -154,9 +154,9 @@ public static StringBuilder GetModuleFileNameLongPath(HandleRef hModule) [DllImport(ExternDll.Gdi32, SetLastError = true, ExactSpelling = true, CharSet = System.Runtime.InteropServices.CharSet.Auto)] public static extern int GetRegionData(HandleRef hRgn, int size, IntPtr lpRgnData); - public unsafe static RECT[] GetRectsFromRegion(IntPtr hRgn) + public unsafe static RECT[]? GetRectsFromRegion(IntPtr hRgn) { - RECT[] regionRects = null; + RECT[]? regionRects = null; IntPtr pBytes = IntPtr.Zero; try { diff --git a/src/System.Windows.Forms.Primitives/src/System/Windows/Forms/Message.cs b/src/System.Windows.Forms.Primitives/src/System/Windows/Forms/Message.cs index 7eea3f97f8f..2b2e501815f 100644 --- a/src/System.Windows.Forms.Primitives/src/System/Windows/Forms/Message.cs +++ b/src/System.Windows.Forms.Primitives/src/System/Windows/Forms/Message.cs @@ -30,7 +30,7 @@ public struct Message /// /// Gets the value, and converts the value to an object. /// - public object GetLParam(Type cls) => Marshal.PtrToStructure(LParam, cls); + public object? GetLParam(Type cls) => Marshal.PtrToStructure(LParam, cls); internal static Message Create(IntPtr hWnd, User32.WM msg, IntPtr wparam, IntPtr lparam) => Create(hWnd, (int)msg, wparam, lparam); @@ -55,7 +55,7 @@ public static Message Create(IntPtr hWnd, int msg, IntPtr wparam, IntPtr lparam) return m; } - public override bool Equals(object o) + public override bool Equals(object? o) { if (!(o is Message m)) { diff --git a/src/System.Windows.Forms.Primitives/src/System/Windows/Forms/Padding.cs b/src/System.Windows.Forms.Primitives/src/System/Windows/Forms/Padding.cs index 773c467d84e..5de20edf938 100644 --- a/src/System.Windows.Forms.Primitives/src/System/Windows/Forms/Padding.cs +++ b/src/System.Windows.Forms.Primitives/src/System/Windows/Forms/Padding.cs @@ -130,7 +130,7 @@ public int Top public static Padding Subtract(Padding p1, Padding p2) => p1 - p2; - public override bool Equals(object other) + public override bool Equals(object? other) { if (!(other is Padding otherPadding)) { diff --git a/src/System.Windows.Forms.Primitives/src/System/Windows/Forms/PaddingConverter.cs b/src/System.Windows.Forms.Primitives/src/System/Windows/Forms/PaddingConverter.cs index 7dbf266269d..023b24ed707 100644 --- a/src/System.Windows.Forms.Primitives/src/System/Windows/Forms/PaddingConverter.cs +++ b/src/System.Windows.Forms.Primitives/src/System/Windows/Forms/PaddingConverter.cs @@ -16,7 +16,7 @@ public class PaddingConverter : TypeConverter /// Determines if this converter can convert an object in the given source type to /// the native type of the converter. /// - public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) + public override bool CanConvertFrom(ITypeDescriptorContext? context, Type sourceType) { if (sourceType == typeof(string)) { @@ -26,7 +26,7 @@ public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceT return base.CanConvertFrom(context, sourceType); } - public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) + public override bool CanConvertTo(ITypeDescriptorContext? context, Type destinationType) { if (destinationType == typeof(InstanceDescriptor)) { @@ -39,7 +39,7 @@ public override bool CanConvertTo(ITypeDescriptorContext context, Type destinati /// /// Converts the given object to the converter's native type. /// - public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) + public override object? ConvertFrom(ITypeDescriptorContext? context, CultureInfo? culture, object? value) { if (value is string stringValue) { @@ -75,7 +75,7 @@ public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo c return base.ConvertFrom(context, culture, value); } - public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) + public override object? ConvertTo(ITypeDescriptorContext? context, CultureInfo? culture, object? value, Type destinationType) { if (value is Padding padding) { @@ -120,7 +120,7 @@ public override object ConvertTo(ITypeDescriptorContext context, CultureInfo cul return base.ConvertTo(context, culture, value, destinationType); } - public override object CreateInstance(ITypeDescriptorContext context, IDictionary propertyValues) + public override object CreateInstance(ITypeDescriptorContext? context, IDictionary propertyValues) { if (propertyValues == null) { @@ -140,16 +140,16 @@ public override object CreateInstance(ITypeDescriptorContext context, IDictionar if (original is Padding originalPadding) { - int all = (int)propertyValues[nameof(Padding.All)]; + int all = (int)propertyValues[nameof(Padding.All)]!; if (originalPadding.All != all) return new Padding(all); } return new Padding( - (int)propertyValues[nameof(Padding.Left)], - (int)propertyValues[nameof(Padding.Top)], - (int)propertyValues[nameof(Padding.Right)], - (int)propertyValues[nameof(Padding.Bottom)] + (int)propertyValues[nameof(Padding.Left)]!, + (int)propertyValues[nameof(Padding.Top)]!, + (int)propertyValues[nameof(Padding.Right)]!, + (int)propertyValues[nameof(Padding.Bottom)]! ); } catch (InvalidCastException invalidCast) @@ -162,14 +162,14 @@ public override object CreateInstance(ITypeDescriptorContext context, IDictionar } } - public override bool GetCreateInstanceSupported(ITypeDescriptorContext context) => true; + public override bool GetCreateInstanceSupported(ITypeDescriptorContext? context) => true; - public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes) + public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext? context, object value, Attribute[] attributes) { PropertyDescriptorCollection props = TypeDescriptor.GetProperties(typeof(Padding), attributes); return props.Sort(new string[] { nameof(Padding.All), nameof(Padding.Left), nameof(Padding.Top), nameof(Padding.Right), nameof(Padding.Bottom) }); } - public override bool GetPropertiesSupported(ITypeDescriptorContext context) => true; + public override bool GetPropertiesSupported(ITypeDescriptorContext? context) => true; } } diff --git a/src/System.Windows.Forms.Primitives/tests/Interop/Mso/IMsoComponentManagerTests.cs b/src/System.Windows.Forms.Primitives/tests/Interop/Mso/IMsoComponentManagerTests.cs index 8ec521c08ec..e3ccfe5ef1b 100644 --- a/src/System.Windows.Forms.Primitives/tests/Interop/Mso/IMsoComponentManagerTests.cs +++ b/src/System.Windows.Forms.Primitives/tests/Interop/Mso/IMsoComponentManagerTests.cs @@ -14,8 +14,8 @@ public unsafe class IMsoComponentManagerTests : IClassFixture (IMsoComponentManager)Activator.CreateInstance( - typeof(Application).Assembly.GetType("System.Windows.Forms.Application+ComponentManager"), - nonPublic: true); + typeof(Application).Assembly.GetType("System.Windows.Forms.Application+ComponentManager")!, + nonPublic: true)!; [Fact] public void FDebugMessage_ReturnsTrue() diff --git a/src/System.Windows.Forms.Primitives/tests/Interop/User32/GetWindowTextTests.cs b/src/System.Windows.Forms.Primitives/tests/Interop/User32/GetWindowTextTests.cs index 1f40c99f426..bdc767d3eca 100644 --- a/src/System.Windows.Forms.Primitives/tests/Interop/User32/GetWindowTextTests.cs +++ b/src/System.Windows.Forms.Primitives/tests/Interop/User32/GetWindowTextTests.cs @@ -50,13 +50,13 @@ private void CallGetWindowText(bool useBeforeGetTextLengthCallback) private class ChangeWindowTextForm : Form { - public Func BeforeGetTextLengthCallback + public Func? BeforeGetTextLengthCallback { get; set; } - public Func BeforeGetTextCallback + public Func? BeforeGetTextCallback { get; set; @@ -66,7 +66,7 @@ protected override void WndProc(ref Message m) { if (m.Msg == (int)WM.GETTEXTLENGTH) { - string text = BeforeGetTextLengthCallback?.Invoke(); + string? text = BeforeGetTextLengthCallback?.Invoke(); if (text != null) { SetWindowTextW(m.HWnd, text); @@ -74,7 +74,7 @@ protected override void WndProc(ref Message m) } else if (m.Msg == (int)WM.GETTEXT) { - string text = BeforeGetTextCallback?.Invoke(); + string? text = BeforeGetTextCallback?.Invoke(); if (text != null) { SetWindowTextW(m.HWnd, text); diff --git a/src/System.Windows.Forms.Primitives/tests/System.Windows.Forms.Primitives.Tests.csproj b/src/System.Windows.Forms.Primitives/tests/System.Windows.Forms.Primitives.Tests.csproj index e080b1c0b9d..4e6b7b3747b 100644 --- a/src/System.Windows.Forms.Primitives/tests/System.Windows.Forms.Primitives.Tests.csproj +++ b/src/System.Windows.Forms.Primitives/tests/System.Windows.Forms.Primitives.Tests.csproj @@ -3,6 +3,7 @@ System.Windows.Forms.Primitives.Tests true + enable