Skip to content

Commit

Permalink
upgrade to .net 7 and fix test #1
Browse files Browse the repository at this point in the history
  • Loading branch information
Nness committed May 15, 2023
1 parent 9179ea2 commit 6f6fef8
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<LangVersion>8.0</LangVersion>
<TargetFramework>netcoreapp3.1</TargetFramework>
<LangVersion>latest</LangVersion>
<TargetFramework>net7.0</TargetFramework>
<Nullable>enable</Nullable>
<RootNamespace>Nness.Text.Json.Validation</RootNamespace>
</PropertyGroup>
Expand Down
4 changes: 2 additions & 2 deletions src/Optional.Json/Optional.Json.csproj
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<LangVersion>8.0</LangVersion>
<TargetFramework>netcoreapp3.1</TargetFramework>
<LangVersion>latest</LangVersion>
<TargetFramework>net7.0</TargetFramework>
<Nullable>enable</Nullable>
<RootNamespace>Nness.Text.Json</RootNamespace>
</PropertyGroup>
Expand Down
6 changes: 3 additions & 3 deletions src/Optional.Json/OptionalCollectionConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ private class OptionalCollectionConverterInner<TValue> : JsonConverter<OptionalC
public OptionalCollectionConverterInner(JsonSerializerOptions options)
{
_valueConverter = (JsonConverter<ICollection<TValue>>)options.GetConverter(typeof(ICollection<TValue>));
_valueType = typeof(TValue);
_valueType = typeof(ICollection<TValue>);
}

public override OptionalCollection<TValue> Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
Expand All @@ -64,10 +64,10 @@ public override OptionalCollection<TValue> Read(ref Utf8JsonReader reader, Type
);
}

ICollection<TValue> value = _valueConverter == null
ICollection<TValue>? value = _valueConverter == null
? JsonSerializer.Deserialize<TValue[]>(ref reader, options)
: _valueConverter.Read(ref reader, _valueType, options);
return new OptionalCollection<TValue>(value);
return new OptionalCollection<TValue>(value ?? Array.Empty<TValue>());
}

public override void Write(Utf8JsonWriter writer, OptionalCollection<TValue> value, JsonSerializerOptions options)
Expand Down
4 changes: 2 additions & 2 deletions src/Optional/Optional.csproj
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<LangVersion>8.0</LangVersion>
<TargetFramework>netcoreapp3.1</TargetFramework>
<LangVersion>latest</LangVersion>
<TargetFramework>net7.0</TargetFramework>
<Nullable>enable</Nullable>
<RootNamespace>Nness.Text.Json</RootNamespace>
</PropertyGroup>
Expand Down
15 changes: 3 additions & 12 deletions src/Optional/OptionalCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,13 @@ namespace Nness.Text.Json
[Serializable]
public readonly struct OptionalCollection<T> : IOptional<ICollection<T>?>, IEnumerable<T>
{
[AllowNull]
private readonly ICollection<T>? _value;

public OptionalState State { get; }

[MaybeNull]
public ICollection<T>? Value {
get {
if (State == OptionalState.HasValue && _value != null) {
return _value;
}
return null;
}
}
public ICollection<T>? Value => State == OptionalState.HasValue && _value != null ? _value : null;

public OptionalCollection(ICollection<T> value)
public OptionalCollection(ICollection<T>? value)
{
_value = value;
State = value == null ? OptionalState.Null : OptionalState.HasValue;
Expand All @@ -41,7 +32,7 @@ public OptionalCollection(OptionalState state)

public bool IsSet() => State != OptionalState.Undefined;

public bool HasValue([NotNullWhen(true), MaybeNullWhen(false)] out ICollection<T>? value)
public bool HasValue([NotNullWhen(true)] out ICollection<T>? value)
{
value = _value;
return value != null && State == OptionalState.HasValue;
Expand Down
4 changes: 2 additions & 2 deletions tests/Optional.Json.Tests/Optional.Json.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<LangVersion>8.0</LangVersion>
<LangVersion>latest</LangVersion>
<TargetFramework>net7.0</TargetFramework>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<RootNamespace>Nness.Text.Json.Tests</RootNamespace>
Expand Down
4 changes: 2 additions & 2 deletions tests/Optional.Tests/Optional.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<LangVersion>8.0</LangVersion>
<LangVersion>latest</LangVersion>
<TargetFramework>net7.0</TargetFramework>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<RootNamespace>Nness.Text.Json.Tests</RootNamespace>
Expand Down

0 comments on commit 6f6fef8

Please sign in to comment.