diff --git a/PInvoke/Cryptography/NCrypt/NCrypt.cs b/PInvoke/Cryptography/NCrypt/NCrypt.cs index f795e88a..07e49bb7 100644 --- a/PInvoke/Cryptography/NCrypt/NCrypt.cs +++ b/PInvoke/Cryptography/NCrypt/NCrypt.cs @@ -5084,7 +5084,9 @@ public static partial class NCrypt /// public NCryptBuffer[] pBuffers { +#pragma warning disable CA2021 // Do not call Enumerable.Cast or Enumerable.OfType with incompatible types get => _pBuffers.ToIEnum<_NCryptBuffer>((int)cBuffers).Cast().ToArray(); +#pragma warning restore CA2021 // Do not call Enumerable.Cast or Enumerable.OfType with incompatible types set { ((IDisposable)this).Dispose(); diff --git a/PInvoke/Gdi32/WinGdi.DevCtxt.cs b/PInvoke/Gdi32/WinGdi.DevCtxt.cs index c92c4954..94acb5bb 100644 --- a/PInvoke/Gdi32/WinGdi.DevCtxt.cs +++ b/PInvoke/Gdi32/WinGdi.DevCtxt.cs @@ -659,7 +659,9 @@ public static partial class Gdi32 throw new ArgumentException($"The supplied type cannot be enumerated by this function."); var l = new List(); EnumObjects(hdc, ev, EnumProc); +#pragma warning disable CA2021 // Do not call Enumerable.Cast or Enumerable.OfType with incompatible types return l.Cast(); +#pragma warning restore CA2021 // Do not call Enumerable.Cast or Enumerable.OfType with incompatible types int EnumProc(IntPtr Arg1, IntPtr Arg2) { diff --git a/Windows.Shell/ShellDataObject.cs b/Windows.Shell/ShellDataObject.cs index b06ac126..4561c195 100644 --- a/Windows.Shell/ShellDataObject.cs +++ b/Windows.Shell/ShellDataObject.cs @@ -35,7 +35,7 @@ public class ShellDataObject : DataObject /// Initializes a new instance of the class. /// A list of ShellItem instances. - public ShellDataObject(IEnumerable items) : base((items as ShellItemArray ?? new ShellItemArray(items)).ToDataObject()) + public ShellDataObject(IEnumerable items) : base((items as ShellItemArray ?? new ShellItemArray(items)).ToDataObject()!) { } @@ -58,7 +58,7 @@ public class ShellDataObject : DataObject /// public System.Globalization.CultureInfo Culture { - get => base.GetDataPresent(DataFormats.Locale) ? new((int)base.GetData(DataFormats.Locale, false)) : System.Globalization.CultureInfo.CurrentCulture; + get => base.GetDataPresent(DataFormats.Locale) ? new((int)base.GetData(DataFormats.Locale, false)!) : System.Globalization.CultureInfo.CurrentCulture; set => base.SetData(DataFormats.Locale, false, value.LCID); } @@ -74,7 +74,7 @@ public class ShellDataObject : DataObject /// if the data object is within a drag-and-drop loop; otherwise, . public bool InDragLoop { - get => base.GetDataPresent(ShellClipboardFormat.CFSTR_INDRAGLOOP) && (int)base.GetData(ShellClipboardFormat.CFSTR_INDRAGLOOP, false) != 0; + get => base.GetDataPresent(ShellClipboardFormat.CFSTR_INDRAGLOOP) && (int)base.GetData(ShellClipboardFormat.CFSTR_INDRAGLOOP, false)! != 0; set => base.SetData(ShellClipboardFormat.CFSTR_INDRAGLOOP, false, value ? 1 : 0); } @@ -109,7 +109,7 @@ public class ShellDataObject : DataObject /// Specifies whether its preferred method of data transfer is move or copy. public DragDropEffects PreferredDropEffect { - get => base.GetDataPresent(ShellClipboardFormat.CFSTR_PREFERREDDROPEFFECT) ? (DragDropEffects)(int)base.GetData(ShellClipboardFormat.CFSTR_PREFERREDDROPEFFECT, false) : 0; + get => base.GetDataPresent(ShellClipboardFormat.CFSTR_PREFERREDDROPEFFECT) ? (DragDropEffects)(int)base.GetData(ShellClipboardFormat.CFSTR_PREFERREDDROPEFFECT, false)! : 0; set => base.SetData(ShellClipboardFormat.CFSTR_PREFERREDDROPEFFECT, false, (int)value); } @@ -124,7 +124,7 @@ public class ShellDataObject : DataObject /// The CLSID. public Guid TargetClsid { - get => base.GetDataPresent(ShellClipboardFormat.CFSTR_TARGETCLSID) ? (Guid)base.GetData(ShellClipboardFormat.CFSTR_TARGETCLSID, false) : default; + get => base.GetDataPresent(ShellClipboardFormat.CFSTR_TARGETCLSID) ? (Guid)base.GetData(ShellClipboardFormat.CFSTR_TARGETCLSID, false)! : default; set => base.SetData(ShellClipboardFormat.CFSTR_TARGETCLSID, false, value); } @@ -187,7 +187,7 @@ public class ShellDataObject : DataObject case ShellClipboardFormat.CFSTR_SHELLIDLIST: return GetShellIdList() ?? new ShellItemArray(); } - return base.GetData(format, autoConvert); + return base.GetData(format, autoConvert)!; } /// Retrieves the data associated with the specified data format at the specified index. @@ -272,7 +272,7 @@ public class ShellDataObject : DataObject /// The data. /// /// Data value must be of type DROPDESCRIPTION., nameof(data) - public override void SetData(string format, object data) + public override void SetData(string format, object? data) { if (format == ShellClipboardFormat.CFSTR_DROPDESCRIPTION) { diff --git a/Windows.Shell/ShellObjects/ShellBrowser.cs b/Windows.Shell/ShellObjects/ShellBrowser.cs index 4524fcfa..9af1e5f5 100644 --- a/Windows.Shell/ShellObjects/ShellBrowser.cs +++ b/Windows.Shell/ShellObjects/ShellBrowser.cs @@ -242,7 +242,7 @@ public class ShellBrowser : UserControl, IWin32Window, IShellBrowser, Shell32.IS /// [Bindable(false), Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public override Image BackgroundImage => base.BackgroundImage; + public override Image BackgroundImage => base.BackgroundImage!; /// protected override Size DefaultSize => new(200, 150); @@ -614,7 +614,7 @@ public class ShellBrowser : UserControl, IWin32Window, IShellBrowser, Shell32.IS { var forward = (keyData & Keys.Shift) != Keys.Shift; - Parent.SelectNextControl(ActiveControl, forward: forward, tabStopOnly: true, nested: true, wrap: true); + Parent!.SelectNextControl(ActiveControl, forward: forward, tabStopOnly: true, nested: true, wrap: true); return true; } diff --git a/Windows.Shell/TaskBar/ImageIndexer.cs b/Windows.Shell/TaskBar/ImageIndexer.cs index db54dace..2b81b516 100644 --- a/Windows.Shell/TaskBar/ImageIndexer.cs +++ b/Windows.Shell/TaskBar/ImageIndexer.cs @@ -10,7 +10,7 @@ public partial class ThumbnailToolbarButton private string key = string.Empty; private bool useIntegerIndex = true; - public virtual int ActualIndex => useIntegerIndex ? Index : (ImageList is null ? -1 : ImageList.Images.IndexOfKey(Key)); + public virtual int ActualIndex => useIntegerIndex ? Index : (ImageList is null ? -1 : ImageList.Images.IndexOfKey(Key ?? "")); public virtual ImageList? ImageList { get; set; }