Skip to content

Commit 38ece1e

Browse files
authored
Merge pull request #3 from dhirensham/address-stricter-null-rules-in-vs17.12
Address stricter rules around nullability in VS 17.12
2 parents 5653642 + f20f0d7 commit 38ece1e

File tree

7 files changed

+19
-12
lines changed

7 files changed

+19
-12
lines changed

src/CouchDB.Driver/Converters/AttachmentsParsedConverter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace CouchDB.Driver.Converters
88
{
99
internal class AttachmentsParsedConverter : JsonConverter<Dictionary<string, CouchAttachment>>
1010
{
11-
public override void WriteJson(JsonWriter writer, Dictionary<string, CouchAttachment> value,
11+
public override void WriteJson(JsonWriter writer, Dictionary<string, CouchAttachment>? value,
1212
JsonSerializer serializer)
1313
{
1414
serializer.Serialize(writer, value
@@ -20,7 +20,7 @@ public override void WriteJson(JsonWriter writer, Dictionary<string, CouchAttach
2020
public override bool CanRead => false;
2121

2222
public override Dictionary<string, CouchAttachment> ReadJson(JsonReader reader, Type objectType,
23-
Dictionary<string, CouchAttachment> existingValue, bool hasExistingValue,
23+
Dictionary<string, CouchAttachment>? existingValue, bool hasExistingValue,
2424
JsonSerializer serializer)
2525
{
2626
throw new NotImplementedException();

src/CouchDB.Driver/CouchDB.Driver.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
<ItemGroup>
3232
<PackageReference Include="Flurl.Http" Version="3.2.4" />
3333
<PackageReference Include="Humanizer.Core" Version="2.14.1" />
34+
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
3435
</ItemGroup>
3536

3637
<ItemGroup>

src/CouchDB.Driver/CouchDatabase.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -591,11 +591,14 @@ public async IAsyncEnumerable<ChangesFeedResponseResult<TSource>> GetContinuousC
591591
var substring = line.Substring(startIndex, lineLength);
592592
ChangesFeedResponseResult<TSource>? result =
593593
JsonConvert.DeserializeObject<ChangesFeedResponseResult<TSource>>(substring);
594-
if (string.IsNullOrWhiteSpace(_discriminator) ||
595-
result.Document.SplitDiscriminator == _discriminator)
594+
if (result != null)
596595
{
597-
lastSequence = result.Seq;
598-
yield return result;
596+
if (string.IsNullOrWhiteSpace(_discriminator) ||
597+
result.Document.SplitDiscriminator == _discriminator)
598+
{
599+
lastSequence = result.Seq;
600+
yield return result;
601+
}
599602
}
600603
}
601604
}

src/CouchDB.Driver/Extensions/MemberInfoExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public static string GetCouchPropertyName(this MemberInfo memberInfo, PropertyCa
1717
? jsonPropertyAttributes[0] as JsonPropertyAttribute
1818
: null;
1919

20-
return jsonProperty != null
20+
return jsonProperty?.PropertyName != null
2121
? jsonProperty.PropertyName
2222
: propertyCaseType.Convert(memberInfo.Name);
2323
}

src/CouchDB.Driver/Extensions/TypeExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public static string GetName(this Type t, CouchOptions options)
1818
? jsonObjectAttributes[0] as JsonObjectAttribute
1919
: null;
2020

21-
if (jsonObject != null)
21+
if (jsonObject?.Id != null)
2222
{
2323
return jsonObject.Id;
2424
}

src/CouchDB.Driver/Helpers/CouchContractResolver.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ internal CouchContractResolver(PropertyCaseType propertyCaseType, string? databa
1717
_databaseSplitDiscriminator = databaseSplitDiscriminator;
1818
}
1919

20-
protected override JsonProperty? CreateProperty(MemberInfo member, MemberSerialization memberSerialization)
20+
protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization)
2121
{
2222
Check.NotNull(member, nameof(member));
2323

src/CouchDB.Driver/Helpers/MicrosecondEpochConverter.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,15 @@ internal class MicrosecondEpochConverter : DateTimeConverterBase
99
{
1010
private static readonly DateTime Epoch = new(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
1111

12-
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
12+
public override void WriteJson(JsonWriter writer, object? value, JsonSerializer serializer)
1313
{
14-
writer.WriteRawValue(((DateTime)value - Epoch).TotalMilliseconds + "000");
14+
if (value != null)
15+
{
16+
writer.WriteRawValue(((DateTime)value - Epoch).TotalMilliseconds + "000");
17+
}
1518
}
1619

17-
public override object? ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
20+
public override object? ReadJson(JsonReader reader, Type objectType, object? existingValue, JsonSerializer serializer)
1821
{
1922
Check.NotNull(reader, nameof(reader));
2023

0 commit comments

Comments
 (0)