-
Notifications
You must be signed in to change notification settings - Fork 482
Closed
Labels
Area-Microsoft.CodeAnalysis.NetAnalyzersFalse_PositiveA diagnostic is reported for non-problematic caseA diagnostic is reported for non-problematic casehelp wantedThe issue is up-for-grabs, and can be claimed by commentingThe issue is up-for-grabs, and can be claimed by commenting
Description
Analyzer CA1861 Avoid constant arrays as arguments
Diagnostic ID: CA1861
Describe the improvement
We have excluded static readonly fields/properties instantiation, we also need to exclude static ReadOnlyCollection<T> field/property initializtions
Example:
public class Test
{
private static ReadOnlyCollection<string>? s_errorPayloadNames;
private void M(string eventName, string msg)
{
var eventCallbackArgs = new EventWrittenEventArgs(this, 0)
{
EventName = eventName,
Message = msg,
Payload = new ReadOnlyCollection<object?>(new object[] { msg }),
// Should not warn here
PayloadNames = s_errorPayloadNames ??= new ReadOnlyCollection<string>(new string[] { "message" })
};
}
}Additional context
Related to dotnet/runtime#86229 (comment)
Metadata
Metadata
Assignees
Labels
Area-Microsoft.CodeAnalysis.NetAnalyzersFalse_PositiveA diagnostic is reported for non-problematic caseA diagnostic is reported for non-problematic casehelp wantedThe issue is up-for-grabs, and can be claimed by commentingThe issue is up-for-grabs, and can be claimed by commenting