From 1f7538637b58ea9381a071eae40e060040db5b77 Mon Sep 17 00:00:00 2001 From: Julien Lebosquain Date: Sat, 9 Mar 2024 19:50:14 +0100 Subject: [PATCH] Warning fixes (#14894) * Fix CA1854 * Fix XML doc warnings * Don't use & operator in async methods * Use SetCurrentValue in DataGrid --- .../Unicode/PropertyValueAliasHelper.cs | 24 +++++++++---------- .../DataGridColumn.cs | 4 ++-- .../SimpleWebSocketHttpServer.cs | 8 +++---- src/Avalonia.Remote.Protocol/MetsysBson.cs | 21 +++++++++------- src/Skia/Avalonia.Skia/DrawingContextImpl.cs | 1 - .../Media/DrawingContextImpl.cs | 1 + 6 files changed, 31 insertions(+), 28 deletions(-) diff --git a/src/Avalonia.Base/Media/TextFormatting/Unicode/PropertyValueAliasHelper.cs b/src/Avalonia.Base/Media/TextFormatting/Unicode/PropertyValueAliasHelper.cs index 69814287ea..c3909ce2e0 100644 --- a/src/Avalonia.Base/Media/TextFormatting/Unicode/PropertyValueAliasHelper.cs +++ b/src/Avalonia.Base/Media/TextFormatting/Unicode/PropertyValueAliasHelper.cs @@ -175,11 +175,11 @@ namespace Avalonia.Media.TextFormatting.Unicode public static string GetTag(Script script) { - if(!s_scriptToTag.ContainsKey(script)) + if (!s_scriptToTag.TryGetValue(script, out var value)) { return "Zzzz"; } - return s_scriptToTag[script]; + return value; } private static readonly Dictionary s_tagToScript = @@ -353,11 +353,11 @@ namespace Avalonia.Media.TextFormatting.Unicode public static Script GetScript(string tag) { - if(!s_tagToScript.ContainsKey(tag)) + if (!s_tagToScript.TryGetValue(tag, out var value)) { return Script.Unknown; } - return s_tagToScript[tag]; + return value; } private static readonly Dictionary s_tagToGeneralCategory = @@ -404,11 +404,11 @@ namespace Avalonia.Media.TextFormatting.Unicode public static GeneralCategory GetGeneralCategory(string tag) { - if(!s_tagToGeneralCategory.ContainsKey(tag)) + if (!s_tagToGeneralCategory.TryGetValue(tag, out var value)) { return GeneralCategory.Other; } - return s_tagToGeneralCategory[tag]; + return value; } private static readonly Dictionary s_tagToLineBreakClass = @@ -460,11 +460,11 @@ namespace Avalonia.Media.TextFormatting.Unicode public static LineBreakClass GetLineBreakClass(string tag) { - if(!s_tagToLineBreakClass.ContainsKey(tag)) + if (!s_tagToLineBreakClass.TryGetValue(tag, out var value)) { return LineBreakClass.Unknown; } - return s_tagToLineBreakClass[tag]; + return value; } private static readonly Dictionary s_tagToBidiPairedBracketType = @@ -476,11 +476,11 @@ namespace Avalonia.Media.TextFormatting.Unicode public static BidiPairedBracketType GetBidiPairedBracketType(string tag) { - if(!s_tagToBidiPairedBracketType.ContainsKey(tag)) + if (!s_tagToBidiPairedBracketType.TryGetValue(tag, out var value)) { return BidiPairedBracketType.None; } - return s_tagToBidiPairedBracketType[tag]; + return value; } private static readonly Dictionary s_tagToBidiClass = @@ -512,11 +512,11 @@ namespace Avalonia.Media.TextFormatting.Unicode public static BidiClass GetBidiClass(string tag) { - if(!s_tagToBidiClass.ContainsKey(tag)) + if (!s_tagToBidiClass.TryGetValue(tag, out var value)) { return BidiClass.LeftToRight; } - return s_tagToBidiClass[tag]; + return value; } } diff --git a/src/Avalonia.Controls.DataGrid/DataGridColumn.cs b/src/Avalonia.Controls.DataGrid/DataGridColumn.cs index 9e435074ed..cc043a6ed9 100644 --- a/src/Avalonia.Controls.DataGrid/DataGridColumn.cs +++ b/src/Avalonia.Controls.DataGrid/DataGridColumn.cs @@ -1061,7 +1061,7 @@ namespace Avalonia.Controls _settingWidthInternally = true; try { - Width = width; + SetCurrentValue(WidthProperty, width); } finally { @@ -1079,7 +1079,7 @@ namespace Avalonia.Controls _setWidthInternalNoCallback = true; try { - Width = width; + SetCurrentValue(WidthProperty, width); } finally { diff --git a/src/Avalonia.DesignerSupport/Remote/HtmlTransport/SimpleWebSocketHttpServer.cs b/src/Avalonia.DesignerSupport/Remote/HtmlTransport/SimpleWebSocketHttpServer.cs index 3fb21fd6cb..69e50fae58 100644 --- a/src/Avalonia.DesignerSupport/Remote/HtmlTransport/SimpleWebSocketHttpServer.cs +++ b/src/Avalonia.DesignerSupport/Remote/HtmlTransport/SimpleWebSocketHttpServer.cs @@ -325,16 +325,16 @@ namespace Avalonia.DesignerSupport.Remote.HtmlTransport const byte endOfMessageBit = (byte)1u << 7; header.Mask = (byte) (endOfMessageBit | ((byte) type & 0xf)); - unsafe - { - Marshal.Copy(new IntPtr(&header), _sendHeaderBuffer, 0, headerLength); - } + CopyHeaderToBuffer(header, _sendHeaderBuffer, headerLength); await _stream.WriteAsync(_sendHeaderBuffer, 0, headerLength); await _stream.WriteAsync(data, offset, length); } } + private static unsafe void CopyHeaderToBuffer(WebSocketHeader source, byte[] destination, int headerLength) + => Marshal.Copy(new IntPtr(&source), destination, 0, headerLength); + struct Frame { public byte[] Data; diff --git a/src/Avalonia.Remote.Protocol/MetsysBson.cs b/src/Avalonia.Remote.Protocol/MetsysBson.cs index 3866cfe47b..01071a7b37 100644 --- a/src/Avalonia.Remote.Protocol/MetsysBson.cs +++ b/src/Avalonia.Remote.Protocol/MetsysBson.cs @@ -1588,11 +1588,12 @@ namespace Metsys.Bson.Configuration internal void AddMap(string property, string alias) { var type = typeof(T); - if (!_aliasMap.ContainsKey(type)) + if (!_aliasMap.TryGetValue(type, out var aliases)) { - _aliasMap[type] = new Dictionary(); + aliases = new Dictionary(); + _aliasMap[type] = aliases; } - _aliasMap[type][property] = alias; + aliases[property] = alias; } internal string AliasFor(Type type, string property) { @@ -1607,11 +1608,12 @@ namespace Metsys.Bson.Configuration public void AddIgnore(string name) { var type = typeof(T); - if (!_ignored.ContainsKey(type)) + if (!_ignored.TryGetValue(type, out var names)) { - _ignored[type] = new HashSet(); + names = new HashSet(); + _ignored[type] = names; } - _ignored[type].Add(name); + names.Add(name); } public bool IsIgnored(Type type, string name) { @@ -1622,11 +1624,12 @@ namespace Metsys.Bson.Configuration public void AddIgnoreIfNull(string name) { var type = typeof(T); - if (!_ignoredIfNull.ContainsKey(type)) + if (!_ignoredIfNull.TryGetValue(type, out var names)) { - _ignoredIfNull[type] = new HashSet(); + names = new HashSet(); + _ignoredIfNull[type] = names; } - _ignoredIfNull[type].Add(name); + names.Add(name); } public bool IsIgnoredIfNull(Type type, string name) { diff --git a/src/Skia/Avalonia.Skia/DrawingContextImpl.cs b/src/Skia/Avalonia.Skia/DrawingContextImpl.cs index 2fdb523287..bbce08b536 100644 --- a/src/Skia/Avalonia.Skia/DrawingContextImpl.cs +++ b/src/Skia/Avalonia.Skia/DrawingContextImpl.cs @@ -1397,7 +1397,6 @@ namespace Avalonia.Skia /// Create new render target compatible with this drawing context. /// /// The size of the render target. - /// The DPI of the render target. /// Whether the render target is being created for a layer. /// Pixel format. /// diff --git a/src/Windows/Avalonia.Direct2D1/Media/DrawingContextImpl.cs b/src/Windows/Avalonia.Direct2D1/Media/DrawingContextImpl.cs index e1d51f7054..7de448235a 100644 --- a/src/Windows/Avalonia.Direct2D1/Media/DrawingContextImpl.cs +++ b/src/Windows/Avalonia.Direct2D1/Media/DrawingContextImpl.cs @@ -34,6 +34,7 @@ namespace Avalonia.Direct2D1.Media /// An object to use to create layers. May be null, in which case a /// will created when a new layer is requested. /// + /// Whether to scale drawings according to the DPI of . /// An optional swap chain associated with this drawing context. /// An optional delegate to be called when context is disposed. public DrawingContextImpl(