Skip to content

Config generator doesn't match nullability semantics of built-in Bind #90987

Closed
@stephentoub

Description

@stephentoub

The built-in Bind method annotates the object as nullable:

public static void Bind(this IConfiguration configuration, object? instance)

and then explicitly nops if it's null:

if (instance != null)
{
    ...
}

In contrast, the code generated by the generator annotates it as non-nullable and throws an exception if it's null, changing the semantics when using the source generator.

if (obj is null)
{
    throw new ArgumentNullException(nameof(obj));
}

(It also names the parameter obj instead of instance.)

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions