[Run.Plugin.UnitConverter] Enable analyzer and fix warnings (#17002)

* [Run.Plugin.UnitConverter] Enable analyzer and fix warnings
This commit is contained in:
CleanCodeDeveloper
2022-03-14 18:08:23 +01:00
committed by GitHub
parent 66619ca059
commit d66fac3c3c
4 changed files with 16 additions and 13 deletions

View File

@@ -13,6 +13,8 @@
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath> <AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
<Platforms>x64</Platforms> <Platforms>x64</Platforms>
<NeutralLanguage>en-US</NeutralLanguage> <NeutralLanguage>en-US</NeutralLanguage>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<AnalysisMode>Recommended</AnalysisMode>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">

View File

@@ -107,7 +107,7 @@ namespace Community.PowerToys.Run.Plugin.UnitConverter
/// </summary> /// </summary>
public static void DegreePrefixer(ref string[] split) public static void DegreePrefixer(ref string[] split)
{ {
switch (split[1].ToLower()) switch (split[1].ToLower(CultureInfo.CurrentCulture))
{ {
case "celsius": case "celsius":
split[1] = "DegreeCelsius"; split[1] = "DegreeCelsius";
@@ -129,7 +129,7 @@ namespace Community.PowerToys.Run.Plugin.UnitConverter
break; break;
} }
switch (split[3].ToLower()) switch (split[3].ToLower(CultureInfo.CurrentCulture))
{ {
case "celsius": case "celsius":
split[3] = "DegreeCelsius"; split[3] = "DegreeCelsius";
@@ -157,12 +157,12 @@ namespace Community.PowerToys.Run.Plugin.UnitConverter
/// </summary> /// </summary>
public static void FeetToFt(ref string[] split) public static void FeetToFt(ref string[] split)
{ {
if (split[1].ToLower() == "feet") if (split[1].ToLowerInvariant() == "feet")
{ {
split[1] = "ft"; split[1] = "ft";
} }
if (split[3].ToLower() == "feet") if (split[3].ToLowerInvariant() == "feet")
{ {
split[3] = "ft"; split[3] = "ft";
} }
@@ -173,12 +173,12 @@ namespace Community.PowerToys.Run.Plugin.UnitConverter
/// </summary> /// </summary>
public static void MetreToMeter(ref string[] split) public static void MetreToMeter(ref string[] split)
{ {
if (split[1].ToLower() == "metre") if (split[1].ToLowerInvariant() == "metre")
{ {
split[1] = "meter"; split[1] = "meter";
} }
if (split[3].ToLower() == "metre") if (split[3].ToLowerInvariant() == "metre")
{ {
split[3] = "meter"; split[3] = "meter";
} }
@@ -190,7 +190,7 @@ namespace Community.PowerToys.Run.Plugin.UnitConverter
public static void GallonHandler(ref string[] split, CultureInfo culture) public static void GallonHandler(ref string[] split, CultureInfo culture)
{ {
HashSet<string> britishCultureNames = new HashSet<string>() { "en-AI", "en-VG", "en-GB", "en-KY", "en-MS", "en-AG", "en-DM", "en-GD", "en-KN", "en-LC", "en-VC", "en-IE", "en-GY", "en-AE" }; HashSet<string> britishCultureNames = new HashSet<string>() { "en-AI", "en-VG", "en-GB", "en-KY", "en-MS", "en-AG", "en-DM", "en-GD", "en-KN", "en-LC", "en-VC", "en-IE", "en-GY", "en-AE" };
if (split[1].ToLower() == "gal" || split[1].ToLower() == "gallon") if (split[1].ToLowerInvariant() == "gal" || split[1].ToLowerInvariant() == "gallon")
{ {
if (britishCultureNames.Contains(culture.Name)) if (britishCultureNames.Contains(culture.Name))
{ {
@@ -202,7 +202,7 @@ namespace Community.PowerToys.Run.Plugin.UnitConverter
} }
} }
if (split[3].ToLower() == "gal" || split[3].ToLower() == "gallon") if (split[3].ToLowerInvariant() == "gal" || split[3].ToLowerInvariant() == "gallon")
{ {
if (britishCultureNames.Contains(culture.Name)) if (britishCultureNames.Contains(culture.Name))
{ {

View File

@@ -4,6 +4,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization;
using System.Linq; using System.Linq;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Threading; using System.Threading;
@@ -61,10 +62,10 @@ namespace Community.PowerToys.Run.Plugin.UnitConverter
return new Result return new Result
{ {
ContextData = result, ContextData = result,
Title = string.Format("{0} {1}", result.ConvertedValue, result.UnitName), Title = $"{result.ConvertedValue} {result.UnitName}",
IcoPath = _icon_path, IcoPath = _icon_path,
Score = 300, Score = 300,
SubTitle = string.Format(Properties.Resources.copy_to_clipboard, result.QuantityType), SubTitle = string.Format(CultureInfo.CurrentCulture, Properties.Resources.copy_to_clipboard, result.QuantityType),
Action = c => Action = c =>
{ {
var ret = false; var ret = false;
@@ -72,7 +73,7 @@ namespace Community.PowerToys.Run.Plugin.UnitConverter
{ {
try try
{ {
Clipboard.SetText(result.ConvertedValue.ToString()); Clipboard.SetText(result.ConvertedValue.ToString(CultureInfo.CurrentCulture));
ret = true; ret = true;
} }
catch (ExternalException) catch (ExternalException)
@@ -104,7 +105,7 @@ namespace Community.PowerToys.Run.Plugin.UnitConverter
{ {
try try
{ {
Clipboard.SetText(result.ConvertedValue.ToString()); Clipboard.SetText(result.ConvertedValue.ToString(CultureInfo.CurrentCulture));
ret = true; ret = true;
} }
catch (ExternalException) catch (ExternalException)

View File

@@ -37,7 +37,7 @@ namespace Community.PowerToys.Run.Plugin.UnitConverter
/// <returns>Corresponding enum or null.</returns> /// <returns>Corresponding enum or null.</returns>
private static Enum GetUnitEnum(string unit, QuantityInfo unitInfo) private static Enum GetUnitEnum(string unit, QuantityInfo unitInfo)
{ {
UnitInfo first = Array.Find(unitInfo.UnitInfos, info => info.Name.ToLower() == unit.ToLower()); UnitInfo first = Array.Find(unitInfo.UnitInfos, info => info.Name.ToLowerInvariant() == unit.ToLowerInvariant());
if (first != null) if (first != null)
{ {
return first.Value; return first.Value;