Skip to content

Commit

Permalink
[Run.Plugin.UnitConverter] Enable analyzer and fix warnings (microsof…
Browse files Browse the repository at this point in the history
…t#17002)

* [Run.Plugin.UnitConverter] Enable analyzer and fix warnings
  • Loading branch information
CleanCodeDeveloper authored Mar 14, 2022
1 parent 66619ca commit d66fac3
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
<Platforms>x64</Platforms>
<NeutralLanguage>en-US</NeutralLanguage>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<AnalysisMode>Recommended</AnalysisMode>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public static void ShorthandFeetInchHandler(ref string[] split, CultureInfo cult
/// </summary>
public static void DegreePrefixer(ref string[] split)
{
switch (split[1].ToLower())
switch (split[1].ToLower(CultureInfo.CurrentCulture))
{
case "celsius":
split[1] = "DegreeCelsius";
Expand All @@ -129,7 +129,7 @@ public static void DegreePrefixer(ref string[] split)
break;
}

switch (split[3].ToLower())
switch (split[3].ToLower(CultureInfo.CurrentCulture))
{
case "celsius":
split[3] = "DegreeCelsius";
Expand Down Expand Up @@ -157,12 +157,12 @@ public static void DegreePrefixer(ref string[] split)
/// </summary>
public static void FeetToFt(ref string[] split)
{
if (split[1].ToLower() == "feet")
if (split[1].ToLowerInvariant() == "feet")
{
split[1] = "ft";
}

if (split[3].ToLower() == "feet")
if (split[3].ToLowerInvariant() == "feet")
{
split[3] = "ft";
}
Expand All @@ -173,12 +173,12 @@ public static void FeetToFt(ref string[] split)
/// </summary>
public static void MetreToMeter(ref string[] split)
{
if (split[1].ToLower() == "metre")
if (split[1].ToLowerInvariant() == "metre")
{
split[1] = "meter";
}

if (split[3].ToLower() == "metre")
if (split[3].ToLowerInvariant() == "metre")
{
split[3] = "meter";
}
Expand All @@ -190,7 +190,7 @@ public static void MetreToMeter(ref string[] split)
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" };
if (split[1].ToLower() == "gal" || split[1].ToLower() == "gallon")
if (split[1].ToLowerInvariant() == "gal" || split[1].ToLowerInvariant() == "gallon")
{
if (britishCultureNames.Contains(culture.Name))
{
Expand All @@ -202,7 +202,7 @@ public static void GallonHandler(ref string[] split, CultureInfo culture)
}
}

if (split[3].ToLower() == "gal" || split[3].ToLower() == "gallon")
if (split[3].ToLowerInvariant() == "gal" || split[3].ToLowerInvariant() == "gallon")
{
if (britishCultureNames.Contains(culture.Name))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading;
Expand Down Expand Up @@ -61,18 +62,18 @@ private Result GetResult(UnitConversionResult result)
return new Result
{
ContextData = result,
Title = string.Format("{0} {1}", result.ConvertedValue, result.UnitName),
Title = $"{result.ConvertedValue} {result.UnitName}",
IcoPath = _icon_path,
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 =>
{
var ret = false;
var thread = new Thread(() =>
{
try
{
Clipboard.SetText(result.ConvertedValue.ToString());
Clipboard.SetText(result.ConvertedValue.ToString(CultureInfo.CurrentCulture));
ret = true;
}
catch (ExternalException)
Expand Down Expand Up @@ -104,7 +105,7 @@ private ContextMenuResult CreateContextMenuEntry(UnitConversionResult result)
{
try
{
Clipboard.SetText(result.ConvertedValue.ToString());
Clipboard.SetText(result.ConvertedValue.ToString(CultureInfo.CurrentCulture));
ret = true;
}
catch (ExternalException)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static class UnitHandler
/// <returns>Corresponding enum or null.</returns>
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)
{
return first.Value;
Expand Down

0 comments on commit d66fac3

Please sign in to comment.