From ea33397c89c8ca41cfaab6653dc1821ff4945509 Mon Sep 17 00:00:00 2001 From: Pieter-Jan Briers Date: Sat, 23 Jan 2021 20:09:02 +0100 Subject: [PATCH] Mark ReagentUnit instance methods are readonly. --- Content.Shared/Chemistry/ReagentUnit.cs | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/Content.Shared/Chemistry/ReagentUnit.cs b/Content.Shared/Chemistry/ReagentUnit.cs index 67a900ec5f..f19553cd6b 100644 --- a/Content.Shared/Chemistry/ReagentUnit.cs +++ b/Content.Shared/Chemistry/ReagentUnit.cs @@ -19,7 +19,7 @@ namespace Content.Shared.Chemistry public static ReagentUnit Epsilon { get; } = new(1); public static ReagentUnit Zero { get; } = new(0); - private double ShiftDown() + private readonly double ShiftDown() { return _value / Math.Pow(10, Shift); } @@ -164,17 +164,17 @@ namespace Content.Shared.Chemistry return a._value > b._value; } - public float Float() + public readonly float Float() { return (float) ShiftDown(); } - public double Double() + public readonly double Double() { return ShiftDown(); } - public int Int() + public readonly int Int() { return (int) ShiftDown(); } @@ -204,14 +204,15 @@ namespace Content.Shared.Chemistry return reagent < min ? min : reagent > max ? max : reagent; } - public override bool Equals(object obj) + public override readonly bool Equals(object obj) { return obj is ReagentUnit unit && _value == unit._value; } - public override int GetHashCode() + public override readonly int GetHashCode() { + // ReSharper disable once NonReadonlyMemberInGetHashCode return HashCode.Combine(_value); } @@ -220,19 +221,19 @@ namespace Content.Shared.Chemistry _value = FromFloat(FloatFromString(value)); } - public override string ToString() => $"{ShiftDown().ToString(CultureInfo.InvariantCulture)}"; + public override readonly string ToString() => $"{ShiftDown().ToString(CultureInfo.InvariantCulture)}"; - public string Serialize() + public readonly string Serialize() { return ToString(); } - public bool Equals(ReagentUnit other) + public readonly bool Equals(ReagentUnit other) { return _value == other._value; } - public int CompareTo(ReagentUnit other) + public readonly int CompareTo(ReagentUnit other) { if(other._value > _value) {