MFTV0001: Do not compare values with different tags
editCause
Two values with different tags are compared, for instance an order id with a project id. Such a comparison is almost always a bug: it is false for every pair of real values.
The rule covers ==, !=, <, <=, >, >=, tuple equality (element by element, including tuple variables), Equals, CompareTo, EqualityComparer<T>.Equals, Comparer<T>.Compare, string.Equals(a, b, comparison), and a.Equals(b, comparison):
_ = order.Id == project.Id; // MFTV0001
_ = order.Id.Equals(project.Id); // MFTV0001
_ = orders.Where(item => item.Id == project.Id); // MFTV0001The message names both values and their tags:
property 'Order.Id' is [ValueTag("OrderId")] and is compared with property 'Project.Id', which is [ValueTag("ProjectId")]How to fix
Compare the value with a value that has the same tag:
_ = order.ProjectId == project.Id;
_ = order.ProjectId.Equals(project.Id);
_ = orders.Where(item => item.ProjectId == project.Id);When the values are right and a declaration is tagged incorrectly, fix the [ValueTag] of that declaration. When a declaration legitimately holds both kinds of values, give it both tags: [ValueTag("OrderId", "ProjectId")]. See Accept several tags.