Skip to content

Commit e6002e4

Browse files
authored
Enable nullable on OpenXmlElement and OpenXmlCompositeElement (#849)
1 parent 132980b commit e6002e4

File tree

8 files changed

+365
-223
lines changed

8 files changed

+365
-223
lines changed

src/DocumentFormat.OpenXml/Framework/Metadata/ElementMetadata.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ public Builder(Builder builder)
199199
_builder = builder;
200200
}
201201

202-
public Builder<TElement> AddAttribute<TSimpleType>(byte nsId, string localName, Expression<Func<TElement, TSimpleType>> expression, Action<AttributeMetadata.Builder<TSimpleType>>? action = null)
202+
public Builder<TElement> AddAttribute<TSimpleType>(byte nsId, string localName, Expression<Func<TElement, TSimpleType?>> expression, Action<AttributeMetadata.Builder<TSimpleType>>? action = null)
203203
where TSimpleType : OpenXmlSimpleType, new()
204204
{
205205
if (expression.Body is MemberExpression member)

src/DocumentFormat.OpenXml/Framework/Schema/CompiledParticle.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public CompiledParticle(ParticleConstraint particle)
2222

2323
public ParticleConstraint Particle { get; }
2424

25-
public ParticlePath? Find(object obj)
25+
public ParticlePath? Find(object? obj)
2626
=> Find(obj?.GetType());
2727

2828
public ParticlePath? Find(Type? type)

src/DocumentFormat.OpenXml/Framework/Schema/ParticleCollection.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ public bool Contains(OpenXmlElement item)
157157
public struct Enumerator : IEnumerator<OpenXmlElement>
158158
{
159159
private readonly Type _type;
160-
private OpenXmlElement _child;
160+
private OpenXmlElement? _child;
161161

162162
internal Enumerator(OpenXmlElement element, Type type)
163163
{
@@ -281,7 +281,7 @@ private void Advance()
281281
{
282282
if (Current is null)
283283
{
284-
Current = _collection._element.FirstChild;
284+
Current = _collection._element.FirstChild!;
285285

286286
if (Current is null)
287287
{
@@ -290,7 +290,7 @@ private void Advance()
290290
}
291291
else
292292
{
293-
Current = Current.Next;
293+
Current = Current.Next!;
294294

295295
if (IsComplete)
296296
{

src/DocumentFormat.OpenXml/OpenXmlChildElements.cs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ public override IEnumerator<OpenXmlElement> GetEnumerator()
2222
{
2323
if (_container.HasChildren && _container.FirstChild is not null)
2424
{
25-
for ( OpenXmlElement element = _container.FirstChild;
26-
element is not null;
27-
element = element.NextSibling() )
25+
for (var element = _container.FirstChild; element is not null; element = element.NextSibling())
2826
{
2927
yield return element;
3028
}
@@ -39,9 +37,7 @@ public override OpenXmlElement GetItem(int index)
3937
{
4038
if (_container.HasChildren)
4139
{
42-
for (OpenXmlElement element = _container.FirstChild;
43-
element is not null;
44-
element = element.NextSibling())
40+
for (var element = _container.FirstChild; element is not null; element = element.NextSibling())
4541
{
4642
if (index == 0)
4743
{
@@ -63,9 +59,7 @@ public override int Count
6359
int num = 0;
6460
if (_container.HasChildren)
6561
{
66-
for (OpenXmlElement element = _container.FirstChild;
67-
element is not null;
68-
element = element.NextSibling())
62+
for (var element = _container.FirstChild; element is not null; element = element.NextSibling())
6963
{
7064
num++;
7165
}

0 commit comments

Comments
 (0)