Exception thrown from an unexpected member (CA1065)
هذا المحتوى غير متوفر بلغتك بعد.
Key dotnet.exception.unexpected-throw · Severity warning · Category exception
Microsoft analyzer CA1065. Flags exceptions thrown from members callers never guard - Equals, GetHashCode, ToString, property getters, static constructors, finalizers, Dispose.
Incorrect
Section titled “Incorrect”public override bool Equals(object? obj){ if (obj is not Money m) throw new ArgumentException("Not money"); return Amount == m.Amount;}Correct
Section titled “Correct”public override bool Equals(object? obj) => obj is Money m && Amount == m.Amount;