Skip to content

Commit

Permalink
Use Nullable annotations
Browse files Browse the repository at this point in the history
Signed-off-by: Florian Hockmann <[email protected]>
  • Loading branch information
FlorianHockmann committed Nov 15, 2023
1 parent fcd7016 commit dd36f6f
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static class JanusGraphTypeSerializerRegistry
/// </summary>
public static readonly TypeSerializerRegistry Instance = Build().Create();

private static Builder Build() => new Builder();
private static Builder Build() => new();

/// <summary>
/// Builds a <see cref="TypeSerializerRegistry" /> with serializers for JanusGraph types already registered.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ protected JanusGraphTypeSerializer(GraphBinaryType type)
}

/// <inheritdoc />
public override async Task WriteAsync(object value, Stream stream, GraphBinaryWriter writer,
public override async Task WriteAsync(object? value, Stream stream, GraphBinaryWriter writer,
CancellationToken cancellationToken = default)
{
await stream.WriteIntAsync(_type.TypeId, cancellationToken).ConfigureAwait(false);
Expand All @@ -52,7 +52,7 @@ public override async Task WriteAsync(object value, Stream stream, GraphBinaryWr
}

/// <inheritdoc />
public override async Task WriteNullableValueAsync(object value, Stream stream, GraphBinaryWriter writer,
public override async Task WriteNullableValueAsync(object? value, Stream stream, GraphBinaryWriter writer,
CancellationToken cancellationToken = default)
{
if (value == null)
Expand Down Expand Up @@ -90,7 +90,7 @@ protected abstract Task WriteNonNullableValueInternalAsync(object value, Stream
GraphBinaryWriter writer, CancellationToken cancellationToken = default);

/// <inheritdoc />
public override async Task<object> ReadAsync(Stream stream, GraphBinaryReader reader,
public override async Task<object?> ReadAsync(Stream stream, GraphBinaryReader reader,
CancellationToken cancellationToken = default)
{
var customTypeInfo = await stream.ReadIntAsync(cancellationToken).ConfigureAwait(false);
Expand All @@ -104,7 +104,7 @@ public override async Task<object> ReadAsync(Stream stream, GraphBinaryReader re
}

/// <inheritdoc />
public override async Task<object> ReadNullableValueAsync(Stream stream, GraphBinaryReader reader,
public override async Task<object?> ReadNullableValueAsync(Stream stream, GraphBinaryReader reader,
CancellationToken cancellationToken = default)
{
var valueFlag = await stream.ReadByteAsync(cancellationToken).ConfigureAwait(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public override async Task<object> ReadNonNullableValueAsync(Stream stream,
var relationId = await stream.ReadLongAsync(cancellationToken).ConfigureAwait(false);

var inVertexIdMarker = await stream.ReadByteAsync(cancellationToken).ConfigureAwait(false);
object inVertexId;
object? inVertexId;
if (inVertexIdMarker == StringMarker)
{
inVertexId = await ReadStringAsync(stream, cancellationToken).ConfigureAwait(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public async Task<byte[]> SerializeMessageAsync(RequestMessage requestMessage,
}

/// <inheritdoc />
public async Task<ResponseMessage<List<object>>> DeserializeMessageAsync(byte[] message,
public async Task<ResponseMessage<List<object>>?> DeserializeMessageAsync(byte[] message,
CancellationToken cancellationToken = default)
{
return await _serializer.DeserializeMessageAsync(message, cancellationToken).ConfigureAwait(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ internal class RelationIdentifierDeserializer : IGraphSONDeserializer
{
public dynamic Objectify(JsonElement graphsonObject, GraphSONReader reader)
{
return new RelationIdentifier(graphsonObject.GetProperty("relationId").GetString());
return new RelationIdentifier(graphsonObject.GetProperty("relationId").GetString()!);
}
}
}
2 changes: 2 additions & 0 deletions src/JanusGraph.Net/JanusGraph.Net.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
<IncludeSource>True</IncludeSource>
<IncludeSymbols>True</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<LangVersion>9</LangVersion>
<Nullable>enable</Nullable>
<Version>1.0.0-rc2</Version>
<Title>JanusGraph.Net</Title>
<Authors>JanusGraph</Authors>
Expand Down
4 changes: 2 additions & 2 deletions src/JanusGraph.Net/JanusGraphClientBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ public class JanusGraphClientBuilder
private readonly GremlinServer _server;
private readonly JanusGraphSONReaderBuilder _readerBuilder = JanusGraphSONReaderBuilder.Build();
private readonly JanusGraphSONWriterBuilder _writerBuilder;
private IMessageSerializer _serializer;
private ConnectionPoolSettings _connectionPoolSettings;
private IMessageSerializer? _serializer;
private ConnectionPoolSettings? _connectionPoolSettings;

private JanusGraphClientBuilder(GremlinServer server)
{
Expand Down
2 changes: 1 addition & 1 deletion src/JanusGraph.Net/JanusGraphP.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace JanusGraph.Net
{
internal class JanusGraphP : P
{
public JanusGraphP(string operatorName, object value, P other = null) : base(operatorName, value, other)
public JanusGraphP(string operatorName, object? value, P? other = null) : base(operatorName, value, other)
{
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/JanusGraph.Net/RelationIdentifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public RelationIdentifier(string stringRepresentation)
/// <param name="typeId">The JanusGraph internal type id.</param>
/// <param name="relationId">The JanusGraph internal relation id.</param>
/// <param name="inVertexId">The id of the incoming vertex.</param>
public RelationIdentifier(object outVertexId, long typeId, long relationId, object inVertexId)
public RelationIdentifier(object outVertexId, long typeId, long relationId, object? inVertexId)
{
OutVertexId = outVertexId;
TypeId = typeId;
Expand Down Expand Up @@ -132,18 +132,18 @@ public RelationIdentifier(object outVertexId, long typeId, long relationId, obje
/// <summary>
/// Gets the id of the incoming vertex.
/// </summary>
public object InVertexId { get; }
public object? InVertexId { get; }

/// <inheritdoc />
public bool Equals(RelationIdentifier other)
public bool Equals(RelationIdentifier? other)
{
if (ReferenceEquals(null, other)) return false;
if (ReferenceEquals(this, other)) return true;
return string.Equals(StringRepresentation, other.StringRepresentation);
}

/// <inheritdoc />
public override bool Equals(object obj)
public override bool Equals(object? obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
Expand All @@ -154,7 +154,7 @@ public override bool Equals(object obj)
/// <inheritdoc />
public override int GetHashCode()
{
return StringRepresentation != null ? StringRepresentation.GetHashCode() : 0;
return StringRepresentation.GetHashCode();
}

/// <inheritdoc />
Expand Down

0 comments on commit dd36f6f

Please sign in to comment.