You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I don't know if any of the above information is relevant or correct, I don't understand it so I haven't touched it. If I'm supposed to enter anything in there, please make it clear in the template.
So, the analyzer "CA1859: Use concrete types when possible for improved performance" gives me a false suggestion. If I follow it, my code breaks immediately.
Steps To Reproduce
Code:
privatestaticobject?Multiply(object?leftValue,object?rightValue){if(ConvertToDoubleOrString(leftValue,outdoubleleft,outstring?leftStr)){if(ConvertToDoubleOrString(rightValue,outdoubleright,outstring?rightStr)){returnleft*right;}returnRepeat(rightStr,(int)left);}elseif(ConvertToDoubleOrString(rightValue,outdoubleright,outstring?_)){returnRepeat(leftStr,(int)right);}thrownewFormatException("The * operator does not accept two string operands.");staticstring?Repeat(string?str,intcount){if(str==null)returnnull;varsb=newStringBuilder(str.Length*count);while(count-->0){sb.Append(str);}returnsb.ToString();}}// Defined in a base class:protectedstaticboolConvertToDoubleOrString(object?value,outdoubledoubleValue,outstring?stringValue){doubleValue=0;stringValue=null;if(value==null){returnfalse;}if(valueisdoubled){doubleValue=d;returntrue;}stringValue=Convert.ToString(value,CultureInfo.InvariantCulture)!;returndouble.TryParse(stringValue,CultureInfo.InvariantCulture,outdoubleValue);}
Expected behavior
No suggestion, object? is already the best return type.
Actual behavior
Analyzer suggests to change return type of Multiply to string? for better performance.
Additional context
.NET 9
Visual Studio 17.12.4
The text was updated successfully, but these errors were encountered:
Analyzer
Diagnostic ID: CA2013:
Do not use ReferenceEquals with value types
Analyzer source
SDK: Built-in CA analyzers in .NET 5 SDK or later
Version: SDK 5.0.100
OR
NuGet Package: Microsoft.CodeAnalysis.NetAnalyzers
Version: 8.0.0
Describe the bug
I don't know if any of the above information is relevant or correct, I don't understand it so I haven't touched it. If I'm supposed to enter anything in there, please make it clear in the template.
So, the analyzer "CA1859: Use concrete types when possible for improved performance" gives me a false suggestion. If I follow it, my code breaks immediately.
Steps To Reproduce
Code:
Expected behavior
No suggestion,
object?
is already the best return type.Actual behavior
Analyzer suggests to change return type of
Multiply
tostring?
for better performance.Additional context
The text was updated successfully, but these errors were encountered: