diff --git a/dotnet/src/Connectors/Connectors.Memory.AzureCosmosDBNoSQL/AzureCosmosDBNoSQLMemoryStore.cs b/dotnet/src/Connectors/Connectors.Memory.AzureCosmosDBNoSQL/AzureCosmosDBNoSQLMemoryStore.cs index acd93973eeb6..d3df09f8350c 100644 --- a/dotnet/src/Connectors/Connectors.Memory.AzureCosmosDBNoSQL/AzureCosmosDBNoSQLMemoryStore.cs +++ b/dotnet/src/Connectors/Connectors.Memory.AzureCosmosDBNoSQL/AzureCosmosDBNoSQLMemoryStore.cs @@ -400,7 +400,9 @@ protected virtual void Dispose(bool disposing) /// /// [DebuggerDisplay("{GetDebuggerDisplay()}")] -internal class MemoryRecordWithSimilarityScore( +#pragma warning disable CA1812 // 'MemoryRecordWithSimilarityScore' is an internal class that is apparently never instantiated. If so, remove the code from the assembly. If this class is intended to contain only static members, make it 'static' (Module in Visual Basic). (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1812) +internal sealed class MemoryRecordWithSimilarityScore( +#pragma warning restore CA1812 MemoryRecordMetadata metadata, ReadOnlyMemory embedding, string? key, @@ -421,7 +423,7 @@ private string GetDebuggerDisplay() /// Creates a new record that also serializes an "id" property. /// [DebuggerDisplay("{GetDebuggerDisplay()}")] -internal class MemoryRecordWithId : MemoryRecord +internal sealed class MemoryRecordWithId : MemoryRecord { /// /// Creates a new record that also serializes an "id" property. diff --git a/dotnet/src/Connectors/Connectors.Memory.AzureCosmosDBNoSQL/CosmosSystemTextJSonSerializer.cs b/dotnet/src/Connectors/Connectors.Memory.AzureCosmosDBNoSQL/CosmosSystemTextJSonSerializer.cs index 7d99004b6879..0737ce09c120 100644 --- a/dotnet/src/Connectors/Connectors.Memory.AzureCosmosDBNoSQL/CosmosSystemTextJSonSerializer.cs +++ b/dotnet/src/Connectors/Connectors.Memory.AzureCosmosDBNoSQL/CosmosSystemTextJSonSerializer.cs @@ -3,6 +3,7 @@ // Taken from https://github.com/Azure/azure-cosmos-dotnet-v3/pull/4332 using System; +using System.Diagnostics.CodeAnalysis; using System.IO; using System.Reflection; using System.Text.Json; @@ -13,7 +14,7 @@ namespace Microsoft.Azure.Cosmos; /// /// This class provides a default implementation of System.Text.Json Cosmos Linq Serializer. /// -internal class CosmosSystemTextJsonSerializer : CosmosLinqSerializer +internal sealed class CosmosSystemTextJsonSerializer : CosmosLinqSerializer { /// /// A read-only instance of . @@ -32,6 +33,7 @@ internal class CosmosSystemTextJsonSerializer : CosmosLinqSerializer } /// + [return: MaybeNull] public override T FromStream(Stream stream) { if (stream == null) @@ -107,9 +109,9 @@ public override Stream ToStream(T input) /// To handle such scenarios, please create a custom serializer which inherits from the and overrides the /// SerializeMemberName to add any special handling. /// - public override string SerializeMemberName(MemberInfo memberInfo) + public override string? SerializeMemberName(MemberInfo memberInfo) { - JsonExtensionDataAttribute jsonExtensionDataAttribute = + JsonExtensionDataAttribute? jsonExtensionDataAttribute = memberInfo.GetCustomAttribute(true); if (jsonExtensionDataAttribute != null) @@ -117,12 +119,12 @@ public override string SerializeMemberName(MemberInfo memberInfo) return null; } - JsonPropertyNameAttribute jsonPropertyNameAttribute = memberInfo.GetCustomAttribute(true); - - string memberName = !string.IsNullOrEmpty(jsonPropertyNameAttribute?.Name) - ? jsonPropertyNameAttribute.Name - : memberInfo.Name; + JsonPropertyNameAttribute? jsonPropertyNameAttribute = memberInfo.GetCustomAttribute(true); + if (jsonPropertyNameAttribute is { } && !string.IsNullOrEmpty(jsonPropertyNameAttribute.Name)) + { + return jsonPropertyNameAttribute.Name; + } - return memberName; + return memberInfo.Name; } }