[Feature] CodeBuity&Refactor #49, [Feature] Code review tool #10

This commit is contained in:
Markus Hofknecht 2020-03-24 14:39:43 +01:00
parent a2b1e7537e
commit 0a9921fb8b
14 changed files with 43 additions and 34 deletions

View file

@ -251,7 +251,7 @@ namespace SystemTrayMenu.Controls
// Description = AssemblyDescription string
// Title = AssemblyTitle string
// </remarks>
private NameValueCollection AssemblyAttribs(Assembly a)
private static NameValueCollection AssemblyAttribs(Assembly a)
{
string TypeName;
string Name;
@ -379,18 +379,17 @@ namespace SystemTrayMenu.Controls
// <summary>
// reads an HKLM Windows Registry key value
// </summary>
private string RegistryHklmValue(string KeyName, string SubKeyRef)
private static string RegistryHklmValue(string KeyName, string SubKeyRef)
{
RegistryKey rk;
string strSysInfoPath = string.Empty;
try
{
rk = Registry.LocalMachine.OpenSubKey(KeyName);
return (string)rk.GetValue(SubKeyRef, "");
}
catch (Exception)
{
return "";
RegistryKey rk = Registry.LocalMachine.OpenSubKey(KeyName);
strSysInfoPath = (string)rk.GetValue(SubKeyRef, string.Empty);
}
catch (Exception) { }
return strSysInfoPath;
}
// <summary>
@ -398,9 +397,7 @@ namespace SystemTrayMenu.Controls
// </summary>
private void ShowSysInfo()
{
string strSysInfoPath = "";
strSysInfoPath = RegistryHklmValue(@"SOFTWARE\Microsoft\Shared Tools Location", "MSINFO");
string strSysInfoPath = RegistryHklmValue(@"SOFTWARE\Microsoft\Shared Tools Location", "MSINFO");
if (string.IsNullOrEmpty(strSysInfoPath))
{
strSysInfoPath = RegistryHklmValue(@"SOFTWARE\Microsoft\Shared Tools\MSINFO", "PATH");
@ -434,7 +431,7 @@ namespace SystemTrayMenu.Controls
// <summary>
// populate a listview with the specified key and value strings
// </summary>
private void Populate(ListView lvw, string Key, string Value)
private static void Populate(ListView lvw, string Key, string Value)
{
if (!string.IsNullOrEmpty(Value))
{

View file

@ -227,7 +227,7 @@ namespace SystemTrayMenu.Controls
/// https://www.codeproject.com/Tips/744914/
/// Sorted-list-of-available-cultures-in-NET
/// </summary>
public IEnumerable<CultureInfo> GetCultureList(
private static IEnumerable<CultureInfo> GetCultureList(
CultureTypes cultureType = CultureTypes.SpecificCultures)
{
List<CultureInfo> cultureList = CultureInfo.GetCultures(cultureType).ToList();

View file

@ -86,6 +86,7 @@ namespace SystemTrayMenu
{
notifyIcon.Icon = null;
notifyIcon.Dispose();
load.Dispose();
}
public void LoadingStart()

View file

@ -6,7 +6,8 @@ namespace SystemTrayMenu.Controls
{
public partial class AskHotKeyForm : Form
{
public string NewHotKey;
public string NewHotKey => newHotKey;
private string newHotKey = string.Empty;
public AskHotKeyForm()
{
@ -102,13 +103,13 @@ namespace SystemTrayMenu.Controls
case Keys.F22:
case Keys.F23:
case Keys.F24:
NewHotKey = keys.ToString();
newHotKey = keys.ToString();
DialogResult = DialogResult.OK;
Close();
break;
case Keys.Back:
case Keys.Delete:
NewHotKey = string.Empty;
newHotKey = string.Empty;
DialogResult = DialogResult.OK;
Close();
break;

View file

@ -174,8 +174,7 @@ namespace SystemTrayMenu
Location = new Point(x, y);
}
public void AdjustLocationAndSize(int heightMax, int widthPredecessors,
Menu menuPredecessor)
public void AdjustLocationAndSize(int heightMax, Menu menuPredecessor)
{
DataGridViewElementStates states = DataGridViewElementStates.None;
if (!autoResizeRowsDone)

View file

@ -413,7 +413,9 @@ namespace SystemTrayMenu.Controls
if (!isDisposed)
{
icon?.Dispose();
Icon?.Dispose();
waitMenuOpen.Dispose();
Reading.Dispose();
}
isDisposed = true;
}

View file

@ -40,6 +40,7 @@ namespace SystemTrayMenu.Handler
public void Dispose()
{
hook.Dispose();
timerKeySearch.Dispose();
}
internal void RegisterHotKey()

View file

@ -4,7 +4,7 @@ using System.Runtime.InteropServices;
namespace SystemTrayMenu.Helper
{
public class WindowToTop
public static class WindowToTop
{
[DllImport("user32.dll")]
private static extern bool IsIconic(IntPtr hWnd);

View file

@ -39,6 +39,7 @@ namespace SystemTrayMenu
timerFadeIn.Dispose();
timerFadeOut.Dispose();
timerFadeHalf.Dispose();
form.Dispose();
}
}

View file

@ -10,9 +10,11 @@ namespace SystemTrayMenu.Helper
public FileIni(string path)
{
values = File.ReadLines(path)
.Where(line => (!string.IsNullOrWhiteSpace(line) && !line.StartsWith("#")))
.Where(line => !string.IsNullOrWhiteSpace(line) &&
!line.StartsWith("#", System.StringComparison.InvariantCulture))
.Select(line => line.Split(new char[] { '=' }, 2, 0))
.ToDictionary(parts => parts[0].Trim(), parts => parts.Length > 1 ? parts[1].Trim() : null);
.ToDictionary(parts => parts[0].Trim(), parts =>
parts.Length > 1 ? parts[1].Trim() : null);
}
public string Value(string name, string value = null)
{

View file

@ -2,7 +2,7 @@
namespace SystemTrayMenu.Helper
{
public class FileUrl
public static class FileUrl
{
private static string browserPath = string.Empty;
public static string GetDefaultBrowserPath()

View file

@ -17,7 +17,7 @@ namespace SystemTrayMenu.Helper
/// <example>
/// <code>IconReader.GetFileIcon("c:\\general.xls");</code>
/// </example>
public class IconReader
public static class IconReader
{
private static readonly ConcurrentDictionary<string, Icon> dictIconCache = new ConcurrentDictionary<string, Icon>();
@ -144,10 +144,10 @@ namespace SystemTrayMenu.Helper
// Cleanup
if (!linkOverlay)
{
User32.DestroyIcon(hIcon);
NativeMethods.DestroyIco(hIcon);
}
User32.DestroyIcon(shfi.hIcon);
NativeMethods.DestroyIco(shfi.hIcon);
}
return icon;
@ -207,7 +207,7 @@ namespace SystemTrayMenu.Helper
}
// Cleanup
User32.DestroyIcon(shfi.hIcon);
NativeMethods.DestroyIco(shfi.hIcon);
}
return icon;
}
@ -231,7 +231,7 @@ namespace SystemTrayMenu.Helper
// This code has been left largely untouched from that in the CRC example. The main changes have been moving
// the icon reading code over to the IconReader type.
public class Shell32
public static class Shell32
{
public const int MAX_PATH = 256;
@ -336,7 +336,7 @@ namespace SystemTrayMenu.Helper
/// <summary>
/// Wraps necessary functions imported from User32.dll. Code courtesy of MSDN Cold Rooster Consulting example.
/// </summary>
public class User32
public static class NativeMethods
{
/// <summary>
/// Provides access to function required to delete handle. This method is used internally
@ -345,8 +345,10 @@ namespace SystemTrayMenu.Helper
/// <param name="hIcon">Pointer to icon handle.</param>
/// <returns>N/A</returns>
[DllImport("User32.dll")]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Interoperability",
"CA1401:P/Invokes should not be visible", Justification = "<Pending>")]
public static extern int DestroyIcon(IntPtr hIcon);
private static extern int DestroyIcon(IntPtr hIcon);
public static void DestroyIco(IntPtr hIcon)
{
_ = DestroyIcon(hIcon);
}
}
}

View file

@ -1,4 +1,5 @@
using System.Reflection;
using System.Resources;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
@ -21,6 +22,9 @@ using System.Runtime.InteropServices;
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("116c8741-a9b0-4560-8e82-7cf412894340")]
//https://stackoverflow.com/questions/4068360/c-sharp-warning-mark-assemblies-with-neutralresourceslanguageattribute
[assembly: NeutralResourcesLanguage("en")]
// Version information for an assembly consists of the following four values:
//
// Major Version

View file

@ -276,8 +276,7 @@ namespace SystemTrayMenu
widthPredecessors -= newWith;
}
menu.AdjustLocationAndSize(heightMax,
widthPredecessors, menuPredecessor);
menu.AdjustLocationAndSize(heightMax, menuPredecessor);
widthPredecessors += menu.Width - menu.Padding.Left;
menuPredecessor = menu;
}