Skip to content

NUnit2007 could flag typeof() as a constant first parameter #880

@stevenaw

Description

@stevenaw

Consider the following code. 0 is a compile-time constant and typeof(TestAnalyzer) is a runtime constant, but passing a runtime constant like typeof() as the actual is still likely an indicator of misuse. The analyzers don't currently identify cases like this but it might be helpful to extend them to catch it.

[Test]
public void Test1()
{
    var result = new TestAnalyzer();

    Assert.That(typeof(TestAnalyzer), Is.EqualTo(result.GetType()));
    Assert.That(0, Is.EqualTo(result.RowVersion));
}

public class TestAnalyzer
{
    public Guid Id { get; set; } = Guid.Empty;
    public int RowVersion { get; set; } = 0;
}

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions