Skip to content

Commit

Permalink
Housecleaning Based on SonarLint Recommendations
Browse files Browse the repository at this point in the history
  • Loading branch information
DelnarErsike committed Jun 12, 2021
1 parent ac3de43 commit 4475ce1
Show file tree
Hide file tree
Showing 109 changed files with 2,476 additions and 2,625 deletions.
32 changes: 10 additions & 22 deletions Chummer/Backend/Attributes/Attribute.Core.cs
Expand Up @@ -677,10 +677,7 @@ public int TotalAugmentedMaximum

public string DisplayNameShort(string strLanguage)
{
if (Abbrev == "MAGAdept")
return LanguageManager.MAGAdeptString(strLanguage);

return LanguageManager.GetString("String_Attribute" + Abbrev + "Short", strLanguage);
return GetDisplayAbbrev(strLanguage);
}

public string DisplayNameLong(string strLanguage)
Expand Down Expand Up @@ -786,13 +783,10 @@ public string ToolTip
StringBuilder sbdNewModifier = new StringBuilder();
foreach (Tuple<string, decimal, string> strValues in lstUniquePair)
{
if (strValues.Item1 == "precedence0")
if (strValues.Item1 == "precedence0" && strValues.Item2 > decHighest)
{
if (strValues.Item2 > decHighest)
{
decHighest = strValues.Item2;
sbdNewModifier = new StringBuilder(strSpace + '+' + strSpace + strValues.Item3 + strSpace + '(' + strValues.Item2.ToString(GlobalOptions.CultureInfo) + ')');
}
decHighest = strValues.Item2;
sbdNewModifier = new StringBuilder(strSpace + '+' + strSpace + strValues.Item3 + strSpace + '(' + strValues.Item2.ToString(GlobalOptions.CultureInfo) + ')');
}
}
if (lstUniqueName.Contains("precedence-1"))
Expand Down Expand Up @@ -828,13 +822,10 @@ public string ToolTip
decimal decHighest = decimal.MinValue;
foreach (Tuple<string, decimal, string> strValues in lstUniquePair)
{
if (strValues.Item1 == strName)
if (strValues.Item1 == strName && strValues.Item2 > decHighest)
{
if (strValues.Item2 > decHighest)
{
decHighest = strValues.Item2;
sbdModifier.Append(strSpace + '+' + strSpace + strValues.Item3 + strSpace + '(' + strValues.Item2.ToString(GlobalOptions.CultureInfo) + ')');
}
decHighest = strValues.Item2;
sbdModifier.Append(strSpace + '+' + strSpace + strValues.Item3 + strSpace + '(' + strValues.Item2.ToString(GlobalOptions.CultureInfo) + ')');
}
}
}
Expand Down Expand Up @@ -870,13 +861,10 @@ public string ToolTip
decimal decHighest = decimal.MinValue;
foreach (Tuple<string, decimal, string> strValues in lstUniquePair)
{
if (strValues.Item1 == strName)
if (strValues.Item1 == strName && strValues.Item2 > decHighest)
{
if (strValues.Item2 > decHighest)
{
decHighest = strValues.Item2;
sbdModifier.Append(strSpace + '+' + strSpace + strValues.Item3 + strSpace + '(' + strValues.Item2.ToString(GlobalOptions.CultureInfo) + ')');
}
decHighest = strValues.Item2;
sbdModifier.Append(strSpace + '+' + strSpace + strValues.Item3 + strSpace + '(' + strValues.Item2.ToString(GlobalOptions.CultureInfo) + ')');
}
}
}
Expand Down
13 changes: 5 additions & 8 deletions Chummer/Backend/Datastructures/DependencyGraph.cs
Expand Up @@ -76,17 +76,14 @@ public HashSet<T> GetWithAllDependents(T2 objParentInstance, T objKey)
/// <param name="objReturn">Collection containing all keys that depend on <paramref name="objKey"/> in some way. It's a HashSet to prevent infinite loops in case of cycles</param>
private void CollectDependents(T2 objParentInstance, T objKey, ICollection<T> objReturn)
{
if (NodeDictionary.TryGetValue(objKey, out DependencyGraphNode<T, T2> objLoopNode))
if (NodeDictionary.TryGetValue(objKey, out DependencyGraphNode<T, T2> objLoopNode) && !objReturn.Contains(objLoopNode.MyObject))
{
if (!objReturn.Contains(objLoopNode.MyObject))
objReturn.Add(objLoopNode.MyObject);
foreach (DependencyGraphNodeWithCondition<T, T2> objNode in objLoopNode.UpStreamNodes)
{
objReturn.Add(objLoopNode.MyObject);
foreach (DependencyGraphNodeWithCondition<T, T2> objNode in objLoopNode.UpStreamNodes)
if (objNode.DependencyCondition?.Invoke(objParentInstance) != false)
{
if (objNode.DependencyCondition?.Invoke(objParentInstance) != false)
{
CollectDependents(objParentInstance, objNode.Node.MyObject, objReturn);
}
CollectDependents(objParentInstance, objNode.Node.MyObject, objReturn);
}
}
}
Expand Down
28 changes: 16 additions & 12 deletions Chummer/Backend/Datastructures/DependencyGraphNode.cs
Expand Up @@ -27,7 +27,7 @@ namespace Chummer
/// A node for use with DependencyGraph. Essentially just a directed graph node that is doubly-linked with all graph nodes to which it has edges.
/// </summary>
[DebuggerDisplay("{" + nameof(MyObject) + "}")]
public sealed class DependencyGraphNode<T, T2>
public sealed class DependencyGraphNode<T, T2> : IEquatable<DependencyGraphNode<T, T2>>
{
/// <summary>
/// Constructor used for to make a blueprint of a DependencyGraph.
Expand Down Expand Up @@ -104,18 +104,22 @@ public DependencyGraphNode(T objMyObject, DependencyGraph<T, T2> objRoot)

public override bool Equals(object obj)
{
if (obj is DependencyGraphNode<T, T2> objOtherNode)
{
if (Root != null)
return Root == objOtherNode.Root
&& (MyObject.Equals(default(T)) && objOtherNode.MyObject.Equals(default(T))
|| MyObject?.Equals(objOtherNode.MyObject) == true);
if (objOtherNode.Root != null)
return false;
}
if (ReferenceEquals(obj, this))
return true;
return obj is DependencyGraphNode<T, T2> objOtherNode && Equals(objOtherNode);
}

// ReSharper disable once BaseObjectEqualsIsObjectEquals
return base.Equals(obj);
public bool Equals(DependencyGraphNode<T, T2> other)
{
if (other == null)
return false;
if (ReferenceEquals(this, other))
return true;
if (Root != null)
return Root == other.Root
&& (MyObject.Equals(default(T)) && other.MyObject.Equals(default(T))
|| MyObject?.Equals(other.MyObject) == true);
return false;
}

public override int GetHashCode()
Expand Down
101 changes: 71 additions & 30 deletions Chummer/Backend/Datastructures/NuyenString.cs
Expand Up @@ -20,65 +20,106 @@

namespace Chummer
{
class NuyenString : IComparable
public readonly struct NuyenString : IComparable, IEquatable<NuyenString>, IComparable<NuyenString>
{
private readonly string _strBaseString;
private readonly decimal _decValue;
private readonly bool _blnUseDecimal;

public string BaseString => _strBaseString;
public decimal Value => _decValue;
public bool UseDecimal => _blnUseDecimal;
public string BaseString { get; }
public decimal Value { get; }
public bool UseDecimal { get; }

public NuyenString(string strNuyenString)
{
_strBaseString = strNuyenString.FastEscape('¥');
_blnUseDecimal = decimal.TryParse(_strBaseString, out _decValue);
BaseString = strNuyenString.FastEscape('¥');
UseDecimal = decimal.TryParse(BaseString, out decimal decValue);
Value = decValue;
}

public override string ToString()
{
return _strBaseString + '¥';
return BaseString + '¥';
}

public string ToString(string format)
{
if (_blnUseDecimal)
return _decValue.ToString(format, GlobalOptions.InvariantCultureInfo) + '¥';
return _strBaseString + '¥';
if (UseDecimal)
return Value.ToString(format, GlobalOptions.InvariantCultureInfo) + '¥';
return BaseString + '¥';
}

public string ToString(IFormatProvider formatProvider)
{
if (_blnUseDecimal)
return _decValue.ToString(formatProvider) + '¥';
return _strBaseString + '¥';
if (UseDecimal)
return Value.ToString(formatProvider) + '¥';
return BaseString + '¥';
}

public string ToString(string format, IFormatProvider formatProvider)
{
if (_blnUseDecimal)
return _decValue.ToString(format, formatProvider) + '¥';
return _strBaseString + '¥';
if (UseDecimal)
return Value.ToString(format, formatProvider) + '¥';
return BaseString + '¥';
}

public bool Equals(NuyenString other)
{
if (UseDecimal != other.UseDecimal)
return false;
return UseDecimal ? Value == other.Value : BaseString.Equals(other.BaseString, StringComparison.Ordinal);
}

public override bool Equals(object obj)
{
return obj is NuyenString other && Equals(other);
}

public override int GetHashCode()
{
return (BaseString, Value, UseDecimal).GetHashCode();
}

public int CompareTo(object obj)
{
return CompareTo((NuyenString)obj);
}

public int CompareTo(NuyenString strOther)
public int CompareTo(NuyenString other)
{
if (_blnUseDecimal)
{
if (strOther.UseDecimal)
return _decValue.CompareTo(strOther.Value);
return -1;
}
if (!UseDecimal)
return other.UseDecimal
? 1
: string.Compare(BaseString, other.BaseString, false, GlobalOptions.CultureInfo);
if (other.UseDecimal)
return Value.CompareTo(other.Value);
return -1;
}

public static bool operator ==(NuyenString left, NuyenString right)
{
return left.Equals(right);
}

if (strOther.UseDecimal)
return 1;
return string.Compare(_strBaseString, strOther.BaseString, false, GlobalOptions.CultureInfo);
public static bool operator !=(NuyenString left, NuyenString right)
{
return !(left == right);
}

public static bool operator <(NuyenString left, NuyenString right)
{
return left.CompareTo(right) < 0;
}

public static bool operator <=(NuyenString left, NuyenString right)
{
return left.CompareTo(right) <= 0;
}

public static bool operator >(NuyenString left, NuyenString right)
{
return left.CompareTo(right) > 0;
}

public static bool operator >=(NuyenString left, NuyenString right)
{
return left.CompareTo(right) >= 0;
}
}
}

0 comments on commit 4475ce1

Please sign in to comment.