Skip to content

Commit a275b6c

Browse files
authored
IRehydrationContext.TryGetValue - Adding NotNullWhen attribute for out value (#9495)
* Update IGrainLifecycle.cs / IRehydrationContext.TryGetValue - Adding NotNullWhen attribute for out value * IGrainLifecycle.cs - Fixing missing import for NotNullWhen * MigrationContext.TryGetValue - Updating to use NotNullWhen attribute for out value * MigrationContext.TryGetValue - value asserted as not null when returning possibly true
1 parent e21a2fd commit a275b6c

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/Orleans.Core.Abstractions/Lifecycle/IGrainLifecycle.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System;
33
using System.Buffers;
44
using System.Collections.Generic;
5+
using System.Diagnostics.CodeAnalysis;
56
using System.Threading;
67

78
namespace Orleans.Runtime
@@ -106,6 +107,6 @@ public interface IRehydrationContext
106107
/// <param name="key">The key.</param>
107108
/// <param name="value">The value, if present.</param>
108109
/// <returns><see langword="true"/> if the key exists in the context, otherwise <see langword="false"/>.</returns>
109-
bool TryGetValue<T>(string key, out T? value);
110+
bool TryGetValue<T>(string key, [NotNullWhen(true)] out T? value);
110111
}
111112
}

src/Orleans.Core/Lifecycle/MigrationContext.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Buffers;
44
using System.Collections;
55
using System.Collections.Generic;
6+
using System.Diagnostics.CodeAnalysis;
67
using System.Runtime.InteropServices;
78
using Orleans.Serialization.Buffers;
89
using Orleans.Serialization.Codecs;
@@ -97,7 +98,7 @@ public bool TryGetBytes(string key, out ReadOnlySequence<byte> value)
9798
return false;
9899
}
99100

100-
public bool TryGetValue<T>(string key, out T? value)
101+
public bool TryGetValue<T>(string key, [NotNullWhen(true)] out T? value)
101102
{
102103
if (_indices.TryGetValue(key, out var record) && _sessionPool.CodecProvider.TryGetCodec<T>() is { } codec)
103104
{
@@ -106,7 +107,7 @@ public bool TryGetValue<T>(string key, out T? value)
106107
var reader = Reader.Create(source, session);
107108
var field = reader.ReadFieldHeader();
108109
value = codec.ReadValue(ref reader, field);
109-
return true;
110+
return value is not null;
110111
}
111112

112113
value = default;

0 commit comments

Comments
 (0)