{"record":{"id":"5b83495c26b05ca3","repo":"louthy/language-ext","slug":"must-be-of-type-timesq","errorCode":null,"errorMessage":"must be of type TimeSq","messagePattern":"must be of type TimeSq","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"LanguageExt.Core/Units of Measure/TimeSq.cs","lineNumber":38,"sourceCode":"\n    public bool Equals(TimeSq other) =>\n        Value.Equals(other.Value);\n\n    public bool Equals(TimeSq other, double epsilon) =>\n        Math.Abs(other.Value - Value) < epsilon;\n\n    public override bool Equals(object? obj) =>\n        obj is TimeSq sq && Equals(sq);\n\n    public override int GetHashCode() =>\n        Value.GetHashCode();\n\n    public int CompareTo(object? obj) =>\n        obj switch\n        {\n            null         => 1,\n            TimeSq other => CompareTo(other),\n            _            => throw new ArgumentException($\"must be of type {nameof(TimeSq)}\")\n        };\n\n    public int CompareTo(TimeSq other) =>\n        Value.CompareTo(other.Value);\n\n    public TimeSq Add(TimeSq rhs) =>\n        new (Value + rhs.Value);\n\n    public TimeSq Subtract(TimeSq rhs) =>\n        new (Value - rhs.Value);\n\n    public TimeSq Multiply(double rhs) =>\n        new (Value * rhs);\n\n    public TimeSq Divide(double rhs) =>\n        new (Value / rhs);\n\n    public static TimeSq operator *(TimeSq lhs, double rhs) =>","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/louthy/language-ext/blob/2f0e3628242889774d4141960a35671a0280051f/LanguageExt.Core/Units of Measure/TimeSq.cs#L20-L56","documentation":"TimeSq's explicit CompareTo(object?) throws ArgumentException('must be of type TimeSq') when given a non-null object that isn't a TimeSq. This is the conventional IComparable non-generic guard: null -> 1, matching type -> typed comparison, otherwise throw. It fires only when comparison is dispatched through an object/IComparable-typed path.","triggerScenarios":"Calling CompareTo((object)x) or using non-generic sorting (ArrayList, Array.Sort(object[])) with a non-TimeSq element — e.g. a Time, int, or other unit type — inside the collection.","commonSituations":"Heterogeneous legacy collections mixing unit types; refactors that renamed/replaced element types; interop with non-generic BCL sorting APIs.","solutions":["Verify element types before non-generic sorting","Use generic collections/sorts (List<TimeSq>.Sort) to get compile-time safety","Guard with `obj is TimeSq` before invoking CompareTo(object)","Catch ArgumentException at boundaries dealing with untyped data"],"exampleFix":"// before\nvar al = new ArrayList { new TimeSq(1), new Time(2) };\nal.Sort(); // ArgumentException: must be of type TimeSq\n// after\nvar list = new List<TimeSq> { new TimeSq(1), new TimeSq(2) };\nlist.Sort();","handlingStrategy":"type-guard","validationCode":"if (obj is not TimeSq) throw new ArgumentException(\"comparison requires TimeSq\");","typeGuard":"static bool IsTimeSq(object? o) => o is TimeSq;","tryCatchPattern":"try { r = ((IComparable)timeSq).CompareTo(obj); }\ncatch (ArgumentException ex) { /* log type mismatch, skip element */ }","preventionTips":["Prefer generic collections for TimeSq values","Use CompareTo(TimeSq) directly when types are known","Validate element types before Array.Sort(object[])","Filter mixed collections with OfType<TimeSq>() before sorting"],"tags":["csharp","languageext","icomparable","argument"],"backgroundTag":"type-mismatch","analyzedSha":"2f0e3628242889774d4141960a35671a0280051f","analyzedAt":"2026-09-15T03:31:55.716Z","contentChangedAt":"2026-09-15T03:31:55.716Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}