C#

C#

Made by DeepSource

Consider reusing record objects that rely on const parameters CS-P1022

Performance
Major

Records are structures that are extensively used in serialization and deserialization. However, if your instance of record takes in parameters that are class' const fields, consider reusing the same record instance instead of instantiating a new one.

Bad Practice

public void M()
{
    var issue = new Issue(code, offset); // Both `code` and `offset` are `const` fields
    Publish(issue);
}

Recommended

private readonly Issue issue = new(code, offset);

public void M()
{
    Publish(issue);
}