WiseTechGlobal / WTG.Analyzers

Analyzers from WiseTech Global to enforce our styles, behaviours, and prevent common mistakes.
Other
16 stars 3 forks source link

WTG3104 bad code-fix #217

Open yaakov-h opened 11 months ago

yaakov-h commented 11 months ago
var expected = new object[] { viewModel }.Concat(viewModel.Items);

This triggers WTG3014: Don't use Concat when prepending a single element to an enumerable.

The code-fix changes it to:

var expected = viewModel.Items.Prepend(viewModel);

However, viewModel and viewModel.Items do not share a common type, so this then causes CS0411: The type arguments for method 'Enumerable.Prepend(IEnumerable, TSource)' cannot be inferred from the usage. Try specifying the type arguments explicitly.

We should probably change this to .Prepend<object> to preserve the explicit typing.