Browse Source

Merge pull request #11288 from workgroupengineering/features/Analyzers/CA1854

feat: Enable Rule CA1854
pull/11304/head
Max Katz 3 years ago
committed by GitHub
parent
commit
85a2fc504d
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      .editorconfig
  2. 4
      src/Avalonia.Diagnostics/Diagnostics/Views/MainWindow.xaml.cs
  3. 9
      src/Avalonia.Remote.Protocol/MetsysBson.cs
  4. 4
      src/Windows/Avalonia.Win32/TrayIconImpl.cs

4
.editorconfig

@ -177,7 +177,9 @@ dotnet_diagnostic.CA1828.severity = warning
dotnet_diagnostic.CA1829.severity = warning dotnet_diagnostic.CA1829.severity = warning
#CA1847: Use string.Contains(char) instead of string.Contains(string) with single characters #CA1847: Use string.Contains(char) instead of string.Contains(string) with single characters
dotnet_diagnostic.CA1847.severity = warning dotnet_diagnostic.CA1847.severity = warning
#CACA2211:Non-constant fields should not be visible #CA1854: Prefer the IDictionary.TryGetValue(TKey, out TValue) method
dotnet_diagnostic.CA1854.severity = warning
#CA2211:Non-constant fields should not be visible
dotnet_diagnostic.CA2211.severity = error dotnet_diagnostic.CA2211.severity = error
# Wrapping preferences # Wrapping preferences

4
src/Avalonia.Diagnostics/Diagnostics/Views/MainWindow.xaml.cs

@ -237,9 +237,9 @@ namespace Avalonia.Diagnostics.Views
else else
{ {
//TODO Use Dictionary.Remove(Key, out Value) in netstandard 2.1 //TODO Use Dictionary.Remove(Key, out Value) in netstandard 2.1
if (_frozenPopupStates.ContainsKey(popup)) if (_frozenPopupStates.TryGetValue(popup, out var value))
{ {
_frozenPopupStates[popup].Dispose(); value.Dispose();
_frozenPopupStates.Remove(popup); _frozenPopupStates.Remove(popup);
} }
} }

9
src/Avalonia.Remote.Protocol/MetsysBson.cs

@ -715,7 +715,8 @@ namespace Metsys.Bson
public MagicProperty FindProperty(string name) public MagicProperty FindProperty(string name)
{ {
return _properties.ContainsKey(name) ? _properties[name] : null; _properties.TryGetValue(name, out var property);
return property;
} }
public static TypeHelper GetHelperForType(Type type) public static TypeHelper GetHelperForType(Type type)
@ -1196,7 +1197,9 @@ namespace Metsys.Bson
} }
object container = null; object container = null;
var property = typeHelper.FindProperty(name); var property = typeHelper.FindProperty(name);
var propertyType = property != null ? property.Type : _typeMap.ContainsKey(storageType) ? _typeMap[storageType] : typeof(object); var propertyType = property?.Type
?? (_typeMap.TryGetValue(storageType, out var type1) ? type1 : null)
?? typeof(object);
if (property != null && property.Setter == null) if (property != null && property.Setter == null)
{ {
container = property.Getter(instance); container = property.Getter(instance);
@ -1588,7 +1591,7 @@ namespace Metsys.Bson.Configuration
{ {
return property; return property;
} }
return map.ContainsKey(property) ? map[property] : property; return map.TryGetValue(property, out var value) ? value : property;
} }
public void AddIgnore<T>(string name) public void AddIgnore<T>(string name)

4
src/Windows/Avalonia.Win32/TrayIconImpl.cs

@ -41,9 +41,9 @@ namespace Avalonia.Win32
internal static void ProcWnd(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam) internal static void ProcWnd(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam)
{ {
if (msg == (int)CustomWindowsMessage.WM_TRAYMOUSE && s_trayIcons.ContainsKey(wParam.ToInt32())) if (msg == (int)CustomWindowsMessage.WM_TRAYMOUSE && s_trayIcons.TryGetValue(wParam.ToInt32(), out var value))
{ {
s_trayIcons[wParam.ToInt32()].WndProc(hWnd, msg, wParam, lParam); value.WndProc(hWnd, msg, wParam, lParam);
} }
if (msg == WM_TASKBARCREATED) if (msg == WM_TASKBARCREATED)

Loading…
Cancel
Save