Revisiting nullable annotations on caching (#66215)
authorMaryam Ariyan <maryam.ariyan@microsoft.com>
Mon, 7 Mar 2022 22:45:01 +0000 (17:45 -0500)
committerGitHub <noreply@github.com>
Mon, 7 Mar 2022 22:45:01 +0000 (16:45 -0600)
* Revisiting nullable annotations on caching

* Fix up more nullablity mismatches

src/libraries/Microsoft.Extensions.Caching.Memory/ref/Microsoft.Extensions.Caching.Memory.cs
src/libraries/Microsoft.Extensions.Configuration.Binder/ref/Microsoft.Extensions.Configuration.Binder.cs
src/libraries/Microsoft.Extensions.Primitives/ref/Microsoft.Extensions.Primitives.cs
src/libraries/Microsoft.Extensions.Primitives/src/StringValues.cs

index e7b28d2..e61a5b0 100644 (file)
@@ -27,6 +27,7 @@ namespace Microsoft.Extensions.Caching.Memory
         public MemoryCache(Microsoft.Extensions.Options.IOptions<Microsoft.Extensions.Caching.Memory.MemoryCacheOptions> optionsAccessor) { }
         public MemoryCache(Microsoft.Extensions.Options.IOptions<Microsoft.Extensions.Caching.Memory.MemoryCacheOptions> optionsAccessor, Microsoft.Extensions.Logging.ILoggerFactory loggerFactory) { }
         public int Count { get { throw null; } }
+        public void Clear() { }
         public void Compact(double percentage) { }
         public Microsoft.Extensions.Caching.Memory.ICacheEntry CreateEntry(object key) { throw null; }
         public void Dispose() { }
@@ -34,7 +35,6 @@ namespace Microsoft.Extensions.Caching.Memory
         ~MemoryCache() { }
         public void Remove(object key) { }
         public bool TryGetValue(object key, out object? result) { throw null; }
-        public void Clear() { }
     }
     public partial class MemoryCacheOptions : Microsoft.Extensions.Options.IOptions<Microsoft.Extensions.Caching.Memory.MemoryCacheOptions>
     {
index efcb740..d42ef62 100644 (file)
@@ -27,7 +27,7 @@ namespace Microsoft.Extensions.Configuration
         [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("In case the type is non-primitive, the trimmer cannot statically analyze the object's type so its members may be trimmed.")]
         public static object? GetValue(this Microsoft.Extensions.Configuration.IConfiguration configuration, [System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.All)] System.Type type, string key) { throw null; }
         [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("In case the type is non-primitive, the trimmer cannot statically analyze the object's type so its members may be trimmed.")]
-        public static object? GetValue(this Microsoft.Extensions.Configuration.IConfiguration configuration, [System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.All)] System.Type type, string key, object defaultValue) { throw null; }
+        public static object? GetValue(this Microsoft.Extensions.Configuration.IConfiguration configuration, [System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.All)] System.Type type, string key, object? defaultValue) { throw null; }
         [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("In case the type is non-primitive, the trimmer cannot statically analyze the object's type so its members may be trimmed.")]
         public static T? GetValue<[System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.All)] T>(this Microsoft.Extensions.Configuration.IConfiguration configuration, string key) { throw null; }
         [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("In case the type is non-primitive, the trimmer cannot statically analyze the object's type so its members may be trimmed.")]
index afa9bc3..5811822 100644 (file)
@@ -180,7 +180,7 @@ namespace Microsoft.Extensions.Primitives
             private int _dummyPrimitive;
             public Enumerator(ref Microsoft.Extensions.Primitives.StringValues values) { throw null; }
             public string? Current { get { throw null; } }
-            object System.Collections.IEnumerator.Current { get { throw null; } }
+            object? System.Collections.IEnumerator.Current { get { throw null; } }
             public void Dispose() { }
             public bool MoveNext() { throw null; }
             void System.Collections.IEnumerator.Reset() { }
index 029b692..f50fa82 100644 (file)
@@ -638,7 +638,7 @@ namespace Microsoft.Extensions.Primitives
         /// <param name="left">The <see cref="string"/> to compare.</param>
         /// <param name="right">The <see cref="StringValues"/> to compare.</param>
         /// <returns><c>true</c> if the value of <paramref name="left"/> is different to the value of <paramref name="right"/>; otherwise, <c>false</c>.</returns>
-        public static bool operator !=(string left, StringValues right) => !Equals(new StringValues(left), right);
+        public static bool operator !=(string? left, StringValues right) => !Equals(new StringValues(left), right);
 
         /// <inheritdoc cref="Equals(StringValues, string[])" />
         public static bool operator ==(StringValues left, string?[]? right) => Equals(left, new StringValues(right));