[fxcop] Fixes for Wox.Plugin (1of3) (#7457)

* Added CultureInfo (CA1307: Specify StringComparison for clarity / CA1304: Specify CultureInfo)

* Check arguments and throw ArgumentNullException (CA1062: Validate arguments of public methods)

* Changed url parameter from string to System.Uri and added null checks (CA1054: URI parameters should not be strings)

* Rethrow exception without specifying the exception explicitly (CA2200: Rethrow to preserve stack details)

* Changed from Collection property to methods for PluginMetadata::ActionKeywords (CA2227: Collection properties should be read only)

* Changed from Collection property to methods for Result::GetTitleHighlightData (CA2227: Collection properties should be read only)

* Made Collection property read-only and added parameter in constructor for Result::SubTitleHighlightData (CA2227: Collection properties should be read only)

* Made Collection property read only and added parameter in constructor for ResultUpdatedEventArgs::Results (CA2227: Collection properties should be read only)

* CA1507: Use nameof in place of string

* Removed initialization for ThemeManager::_disposed (CA1805: Do not initialize unnecessarily)

* Changed Query::Terms array property to ReadOnlyCollection and added private set (CA1819: Properties should not return arrays)

* CA1060: Move P/Invokes to NativeMethods class

* CA1806: Do not ignore method results

* CA2101: Specify marshaling for P/Invoke string arguments

* Removed unnecessary empty interface IFeatures (CA1040: Avoid empty interfaces)

- Removed IFeatures interface and references
- Renamed IFeatures.cs to IContextMenu.cs according to guidelines

* Added comments for CultureInfo (CA1307: Specify StringComparison for clarity / CA1304: Specify CultureInfo)

* Added localization for Wox.Plugin and localized strings in FilesFolders.cs
This commit is contained in:
Avneet Kaur
2020-10-26 15:14:33 -07:00
committed by GitHub
parent 3906896947
commit ca1e5d111a
31 changed files with 432 additions and 97 deletions

View File

@@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Windows;
using System.Windows.Media;
@@ -16,6 +17,7 @@ namespace Wox.Plugin
private ToolTipData _toolTipData;
private string _pluginDirectory;
private string _icoPath;
private IList<int> _titleHighlightData;
public string Title
{
@@ -26,7 +28,13 @@ namespace Wox.Plugin
set
{
_title = value.Replace("\n", " ");
if (value == null)
{
throw new ArgumentNullException(nameof(value));
}
// Using Ordinal since this is used internally
_title = value.Replace("\n", " ", StringComparison.Ordinal);
}
}
@@ -90,15 +98,32 @@ namespace Wox.Plugin
public int Score { get; set; }
/// <summary>
/// Gets or sets a list of indexes for the characters to be highlighted in Title
/// </summary>
public IList<int> TitleHighlightData { get; set; }
public Result(IList<int> titleHighlightData = null, IList<int> subTitleHighlightData = null)
{
_titleHighlightData = titleHighlightData;
SubTitleHighlightData = subTitleHighlightData;
}
/// <summary>
/// Gets or sets a list of indexes for the characters to be highlighted in SubTitle
/// Gets a list of indexes for the characters to be highlighted in Title
/// </summary>
public IList<int> SubTitleHighlightData { get; set; }
public IList<int> GetTitleHighlightData()
{
return _titleHighlightData;
}
/// <summary>
/// Sets a list of indexes for the characters to be highlighted in Title
/// </summary>
public void SetTitleHighlightData(IList<int> value)
{
_titleHighlightData = value;
}
/// <summary>
/// Gets a list of indexes for the characters to be highlighted in SubTitle
/// </summary>
public IList<int> SubTitleHighlightData { get; private set; }
/// <summary>
/// Gets or sets only results that originQuery match with current query will be displayed in the panel
@@ -129,10 +154,11 @@ namespace Wox.Plugin
{
var r = obj as Result;
var equality = string.Equals(r?.Title, Title) &&
string.Equals(r?.SubTitle, SubTitle) &&
string.Equals(r?.IcoPath, IcoPath) &&
TitleHighlightData == r.TitleHighlightData &&
// Using Ordinal since this is used internally
var equality = string.Equals(r?.Title, Title, StringComparison.Ordinal) &&
string.Equals(r?.SubTitle, SubTitle, StringComparison.Ordinal) &&
string.Equals(r?.IcoPath, IcoPath, StringComparison.Ordinal) &&
GetTitleHighlightData() == r.GetTitleHighlightData() &&
SubTitleHighlightData == r.SubTitleHighlightData;
return equality;
@@ -140,18 +166,16 @@ namespace Wox.Plugin
public override int GetHashCode()
{
var hashcode = (Title?.GetHashCode() ?? 0) ^
(SubTitle?.GetHashCode() ?? 0);
// Using Ordinal since this is used internally
var hashcode = (Title?.GetHashCode(StringComparison.Ordinal) ?? 0) ^
(SubTitle?.GetHashCode(StringComparison.Ordinal) ?? 0);
return hashcode;
}
public override string ToString()
{
return string.Format("{0} : {1}", Title, SubTitle);
}
public Result()
{
// Using CurrentCulture since this is user facing
return string.Format(CultureInfo.CurrentCulture, "{0} : {1}", Title, SubTitle);
}
/// <summary>