MFTV0003: Combine only values with the same tag

edit

Cause

Several values with different tags are combined into one value:

  • the operands of + and -,
  • the branches of ?:, ??, and switch expressions,
  • the elements of arrays, collection expressions, and collection initializers.
var id = useProject ? order.ProjectId : order.Id; // MFTV0003
Guid[] ids = [order.Id, order.ProjectId];         // MFTV0003
var length = meters + feet;                       // MFTV0003

The arguments of params and the elements of a collection of object are not combined, as they hold values of different kinds, such as the arguments of a log message.

How to fix

Make every operand, branch, or element produce a value with the same tag:

var id = useProject ? order.ProjectId : project.Id; // both are ProjectIds
Guid[] ids = [order.Id, other.Id];                  // both are OrderIds

When the values are right, fix the [ValueTag] of the declaration that is tagged incorrectly. When a declaration legitimately holds both kinds of values, give it both tags: [ValueTag("OrderId", "ProjectId")].