Ambiguous OpenXmlElement constructors
See original GitHub issueDescription
Greetings. Some time ago we started analyzing our code with SonarQube, and I have noticed a large number of reports in cases like these:
placeholder.InsertBeforeSelf(new Paragraph(new ParagraphProperties(new SpacingBetweenLines() { After = "0" })));
which lead to warnings like this:
S3220: Review this call, which partially matches an overload without ‘params’. The partial match is ‘Paragraph.Paragraph(IEnumerable<DocumentFormat.OpenXml.OpenXmlElement> childElements)’.
This happens because
- all (most?)
OpenXmlElement
s define two constructors:- one accepting an
IEnumerable<OpenXmlElement>
- one accepting an
OpenXmlElement[]
asparams
- one accepting an
OpenXmlElement
implementsIEnumerable<OpenXmlElement>
A call with a single OpenXmlElement
as the argument is correctly resolved with the params[] overload, so this does not cause actual problems. However, this report shows this usage is king of ambiguous which I agree with (note also OpenXmlElement.Append
and Linq.Enumerable.Append
).
Information
- .NET Target: .NET Core (irrelevant)
- DocumentFormat.OpenXml Version: 2.16.0 (and previous)
Expected
I guess adding an OpenXmlElement(OpenXmlElement)
constructor would solve this issue, but I understand this would be an immense undertaking (every single OpenXmlElement would have to include it) which is likely not worth the time for this little gain. Moreover, while I understand and agree with this specific rule, I do not know how SonarQube rules are regarded in general / whether others share this sentiment.
Please consider this as just a comment about something I noticed and not as a strong request.
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (2 by maintainers)
This could be considered. However, I’m unsure of the value of this. The C# compiler itself doesn’t warn about this and binds to the expected overload. I’d need to be convinced of the value here due to the number of custom types that this would be added to.
I’m going to close this for now. Please feel free to reopen/comment if there’s an actual blocker here.