Skip to content

Analyzer to ensure correct C# nullable annotation when AllowDefault = true #317

Open
@drewnoakes

Description

@drewnoakes
#nullable enable

[Import(AllowDefault = true)]
public IBar Bar { get; private set; }

[ImportingConstructor]
public Foo([Import(AllowDefault = true)] IBar bar)
{}

Both of these imports lead to potential runtime problems if a null value is not guarded against.

When in a nullable context, use of AllowDefault = true on a non-nullable type should be flagged with a diagnostic. A codefix could also be added to change the type to be nullable.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions