Skip to content

Commit

Permalink
Change to Nullable<T>.GetValueOrDefault() instead of Nullable<T>.Value
Browse files Browse the repository at this point in the history
  • Loading branch information
prozolic committed Dec 14, 2024
1 parent 4a3101d commit 406f673
Show file tree
Hide file tree
Showing 28 changed files with 32 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ public class NullableBooleanFormatter : IYamlFormatter<bool?>

public void Serialize(ref Utf8YamlEmitter emitter, bool? value, YamlSerializationContext context)
{
if (value == null)
if (value.HasValue)
{
emitter.WriteNull();
emitter.WriteBool(value.GetValueOrDefault());
}
else
{
emitter.WriteBool(value.Value);
emitter.WriteNull();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void Serialize(ref Utf8YamlEmitter emitter, byte? value, YamlSerializatio
{
if (value.HasValue)
{
emitter.WriteInt32(value.Value);
emitter.WriteInt32(value.GetValueOrDefault());
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void Serialize(ref Utf8YamlEmitter emitter, char? value, YamlSerializatio
{
if (value.HasValue)
{
emitter.WriteInt32(value.Value);
emitter.WriteInt32(value.GetValueOrDefault());
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void Serialize(ref Utf8YamlEmitter emitter, DateTime? value, YamlSerializ
if (value.HasValue)
{
var buf = context.GetBuffer64();
if (Utf8Formatter.TryFormat(value.Value, buf, out var bytesWritten, new StandardFormat('O')))
if (Utf8Formatter.TryFormat(value.GetValueOrDefault(), buf, out var bytesWritten, new StandardFormat('O')))
{
emitter.WriteScalar(buf[..bytesWritten]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void Serialize(ref Utf8YamlEmitter emitter, float? value, YamlSerializati
{
if (value.HasValue)
{
emitter.WriteFloat(value.Value);
emitter.WriteFloat(value.GetValueOrDefault());
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void Serialize(ref Utf8YamlEmitter emitter, double? value, YamlSerializat
{
if (value.HasValue)
{
emitter.WriteDouble(value.Value);
emitter.WriteDouble(value.GetValueOrDefault());
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void Serialize(ref Utf8YamlEmitter emitter, short? value, YamlSerializati
{
if (value.HasValue)
{
emitter.WriteInt32(value.Value);
emitter.WriteInt32(value.GetValueOrDefault());
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void Serialize(ref Utf8YamlEmitter emitter, int? value, YamlSerialization
{
if (value.HasValue)
{
emitter.WriteInt32(value.Value);
emitter.WriteInt32(value.GetValueOrDefault());
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void Serialize(ref Utf8YamlEmitter emitter, long? value, YamlSerializatio
{
if (value.HasValue)
{
emitter.WriteInt64(value.Value);
emitter.WriteInt64(value.GetValueOrDefault());
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void Serialize(ref Utf8YamlEmitter emitter, T? value, YamlSerializationCo
{
if (value.HasValue)
{
underlyingFormatter.Serialize(ref emitter, value.Value, context);
underlyingFormatter.Serialize(ref emitter, value.GetValueOrDefault(), context);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void Serialize(ref Utf8YamlEmitter emitter, sbyte? value, YamlSerializati
{
if (value.HasValue)
{
emitter.WriteInt32(value.Value);
emitter.WriteInt32(value.GetValueOrDefault());
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void Serialize(ref Utf8YamlEmitter emitter, ushort? value, YamlSerializat
{
if (value.HasValue)
{
emitter.WriteUInt32(value.Value);
emitter.WriteUInt32(value.GetValueOrDefault());
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void Serialize(ref Utf8YamlEmitter emitter, uint? value, YamlSerializatio
{
if (value.HasValue)
{
emitter.WriteUInt32(value.Value);
emitter.WriteUInt32(value.GetValueOrDefault());
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void Serialize(ref Utf8YamlEmitter emitter, ulong? value, YamlSerializati
{
if (value.HasValue)
{
emitter.WriteUInt64(value.Value);
emitter.WriteUInt64(value.GetValueOrDefault());
}
else
{
Expand Down
6 changes: 3 additions & 3 deletions VYaml/Serialization/Formatters/BooleanFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ public class NullableBooleanFormatter : IYamlFormatter<bool?>

public void Serialize(ref Utf8YamlEmitter emitter, bool? value, YamlSerializationContext context)
{
if (value == null)
if (value.HasValue)
{
emitter.WriteNull();
emitter.WriteBool(value.GetValueOrDefault());
}
else
{
emitter.WriteBool(value.Value);
emitter.WriteNull();
}
}

Expand Down
2 changes: 1 addition & 1 deletion VYaml/Serialization/Formatters/ByteFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void Serialize(ref Utf8YamlEmitter emitter, byte? value, YamlSerializatio
{
if (value.HasValue)
{
emitter.WriteInt32(value.Value);
emitter.WriteInt32(value.GetValueOrDefault());
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion VYaml/Serialization/Formatters/CharFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void Serialize(ref Utf8YamlEmitter emitter, char? value, YamlSerializatio
{
if (value.HasValue)
{
emitter.WriteInt32(value.Value);
emitter.WriteInt32(value.GetValueOrDefault());
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion VYaml/Serialization/Formatters/DateTimeFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void Serialize(ref Utf8YamlEmitter emitter, DateTime? value, YamlSerializ
if (value.HasValue)
{
var buf = context.GetBuffer64();
if (Utf8Formatter.TryFormat(value.Value, buf, out var bytesWritten, new StandardFormat('O')))
if (Utf8Formatter.TryFormat(value.GetValueOrDefault(), buf, out var bytesWritten, new StandardFormat('O')))
{
emitter.WriteScalar(buf[..bytesWritten]);
}
Expand Down
2 changes: 1 addition & 1 deletion VYaml/Serialization/Formatters/Float32Formatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void Serialize(ref Utf8YamlEmitter emitter, float? value, YamlSerializati
{
if (value.HasValue)
{
emitter.WriteFloat(value.Value);
emitter.WriteFloat(value.GetValueOrDefault());
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion VYaml/Serialization/Formatters/Float64Formatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void Serialize(ref Utf8YamlEmitter emitter, double? value, YamlSerializat
{
if (value.HasValue)
{
emitter.WriteDouble(value.Value);
emitter.WriteDouble(value.GetValueOrDefault());
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion VYaml/Serialization/Formatters/Int16Formatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void Serialize(ref Utf8YamlEmitter emitter, short? value, YamlSerializati
{
if (value.HasValue)
{
emitter.WriteInt32(value.Value);
emitter.WriteInt32(value.GetValueOrDefault());
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion VYaml/Serialization/Formatters/Int32Formatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void Serialize(ref Utf8YamlEmitter emitter, int? value, YamlSerialization
{
if (value.HasValue)
{
emitter.WriteInt32(value.Value);
emitter.WriteInt32(value.GetValueOrDefault());
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion VYaml/Serialization/Formatters/Int64Formatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void Serialize(ref Utf8YamlEmitter emitter, long? value, YamlSerializatio
{
if (value.HasValue)
{
emitter.WriteInt64(value.Value);
emitter.WriteInt64(value.GetValueOrDefault());
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion VYaml/Serialization/Formatters/NullableFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void Serialize(ref Utf8YamlEmitter emitter, T? value, YamlSerializationCo
{
if (value.HasValue)
{
underlyingFormatter.Serialize(ref emitter, value.Value, context);
underlyingFormatter.Serialize(ref emitter, value.GetValueOrDefault(), context);
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion VYaml/Serialization/Formatters/SByteFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void Serialize(ref Utf8YamlEmitter emitter, sbyte? value, YamlSerializati
{
if (value.HasValue)
{
emitter.WriteInt32(value.Value);
emitter.WriteInt32(value.GetValueOrDefault());
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion VYaml/Serialization/Formatters/UInt16Formatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void Serialize(ref Utf8YamlEmitter emitter, ushort? value, YamlSerializat
{
if (value.HasValue)
{
emitter.WriteUInt32(value.Value);
emitter.WriteUInt32(value.GetValueOrDefault());
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion VYaml/Serialization/Formatters/UInt32Formatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void Serialize(ref Utf8YamlEmitter emitter, uint? value, YamlSerializatio
{
if (value.HasValue)
{
emitter.WriteUInt32(value.Value);
emitter.WriteUInt32(value.GetValueOrDefault());
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion VYaml/Serialization/Formatters/UInt64Formatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void Serialize(ref Utf8YamlEmitter emitter, ulong? value, YamlSerializati
{
if (value.HasValue)
{
emitter.WriteUInt64(value.Value);
emitter.WriteUInt64(value.GetValueOrDefault());
}
else
{
Expand Down

0 comments on commit 406f673

Please sign in to comment.