Skip to content

Commit 84a9fd5

Browse files
nan01abJimmy
andauthored
Fix: return NotNullIfNotNull (#3704)
Co-authored-by: Jimmy <[email protected]>
1 parent 5e7d90f commit 84a9fd5

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

src/Neo/Persistence/DataCache.cs

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -311,12 +311,21 @@ public bool Contains(StorageKey key)
311311
protected abstract StorageItem GetInternal(StorageKey key);
312312

313313
/// <summary>
314-
/// Reads a specified entry from the cache, and mark it as <see cref="TrackState.Changed"/>. If the entry is not in the cache, it will be automatically loaded from the underlying storage.
314+
/// Reads a specified entry from the cache, and mark it as <see cref="TrackState.Changed"/>.
315+
/// If the entry is not in the cache, it will be automatically loaded from the underlying storage.
315316
/// </summary>
316317
/// <param name="key">The key of the entry.</param>
317-
/// <param name="factory">A delegate used to create the entry if it doesn't exist. If the entry already exists, the factory will not be used.</param>
318-
/// <returns>The cached data. Or <see langword="null"/> if it doesn't exist and the <paramref name="factory"/> is not provided.</returns>
319-
public StorageItem? GetAndChange(StorageKey key, [NotNullIfNotNull(nameof(factory))] Func<StorageItem>? factory = null)
318+
/// <param name="factory">
319+
/// A delegate used to create the entry if it doesn't exist.
320+
/// If the entry already exists, the factory will not be used.
321+
/// </param>
322+
/// <returns>
323+
/// The cached data, or <see langword="null"/> if it doesn't exist and the <paramref name="factory"/> is not provided.
324+
/// </returns>
325+
#if NET5_0_OR_GREATER
326+
[return: NotNullIfNotNull(nameof(factory))]
327+
#endif
328+
public StorageItem? GetAndChange(StorageKey key, Func<StorageItem>? factory = null)
320329
{
321330
lock (_dictionary)
322331
{
@@ -362,10 +371,15 @@ public bool Contains(StorageKey key)
362371
}
363372

364373
/// <summary>
365-
/// Reads a specified entry from the cache. If the entry is not in the cache, it will be automatically loaded from the underlying storage. If the entry doesn't exist, the factory will be used to create a new one.
374+
/// Reads a specified entry from the cache.
375+
/// If the entry is not in the cache, it will be automatically loaded from the underlying storage.
376+
/// If the entry doesn't exist, the factory will be used to create a new one.
366377
/// </summary>
367378
/// <param name="key">The key of the entry.</param>
368-
/// <param name="factory">A delegate used to create the entry if it doesn't exist. If the entry already exists, the factory will not be used.</param>
379+
/// <param name="factory">
380+
/// A delegate used to create the entry if it doesn't exist.
381+
/// If the entry already exists, the factory will not be used.
382+
/// </param>
369383
/// <returns>The cached data.</returns>
370384
public StorageItem GetOrAdd(StorageKey key, Func<StorageItem> factory)
371385
{

0 commit comments

Comments
 (0)