[Chore] Run solution code cleanup (#20584)

This commit is contained in:
Andrey Nekrasov
2022-09-16 11:54:58 +03:00
committed by GitHub
parent 09f4dead7f
commit ca3c758046
133 changed files with 108 additions and 359 deletions

View File

@@ -14,7 +14,6 @@ namespace ColorPicker
{
public static CompositionContainer Container { get; private set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Reliability", "CA2000:Dispose objects before losing scope", Justification = "This is properly disposed of in MainWindow.Xaml.cs")]
public static void InitializeContainer(object initPoint)
{
var catalog = new AssemblyCatalog(System.Reflection.Assembly.GetExecutingAssembly());

View File

@@ -233,9 +233,7 @@ namespace ColorPicker.Controls
DetailsFlyout.Hide();
}
#pragma warning disable CA1801 // Review unused parameters
private void DetailsFlyout_Closed(object sender, object e)
#pragma warning restore CA1801 // Review unused parameters
{
HideDetails();
AppStateHandler.BlockEscapeKeyClosingColorPickerEditor = false;
@@ -247,11 +245,7 @@ namespace ColorPicker.Controls
HexCode.Text = ColorToHex(_originalColor);
}
#pragma warning disable CA1822 // Mark members as static
#pragma warning disable CA1801 // Review unused parameters
private void DetailsFlyout_Opened(object sender, object e)
#pragma warning restore CA1801 // Review unused parameters
#pragma warning restore CA1822 // Mark members as static
{
AppStateHandler.BlockEscapeKeyClosingColorPickerEditor = true;
}
@@ -331,10 +325,7 @@ namespace ColorPicker.Controls
private static string ColorToHex(Color color, string oldValue = "")
{
string newHexString = BitConverter.ToString(new byte[] { color.R, color.G, color.B }).Replace("-", string.Empty, StringComparison.InvariantCulture);
#pragma warning disable CA1308 // Normalize strings to uppercase - Supressed because we want to show hex value in lower case on all places
newHexString = newHexString.ToLowerInvariant();
#pragma warning restore CA1308 // Normalize strings to uppercase
// Return only with hashtag if user typed it before
bool addHashtag = oldValue.StartsWith("#", StringComparison.InvariantCulture);

View File

@@ -212,9 +212,7 @@ namespace ColorPicker.Helpers
_hwndSource = hwndSource;
}
#pragma warning disable CA1801 // Review unused parameters
public IntPtr ProcessWindowMessages(IntPtr hwnd, int msg, IntPtr wparam, IntPtr lparam, ref bool handled)
#pragma warning restore CA1801 // Review unused parameters
{
switch (msg)
{

View File

@@ -17,7 +17,6 @@ namespace ColorPicker.Helpers
{
public static readonly HandleRef NullHandleRef = new HandleRef(null, IntPtr.Zero);
[System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA1801:Review unused parameters", Justification = "Interop")]
private MonitorResolutionHelper(IntPtr monitor, IntPtr hdc)
{
var info = new MonitorInfoEx();
@@ -74,7 +73,6 @@ namespace ColorPicker.Helpers
public ArrayList Monitors { get; private set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA1801:Review unused parameters", Justification = "Interop")]
public bool Callback(
IntPtr monitor,
IntPtr hdc,

View File

@@ -32,62 +32,58 @@ namespace ColorPicker.Helpers
switch (method)
{
case GroupExportedColorsBy.Color:
{
foreach (Color color in (IList)colorsToExport)
{
var tmp = new Dictionary<string, string>();
foreach (var colorFormatModel in colorFormatModels)
{
var colorInSpecificFormat = colorFormatModel.Convert(color);
if (colorFormatModel.FormatName == "HEX")
{
colorInSpecificFormat = "#" + colorInSpecificFormat;
}
tmp.Add(
colorFormatModel.FormatName,
#pragma warning disable CA1308 // Normalize strings to uppercase
colorInSpecificFormat.Replace(
colorFormatModel.FormatName.ToLower(CultureInfo.InvariantCulture),
string.Empty,
StringComparison.InvariantCultureIgnoreCase));
#pragma warning restore CA1308 // Normalize strings to uppercase
}
colors.Add($"color{i++}", tmp);
}
}
break;
case GroupExportedColorsBy.Format:
{
foreach (var colorFormatModel in colorFormatModels)
{
var tmp = new Dictionary<string, string>();
i = 1;
foreach (Color color in (IList)colorsToExport)
{
var colorInSpecificFormat = colorFormatModel.Convert(color);
if (colorFormatModel.FormatName == "HEX")
var tmp = new Dictionary<string, string>();
foreach (var colorFormatModel in colorFormatModels)
{
colorInSpecificFormat = "#" + colorInSpecificFormat;
var colorInSpecificFormat = colorFormatModel.Convert(color);
if (colorFormatModel.FormatName == "HEX")
{
colorInSpecificFormat = "#" + colorInSpecificFormat;
}
tmp.Add(
colorFormatModel.FormatName,
colorInSpecificFormat.Replace(
colorFormatModel.FormatName.ToLower(CultureInfo.InvariantCulture),
string.Empty,
StringComparison.InvariantCultureIgnoreCase));
}
tmp.Add(
$"color{i++}",
#pragma warning disable CA1308 // Normalize strings to uppercase
colorInSpecificFormat.Replace(
colorFormatModel.FormatName.ToLower(CultureInfo.InvariantCulture),
string.Empty,
StringComparison.InvariantCultureIgnoreCase));
#pragma warning restore CA1308 // Normalize strings to uppercase
colors.Add($"color{i++}", tmp);
}
colors.Add(colorFormatModel.FormatName, tmp);
}
}
break;
break;
case GroupExportedColorsBy.Format:
{
foreach (var colorFormatModel in colorFormatModels)
{
var tmp = new Dictionary<string, string>();
i = 1;
foreach (Color color in (IList)colorsToExport)
{
var colorInSpecificFormat = colorFormatModel.Convert(color);
if (colorFormatModel.FormatName == "HEX")
{
colorInSpecificFormat = "#" + colorInSpecificFormat;
}
tmp.Add(
$"color{i++}",
colorInSpecificFormat.Replace(
colorFormatModel.FormatName.ToLower(CultureInfo.InvariantCulture),
string.Empty,
StringComparison.InvariantCultureIgnoreCase));
}
colors.Add(colorFormatModel.FormatName, tmp);
}
}
break;
}
return colors;
@@ -121,9 +117,9 @@ namespace ColorPicker.Helpers
public static string ToJson(this Dictionary<string, Dictionary<string, string>> source, bool indented = true)
{
var options = new JsonSerializerOptions
{
WriteIndented = indented,
};
{
WriteIndented = indented,
};
return JsonSerializer.Serialize(source, options);
}

View File

@@ -17,53 +17,20 @@ namespace ColorPicker
{
private const int GWL_EX_STYLE = -20;
private const int WS_EX_TOOLWINDOW = 0x00000080;
[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.NamingRules", "SA1310:Field names should not contain underscore", Justification = "Interop")]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1707:Identifiers should not contain underscores", Justification = "Interop")]
public const int WH_KEYBOARD_LL = 13;
public const int VkSnapshot = 0x2c;
public const int KfAltdown = 0x2000;
public const int LlkhfAltdown = KfAltdown >> 8;
public const int MonitorinfofPrimary = 0x00000001;
[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.NamingRules", "SA1310:Field names should not contain underscore", Justification = "Interop")]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1707:Identifiers should not contain underscores", Justification = "Interop")]
public const int VK_SHIFT = 0x10;
[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.NamingRules", "SA1310:Field names should not contain underscore", Justification = "Interop")]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1707:Identifiers should not contain underscores", Justification = "Interop")]
public const int VK_CONTROL = 0x11;
[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.NamingRules", "SA1310:Field names should not contain underscore", Justification = "Interop")]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1707:Identifiers should not contain underscores", Justification = "Interop")]
public const int VK_MENU = 0x12;
[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.NamingRules", "SA1310:Field names should not contain underscore", Justification = "Interop")]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1707:Identifiers should not contain underscores", Justification = "Interop")]
public const int VK_LWIN = 0x5B;
[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.NamingRules", "SA1310:Field names should not contain underscore", Justification = "Interop")]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1707:Identifiers should not contain underscores", Justification = "Interop")]
public const int VK_RWIN = 0x5C;
[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.NamingRules", "SA1310:Field names should not contain underscore", Justification = "Interop")]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1707:Identifiers should not contain underscores", Justification = "Interop")]
public const int VK_ESCAPE = 0x1B;
[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.NamingRules", "SA1310:Field names should not contain underscore", Justification = "Interop")]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1707:Identifiers should not contain underscores", Justification = "Interop")]
public const int WM_HOTKEY = 0x0312;
[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.NamingRules", "SA1310:Field names should not contain underscore", Justification = "Interop")]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1707:Identifiers should not contain underscores", Justification = "Interop")]
public const int WM_KEYDOWN = 0x0100;
[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.NamingRules", "SA1310:Field names should not contain underscore", Justification = "Interop")]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1707:Identifiers should not contain underscores", Justification = "Interop")]
public const int WM_KEYUP = 0x0101;
[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.NamingRules", "SA1310:Field names should not contain underscore", Justification = "Interop")]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1707:Identifiers should not contain underscores", Justification = "Interop")]
public const uint MOD_NOREPEAT = 0x4000;
public delegate bool MonitorEnumProc(
@@ -117,7 +84,6 @@ namespace ColorPicker
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
internal static extern bool PostMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.NamingRules", "SA1307:Accessible fields should begin with upper-case letter", Justification = "Interop object")]
[StructLayout(LayoutKind.Sequential)]
internal struct POINT
{
@@ -125,7 +91,6 @@ namespace ColorPicker
public int y;
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.NamingRules", "SA1307:Accessible fields should begin with upper-case letter", Justification = "Interop object")]
[StructLayout(LayoutKind.Sequential)]
internal struct MSLLHOOKSTRUCT
{
@@ -145,7 +110,6 @@ namespace ColorPicker
public static explicit operator System.Windows.Point(PointInter point) => new System.Windows.Point(point.X, point.Y);
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.NamingRules", "SA1307:Accessible fields should begin with upper-case letter", Justification = "Interop object")]
[StructLayout(LayoutKind.Sequential)]
internal struct Rect
{
@@ -155,7 +119,6 @@ namespace ColorPicker
public int bottom;
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.NamingRules", "SA1307:Accessible fields should begin with upper-case letter", Justification = "Interop object")]
[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1401:Fields should be private", Justification = "false positive, used in MonitorResolutionHelper")]
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto, Pack = 4)]
internal class MonitorInfoEx

View File

@@ -7,7 +7,6 @@ using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel.Composition;
using System.Drawing.Drawing2D;
using System.Globalization;
using System.IO;
using System.Linq;
@@ -177,10 +176,10 @@ namespace ColorPicker.ViewModels
var colors = SerializationHelper.ConvertToDesiredColorFormats((IList)colorsToExport, ColorRepresentations, method);
var dialog = new SaveFileDialog
{
Title = "Save selected colors to",
Filter = "Text Files (*.txt)|*.txt|Json Files (*.json)|*.json",
};
{
Title = "Save selected colors to",
Filter = "Text Files (*.txt)|*.txt|Json Files (*.json)|*.json",
};
if (dialog.ShowDialog() == true)
{