diff --git a/src/libraries/Microsoft.Extensions.Caching.Abstractions/ref/Microsoft.Extensions.Caching.Abstractions.cs b/src/libraries/Microsoft.Extensions.Caching.Abstractions/ref/Microsoft.Extensions.Caching.Abstractions.cs index 055c97089a7ca..3476a93dcf6a4 100644 --- a/src/libraries/Microsoft.Extensions.Caching.Abstractions/ref/Microsoft.Extensions.Caching.Abstractions.cs +++ b/src/libraries/Microsoft.Extensions.Caching.Abstractions/ref/Microsoft.Extensions.Caching.Abstractions.cs @@ -21,8 +21,8 @@ public DistributedCacheEntryOptions() { } } public static partial class DistributedCacheExtensions { - public static string GetString(this Microsoft.Extensions.Caching.Distributed.IDistributedCache cache, string key) { throw null; } - public static System.Threading.Tasks.Task GetStringAsync(this Microsoft.Extensions.Caching.Distributed.IDistributedCache cache, string key, System.Threading.CancellationToken token = default(System.Threading.CancellationToken)) { throw null; } + public static string? GetString(this Microsoft.Extensions.Caching.Distributed.IDistributedCache cache, string key) { throw null; } + public static System.Threading.Tasks.Task GetStringAsync(this Microsoft.Extensions.Caching.Distributed.IDistributedCache cache, string key, System.Threading.CancellationToken token = default(System.Threading.CancellationToken)) { throw null; } public static void Set(this Microsoft.Extensions.Caching.Distributed.IDistributedCache cache, string key, byte[] value) { } public static System.Threading.Tasks.Task SetAsync(this Microsoft.Extensions.Caching.Distributed.IDistributedCache cache, string key, byte[] value, System.Threading.CancellationToken token = default(System.Threading.CancellationToken)) { throw null; } public static void SetString(this Microsoft.Extensions.Caching.Distributed.IDistributedCache cache, string key, string value) { } @@ -32,8 +32,8 @@ public static void SetString(this Microsoft.Extensions.Caching.Distributed.IDist } public partial interface IDistributedCache { - byte[] Get(string key); - System.Threading.Tasks.Task GetAsync(string key, System.Threading.CancellationToken token = default(System.Threading.CancellationToken)); + byte[]? Get(string key); + System.Threading.Tasks.Task GetAsync(string key, System.Threading.CancellationToken token = default(System.Threading.CancellationToken)); void Refresh(string key); System.Threading.Tasks.Task RefreshAsync(string key, System.Threading.CancellationToken token = default(System.Threading.CancellationToken)); void Remove(string key); @@ -48,7 +48,7 @@ public static partial class CacheEntryExtensions { public static Microsoft.Extensions.Caching.Memory.ICacheEntry AddExpirationToken(this Microsoft.Extensions.Caching.Memory.ICacheEntry entry, Microsoft.Extensions.Primitives.IChangeToken expirationToken) { throw null; } public static Microsoft.Extensions.Caching.Memory.ICacheEntry RegisterPostEvictionCallback(this Microsoft.Extensions.Caching.Memory.ICacheEntry entry, Microsoft.Extensions.Caching.Memory.PostEvictionDelegate callback) { throw null; } - public static Microsoft.Extensions.Caching.Memory.ICacheEntry RegisterPostEvictionCallback(this Microsoft.Extensions.Caching.Memory.ICacheEntry entry, Microsoft.Extensions.Caching.Memory.PostEvictionDelegate callback, object state) { throw null; } + public static Microsoft.Extensions.Caching.Memory.ICacheEntry RegisterPostEvictionCallback(this Microsoft.Extensions.Caching.Memory.ICacheEntry entry, Microsoft.Extensions.Caching.Memory.PostEvictionDelegate callback, object? state) { throw null; } public static Microsoft.Extensions.Caching.Memory.ICacheEntry SetAbsoluteExpiration(this Microsoft.Extensions.Caching.Memory.ICacheEntry entry, System.DateTimeOffset absolute) { throw null; } public static Microsoft.Extensions.Caching.Memory.ICacheEntry SetAbsoluteExpiration(this Microsoft.Extensions.Caching.Memory.ICacheEntry entry, System.TimeSpan relative) { throw null; } public static Microsoft.Extensions.Caching.Memory.ICacheEntry SetOptions(this Microsoft.Extensions.Caching.Memory.ICacheEntry entry, Microsoft.Extensions.Caching.Memory.MemoryCacheEntryOptions options) { throw null; } @@ -59,16 +59,16 @@ public static partial class CacheEntryExtensions } public static partial class CacheExtensions { - public static object Get(this Microsoft.Extensions.Caching.Memory.IMemoryCache cache, object key) { throw null; } - public static System.Threading.Tasks.Task GetOrCreateAsync(this Microsoft.Extensions.Caching.Memory.IMemoryCache cache, object key, System.Func> factory) { throw null; } - public static TItem GetOrCreate(this Microsoft.Extensions.Caching.Memory.IMemoryCache cache, object key, System.Func factory) { throw null; } - public static TItem Get(this Microsoft.Extensions.Caching.Memory.IMemoryCache cache, object key) { throw null; } - public static TItem Set(this Microsoft.Extensions.Caching.Memory.IMemoryCache cache, object key, TItem value) { throw null; } - public static TItem Set(this Microsoft.Extensions.Caching.Memory.IMemoryCache cache, object key, TItem value, Microsoft.Extensions.Caching.Memory.MemoryCacheEntryOptions options) { throw null; } - public static TItem Set(this Microsoft.Extensions.Caching.Memory.IMemoryCache cache, object key, TItem value, Microsoft.Extensions.Primitives.IChangeToken expirationToken) { throw null; } - public static TItem Set(this Microsoft.Extensions.Caching.Memory.IMemoryCache cache, object key, TItem value, System.DateTimeOffset absoluteExpiration) { throw null; } - public static TItem Set(this Microsoft.Extensions.Caching.Memory.IMemoryCache cache, object key, TItem value, System.TimeSpan absoluteExpirationRelativeToNow) { throw null; } - public static bool TryGetValue(this Microsoft.Extensions.Caching.Memory.IMemoryCache cache, object key, out TItem value) { throw null; } + public static object? Get(this Microsoft.Extensions.Caching.Memory.IMemoryCache cache, object key) { throw null; } + public static System.Threading.Tasks.Task GetOrCreateAsync(this Microsoft.Extensions.Caching.Memory.IMemoryCache cache, object key, System.Func> factory) { throw null; } + public static TItem? GetOrCreate(this Microsoft.Extensions.Caching.Memory.IMemoryCache cache, object key, System.Func factory) { throw null; } + public static TItem? Get(this Microsoft.Extensions.Caching.Memory.IMemoryCache cache, object key) { throw null; } + public static TItem? Set(this Microsoft.Extensions.Caching.Memory.IMemoryCache cache, object key, TItem? value) { throw null; } + public static TItem? Set(this Microsoft.Extensions.Caching.Memory.IMemoryCache cache, object key, TItem? value, Microsoft.Extensions.Caching.Memory.MemoryCacheEntryOptions? options) { throw null; } + public static TItem? Set(this Microsoft.Extensions.Caching.Memory.IMemoryCache cache, object key, TItem? value, Microsoft.Extensions.Primitives.IChangeToken expirationToken) { throw null; } + public static TItem? Set(this Microsoft.Extensions.Caching.Memory.IMemoryCache cache, object key, TItem? value, System.DateTimeOffset absoluteExpiration) { throw null; } + public static TItem? Set(this Microsoft.Extensions.Caching.Memory.IMemoryCache cache, object key, TItem? value, System.TimeSpan absoluteExpirationRelativeToNow) { throw null; } + public static bool TryGetValue(this Microsoft.Extensions.Caching.Memory.IMemoryCache cache, object key, out TItem? value) { throw null; } } public enum CacheItemPriority { @@ -96,19 +96,19 @@ public partial interface ICacheEntry : System.IDisposable Microsoft.Extensions.Caching.Memory.CacheItemPriority Priority { get; set; } long? Size { get; set; } System.TimeSpan? SlidingExpiration { get; set; } - object Value { get; set; } + object? Value { get; set; } } public partial interface IMemoryCache : System.IDisposable { Microsoft.Extensions.Caching.Memory.ICacheEntry CreateEntry(object key); void Remove(object key); - bool TryGetValue(object key, out object value); + bool TryGetValue(object key, out object? value); } public static partial class MemoryCacheEntryExtensions { public static Microsoft.Extensions.Caching.Memory.MemoryCacheEntryOptions AddExpirationToken(this Microsoft.Extensions.Caching.Memory.MemoryCacheEntryOptions options, Microsoft.Extensions.Primitives.IChangeToken expirationToken) { throw null; } public static Microsoft.Extensions.Caching.Memory.MemoryCacheEntryOptions RegisterPostEvictionCallback(this Microsoft.Extensions.Caching.Memory.MemoryCacheEntryOptions options, Microsoft.Extensions.Caching.Memory.PostEvictionDelegate callback) { throw null; } - public static Microsoft.Extensions.Caching.Memory.MemoryCacheEntryOptions RegisterPostEvictionCallback(this Microsoft.Extensions.Caching.Memory.MemoryCacheEntryOptions options, Microsoft.Extensions.Caching.Memory.PostEvictionDelegate callback, object state) { throw null; } + public static Microsoft.Extensions.Caching.Memory.MemoryCacheEntryOptions RegisterPostEvictionCallback(this Microsoft.Extensions.Caching.Memory.MemoryCacheEntryOptions options, Microsoft.Extensions.Caching.Memory.PostEvictionDelegate callback, object? state) { throw null; } public static Microsoft.Extensions.Caching.Memory.MemoryCacheEntryOptions SetAbsoluteExpiration(this Microsoft.Extensions.Caching.Memory.MemoryCacheEntryOptions options, System.DateTimeOffset absolute) { throw null; } public static Microsoft.Extensions.Caching.Memory.MemoryCacheEntryOptions SetAbsoluteExpiration(this Microsoft.Extensions.Caching.Memory.MemoryCacheEntryOptions options, System.TimeSpan relative) { throw null; } public static Microsoft.Extensions.Caching.Memory.MemoryCacheEntryOptions SetPriority(this Microsoft.Extensions.Caching.Memory.MemoryCacheEntryOptions options, Microsoft.Extensions.Caching.Memory.CacheItemPriority priority) { throw null; } @@ -129,10 +129,10 @@ public MemoryCacheEntryOptions() { } public partial class PostEvictionCallbackRegistration { public PostEvictionCallbackRegistration() { } - public Microsoft.Extensions.Caching.Memory.PostEvictionDelegate EvictionCallback { get { throw null; } set { } } - public object State { get { throw null; } set { } } + public Microsoft.Extensions.Caching.Memory.PostEvictionDelegate? EvictionCallback { get { throw null; } set { } } + public object? State { get { throw null; } set { } } } - public delegate void PostEvictionDelegate(object key, object value, Microsoft.Extensions.Caching.Memory.EvictionReason reason, object state); + public delegate void PostEvictionDelegate(object key, object? value, Microsoft.Extensions.Caching.Memory.EvictionReason reason, object? state); } namespace Microsoft.Extensions.Internal { diff --git a/src/libraries/Microsoft.Extensions.Caching.Abstractions/ref/Microsoft.Extensions.Caching.Abstractions.csproj b/src/libraries/Microsoft.Extensions.Caching.Abstractions/ref/Microsoft.Extensions.Caching.Abstractions.csproj index 8895a198c5c3e..9d967d4f3adb2 100644 --- a/src/libraries/Microsoft.Extensions.Caching.Abstractions/ref/Microsoft.Extensions.Caching.Abstractions.csproj +++ b/src/libraries/Microsoft.Extensions.Caching.Abstractions/ref/Microsoft.Extensions.Caching.Abstractions.csproj @@ -1,6 +1,7 @@ $(NetCoreAppCurrent);$(NetCoreAppMinimum);netstandard2.0;$(NetFrameworkMinimum) + enable diff --git a/src/libraries/Microsoft.Extensions.Caching.Abstractions/src/CacheEntryExtensions.cs b/src/libraries/Microsoft.Extensions.Caching.Abstractions/src/CacheEntryExtensions.cs index 1adf580d2b714..ab8305044ea9e 100644 --- a/src/libraries/Microsoft.Extensions.Caching.Abstractions/src/CacheEntryExtensions.cs +++ b/src/libraries/Microsoft.Extensions.Caching.Abstractions/src/CacheEntryExtensions.cs @@ -112,7 +112,7 @@ public static ICacheEntry RegisterPostEvictionCallback( public static ICacheEntry RegisterPostEvictionCallback( this ICacheEntry entry, PostEvictionDelegate callback, - object state) + object? state) { if (callback == null) { @@ -186,7 +186,7 @@ public static ICacheEntry SetOptions(this ICacheEntry entry, MemoryCacheEntryOpt foreach (PostEvictionCallbackRegistration postEvictionCallback in options.PostEvictionCallbacks) { - entry.RegisterPostEvictionCallback(postEvictionCallback.EvictionCallback, postEvictionCallback.State); + entry.RegisterPostEvictionCallback(postEvictionCallback.EvictionCallback!, postEvictionCallback.State); } return entry; diff --git a/src/libraries/Microsoft.Extensions.Caching.Abstractions/src/DistributedCacheExtensions.cs b/src/libraries/Microsoft.Extensions.Caching.Abstractions/src/DistributedCacheExtensions.cs index 621321ce975d3..562d8e224c075 100644 --- a/src/libraries/Microsoft.Extensions.Caching.Abstractions/src/DistributedCacheExtensions.cs +++ b/src/libraries/Microsoft.Extensions.Caching.Abstractions/src/DistributedCacheExtensions.cs @@ -133,9 +133,9 @@ public static void SetString(this IDistributedCache cache, string key, string va /// The cache in which to store the data. /// The key to get the stored data for. /// The string value from the stored cache key. - public static string GetString(this IDistributedCache cache, string key) + public static string? GetString(this IDistributedCache cache, string key) { - byte[] data = cache.Get(key); + byte[]? data = cache.Get(key); if (data == null) { return null; @@ -150,9 +150,9 @@ public static string GetString(this IDistributedCache cache, string key) /// The key to get the stored data for. /// Optional. A to cancel the operation. /// A task that gets the string value from the stored cache key. - public static async Task GetStringAsync(this IDistributedCache cache, string key, CancellationToken token = default(CancellationToken)) + public static async Task GetStringAsync(this IDistributedCache cache, string key, CancellationToken token = default(CancellationToken)) { - byte[] data = await cache.GetAsync(key, token).ConfigureAwait(false); + byte[]? data = await cache.GetAsync(key, token).ConfigureAwait(false); if (data == null) { return null; diff --git a/src/libraries/Microsoft.Extensions.Caching.Abstractions/src/ICacheEntry.cs b/src/libraries/Microsoft.Extensions.Caching.Abstractions/src/ICacheEntry.cs index be1cf5ccc0d35..02ff52ee5942a 100644 --- a/src/libraries/Microsoft.Extensions.Caching.Abstractions/src/ICacheEntry.cs +++ b/src/libraries/Microsoft.Extensions.Caching.Abstractions/src/ICacheEntry.cs @@ -20,7 +20,7 @@ public interface ICacheEntry : IDisposable /// /// Gets or set the value of the cache entry. /// - object Value { get; set; } + object? Value { get; set; } /// /// Gets or sets an absolute expiration date for the cache entry. diff --git a/src/libraries/Microsoft.Extensions.Caching.Abstractions/src/IDistributedCache.cs b/src/libraries/Microsoft.Extensions.Caching.Abstractions/src/IDistributedCache.cs index d3b32ec54c03e..7be960251823b 100644 --- a/src/libraries/Microsoft.Extensions.Caching.Abstractions/src/IDistributedCache.cs +++ b/src/libraries/Microsoft.Extensions.Caching.Abstractions/src/IDistributedCache.cs @@ -16,7 +16,7 @@ public interface IDistributedCache /// /// A string identifying the requested value. /// The located value or null. - byte[] Get(string key); + byte[]? Get(string key); /// /// Gets a value with the given key. @@ -24,7 +24,7 @@ public interface IDistributedCache /// A string identifying the requested value. /// Optional. The used to propagate notifications that the operation should be canceled. /// The that represents the asynchronous operation, containing the located value or null. - Task GetAsync(string key, CancellationToken token = default(CancellationToken)); + Task GetAsync(string key, CancellationToken token = default(CancellationToken)); /// /// Sets a value with the given key. diff --git a/src/libraries/Microsoft.Extensions.Caching.Abstractions/src/IMemoryCache.cs b/src/libraries/Microsoft.Extensions.Caching.Abstractions/src/IMemoryCache.cs index 10379bc4cc7a6..88576eba04c74 100644 --- a/src/libraries/Microsoft.Extensions.Caching.Abstractions/src/IMemoryCache.cs +++ b/src/libraries/Microsoft.Extensions.Caching.Abstractions/src/IMemoryCache.cs @@ -16,7 +16,7 @@ public interface IMemoryCache : IDisposable /// An object identifying the requested entry. /// The located value or null. /// True if the key was found. - bool TryGetValue(object key, out object value); + bool TryGetValue(object key, out object? value); /// /// Create or overwrite an entry in the cache. diff --git a/src/libraries/Microsoft.Extensions.Caching.Abstractions/src/MemoryCacheEntryExtensions.cs b/src/libraries/Microsoft.Extensions.Caching.Abstractions/src/MemoryCacheEntryExtensions.cs index a66d4a519cc4f..ba75e79961012 100644 --- a/src/libraries/Microsoft.Extensions.Caching.Abstractions/src/MemoryCacheEntryExtensions.cs +++ b/src/libraries/Microsoft.Extensions.Caching.Abstractions/src/MemoryCacheEntryExtensions.cs @@ -131,7 +131,7 @@ public static MemoryCacheEntryOptions RegisterPostEvictionCallback( public static MemoryCacheEntryOptions RegisterPostEvictionCallback( this MemoryCacheEntryOptions options, PostEvictionDelegate callback, - object state) + object? state) { if (callback == null) { diff --git a/src/libraries/Microsoft.Extensions.Caching.Abstractions/src/MemoryCacheExtensions.cs b/src/libraries/Microsoft.Extensions.Caching.Abstractions/src/MemoryCacheExtensions.cs index 6e3d9422d6310..74d757d76cc24 100644 --- a/src/libraries/Microsoft.Extensions.Caching.Abstractions/src/MemoryCacheExtensions.cs +++ b/src/libraries/Microsoft.Extensions.Caching.Abstractions/src/MemoryCacheExtensions.cs @@ -9,20 +9,20 @@ namespace Microsoft.Extensions.Caching.Memory { public static class CacheExtensions { - public static object Get(this IMemoryCache cache, object key) + public static object? Get(this IMemoryCache cache, object key) { - cache.TryGetValue(key, out object value); + cache.TryGetValue(key, out object? value); return value; } - public static TItem Get(this IMemoryCache cache, object key) + public static TItem? Get(this IMemoryCache cache, object key) { - return (TItem)(cache.Get(key) ?? default(TItem)); + return (TItem?)(cache.Get(key) ?? default(TItem)); } - public static bool TryGetValue(this IMemoryCache cache, object key, out TItem value) + public static bool TryGetValue(this IMemoryCache cache, object key, out TItem? value) { - if (cache.TryGetValue(key, out object result)) + if (cache.TryGetValue(key, out object? result)) { if (result == null) { @@ -41,7 +41,7 @@ public static bool TryGetValue(this IMemoryCache cache, object key, out T return false; } - public static TItem Set(this IMemoryCache cache, object key, TItem value) + public static TItem? Set(this IMemoryCache cache, object key, TItem? value) { using ICacheEntry entry = cache.CreateEntry(key); entry.Value = value; @@ -49,7 +49,7 @@ public static TItem Set(this IMemoryCache cache, object key, TItem value) return value; } - public static TItem Set(this IMemoryCache cache, object key, TItem value, DateTimeOffset absoluteExpiration) + public static TItem? Set(this IMemoryCache cache, object key, TItem? value, DateTimeOffset absoluteExpiration) { using ICacheEntry entry = cache.CreateEntry(key); entry.AbsoluteExpiration = absoluteExpiration; @@ -58,7 +58,7 @@ public static TItem Set(this IMemoryCache cache, object key, TItem value, return value; } - public static TItem Set(this IMemoryCache cache, object key, TItem value, TimeSpan absoluteExpirationRelativeToNow) + public static TItem? Set(this IMemoryCache cache, object key, TItem? value, TimeSpan absoluteExpirationRelativeToNow) { using ICacheEntry entry = cache.CreateEntry(key); entry.AbsoluteExpirationRelativeToNow = absoluteExpirationRelativeToNow; @@ -67,7 +67,7 @@ public static TItem Set(this IMemoryCache cache, object key, TItem value, return value; } - public static TItem Set(this IMemoryCache cache, object key, TItem value, IChangeToken expirationToken) + public static TItem? Set(this IMemoryCache cache, object key, TItem? value, IChangeToken expirationToken) { using ICacheEntry entry = cache.CreateEntry(key); entry.AddExpirationToken(expirationToken); @@ -76,7 +76,7 @@ public static TItem Set(this IMemoryCache cache, object key, TItem value, return value; } - public static TItem Set(this IMemoryCache cache, object key, TItem value, MemoryCacheEntryOptions options) + public static TItem? Set(this IMemoryCache cache, object key, TItem? value, MemoryCacheEntryOptions? options) { using ICacheEntry entry = cache.CreateEntry(key); if (options != null) @@ -89,9 +89,9 @@ public static TItem Set(this IMemoryCache cache, object key, TItem value, return value; } - public static TItem GetOrCreate(this IMemoryCache cache, object key, Func factory) + public static TItem? GetOrCreate(this IMemoryCache cache, object key, Func factory) { - if (!cache.TryGetValue(key, out object result)) + if (!cache.TryGetValue(key, out object? result)) { using ICacheEntry entry = cache.CreateEntry(key); @@ -99,12 +99,12 @@ public static TItem GetOrCreate(this IMemoryCache cache, object key, Func entry.Value = result; } - return (TItem)result; + return (TItem?)result; } - public static async Task GetOrCreateAsync(this IMemoryCache cache, object key, Func> factory) + public static async Task GetOrCreateAsync(this IMemoryCache cache, object key, Func> factory) { - if (!cache.TryGetValue(key, out object result)) + if (!cache.TryGetValue(key, out object? result)) { using ICacheEntry entry = cache.CreateEntry(key); @@ -112,7 +112,7 @@ public static async Task GetOrCreateAsync(this IMemoryCache cache, entry.Value = result; } - return (TItem)result; + return (TItem?)result; } } } diff --git a/src/libraries/Microsoft.Extensions.Caching.Abstractions/src/Microsoft.Extensions.Caching.Abstractions.csproj b/src/libraries/Microsoft.Extensions.Caching.Abstractions/src/Microsoft.Extensions.Caching.Abstractions.csproj index f2f695e68eff7..ddd5093c1436a 100644 --- a/src/libraries/Microsoft.Extensions.Caching.Abstractions/src/Microsoft.Extensions.Caching.Abstractions.csproj +++ b/src/libraries/Microsoft.Extensions.Caching.Abstractions/src/Microsoft.Extensions.Caching.Abstractions.csproj @@ -2,6 +2,7 @@ $(NetCoreAppCurrent);$(NetCoreAppMinimum);netstandard2.0;$(NetFrameworkMinimum) + enable true false diff --git a/src/libraries/Microsoft.Extensions.Caching.Abstractions/src/PostEvictionCallbackRegistration.cs b/src/libraries/Microsoft.Extensions.Caching.Abstractions/src/PostEvictionCallbackRegistration.cs index 532ffa2385ad0..4c4c950a45569 100644 --- a/src/libraries/Microsoft.Extensions.Caching.Abstractions/src/PostEvictionCallbackRegistration.cs +++ b/src/libraries/Microsoft.Extensions.Caching.Abstractions/src/PostEvictionCallbackRegistration.cs @@ -5,8 +5,8 @@ namespace Microsoft.Extensions.Caching.Memory { public class PostEvictionCallbackRegistration { - public PostEvictionDelegate EvictionCallback { get; set; } + public PostEvictionDelegate? EvictionCallback { get; set; } - public object State { get; set; } + public object? State { get; set; } } }