dotnet / dotnet/Open-XML-SDK

Strongly typed classes define all properties as nullable

Open
#960 7 comments 0 reactions 1 assignee Claimed by @tomjebo View on GitHub
by design enhancement has-repro
Dominant language
C#
Stars
4.6k
Forks
605
PR merge metrics
No merged PRs in 30d

Description

**Description**

Using the generated `Sheet` class as an example, it seems that (pretty much all) the strongly typed classes define all their properties as nullable. For example:

```csharp
public StringValue? Name
{
get => GetAttribute();
set => SetAttribute(value);
}
```

This is done even where the schema defines the corresponding attributes as required, meaning they will (or should) not be null. For example:

```xml






```

Flagging all properties as nullable is at least not helpful. It would be better to have `Name`, `SheetId`, and `Id` not nullable and only `State` nullable, meaning the schema would be reflected in the nullability of the properties. Otherwise, you'll have to add countless `!` to tell the compiler that everything is fine.

**Information**

- .NET Target: all
- DocumentFormat.OpenXml Version: latest

**Observed**

Nullability is not in line with schema.

**Expected**

Nullability should be in line with schema.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.