Skip to content

Option to ignore field/property initializers and auto-implemented properties #328

Closed
@rickardp

Description

@rickardp

Consider a class, e.g.

class MyClass
{
    public int MyValue { get; set; }
}

The property would be excluded because it's getter/setter has the CompilerGeneratedAttribute set. Now consider this class:

class MyClass
{
    public int MyValue { get; set; } = 42;
}

The line is included in coverage. I think this is because in the IL code, the initializers are actually part of the constructor. While this may be a sensible default even if explicitly opting out of compiler generated code, there should be an option to exclude initializers from coverage analysis.

The use case for this is when you have large model objects that contain code that you actually want coverage on, but also contains lots of pure data members.

Suggestion is to include an option, e.g. ExcludeInitializers, that ignores all initializers from coverage.

I saw e.g. issue #316, but I would argue something more specific than an arbitrary "IgnoreTrivial" is more suitable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions