From 57e0c2f0c71499ca01fb10e275058956da3659e0 Mon Sep 17 00:00:00 2001 From: Felix Date: Thu, 11 Jan 2024 01:18:52 +0100 Subject: [PATCH] GetCollectionOf* methods of IParseNode can now return null --- src/serialization/IParseNode.cs | 8 ++++---- .../KiotaJsonSerializer.Deserialization.cs | 12 ++++++------ src/serialization/KiotaSerializer.Deserialization.cs | 12 ++++++------ 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/serialization/IParseNode.cs b/src/serialization/IParseNode.cs index e9628dd3..13d769d5 100644 --- a/src/serialization/IParseNode.cs +++ b/src/serialization/IParseNode.cs @@ -95,22 +95,22 @@ public interface IParseNode /// Gets the collection of primitive values of the node. /// /// The collection of primitive values. - IEnumerable GetCollectionOfPrimitiveValues(); + IEnumerable? GetCollectionOfPrimitiveValues(); /// /// Gets the collection of enum values of the node. /// /// The collection of enum values. #if NET5_0_OR_GREATER - IEnumerable GetCollectionOfEnumValues<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]T>() where T : struct, Enum; + IEnumerable? GetCollectionOfEnumValues<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]T>() where T : struct, Enum; #else - IEnumerable GetCollectionOfEnumValues() where T : struct, Enum; + IEnumerable? GetCollectionOfEnumValues() where T : struct, Enum; #endif /// /// Gets the collection of model objects values of the node. /// /// The factory to use to create the model object. /// The collection of model objects values. - IEnumerable GetCollectionOfObjectValues(ParsableFactory factory) where T : IParsable; + IEnumerable? GetCollectionOfObjectValues(ParsableFactory factory) where T : IParsable; /// /// Gets the enum value of the node. /// diff --git a/src/serialization/KiotaJsonSerializer.Deserialization.cs b/src/serialization/KiotaJsonSerializer.Deserialization.cs index 27ac6817..62c001f2 100644 --- a/src/serialization/KiotaJsonSerializer.Deserialization.cs +++ b/src/serialization/KiotaJsonSerializer.Deserialization.cs @@ -55,23 +55,23 @@ public static partial class KiotaJsonSerializer /// /// The stream to deserialize. /// The factory to create the object. - public static IEnumerable DeserializeCollection(Stream stream, ParsableFactory parsableFactory) where T : IParsable + public static IEnumerable? DeserializeCollection(Stream stream, ParsableFactory parsableFactory) where T : IParsable => KiotaSerializer.DeserializeCollection(_jsonContentType, stream, parsableFactory); /// /// Deserializes the given stream into a collection of objects based on the content type. /// /// The serialized representation of the objects. /// The factory to create the object. - public static IEnumerable DeserializeCollection(string serializedRepresentation, ParsableFactory parsableFactory) where T : IParsable + public static IEnumerable? DeserializeCollection(string serializedRepresentation, ParsableFactory parsableFactory) where T : IParsable => KiotaSerializer.DeserializeCollection(_jsonContentType, serializedRepresentation, parsableFactory); /// /// Deserializes the given stream into a collection of objects based on the content type. /// /// The stream to deserialize. #if NET5_0_OR_GREATER - public static IEnumerable DeserializeCollection<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)] T>(Stream stream) where T : IParsable + public static IEnumerable? DeserializeCollection<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)] T>(Stream stream) where T : IParsable #else - public static IEnumerable DeserializeCollection(Stream stream) where T : IParsable + public static IEnumerable? DeserializeCollection(Stream stream) where T : IParsable #endif => KiotaSerializer.DeserializeCollection(_jsonContentType, stream); /// @@ -79,9 +79,9 @@ public static IEnumerable DeserializeCollection(Stream stream) where T : I /// /// The serialized representation of the object. #if NET5_0_OR_GREATER - public static IEnumerable DeserializeCollection<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)] T>(string serializedRepresentation) where T : IParsable + public static IEnumerable? DeserializeCollection<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)] T>(string serializedRepresentation) where T : IParsable #else - public static IEnumerable DeserializeCollection(string serializedRepresentation) where T : IParsable + public static IEnumerable? DeserializeCollection(string serializedRepresentation) where T : IParsable #endif => KiotaSerializer.DeserializeCollection(_jsonContentType, serializedRepresentation); } \ No newline at end of file diff --git a/src/serialization/KiotaSerializer.Deserialization.cs b/src/serialization/KiotaSerializer.Deserialization.cs index 5756b08c..4e534049 100644 --- a/src/serialization/KiotaSerializer.Deserialization.cs +++ b/src/serialization/KiotaSerializer.Deserialization.cs @@ -90,7 +90,7 @@ private static ParsableFactory GetFactoryFromType() where T : IParsable /// The content type of the stream. /// The stream to deserialize. /// The factory to create the object. - public static IEnumerable DeserializeCollection(string contentType, Stream stream, ParsableFactory parsableFactory) where T : IParsable + public static IEnumerable? DeserializeCollection(string contentType, Stream stream, ParsableFactory parsableFactory) where T : IParsable { if(string.IsNullOrEmpty(contentType)) throw new ArgumentNullException(nameof(contentType)); if(stream == null) throw new ArgumentNullException(nameof(stream)); @@ -104,7 +104,7 @@ public static IEnumerable DeserializeCollection(string contentType, Stream /// The content type of the stream. /// The serialized representation of the objects. /// The factory to create the object. - public static IEnumerable DeserializeCollection(string contentType, string serializedRepresentation, ParsableFactory parsableFactory) where T : IParsable + public static IEnumerable? DeserializeCollection(string contentType, string serializedRepresentation, ParsableFactory parsableFactory) where T : IParsable { if(string.IsNullOrEmpty(serializedRepresentation)) throw new ArgumentNullException(nameof(serializedRepresentation)); using var stream = GetStreamFromString(serializedRepresentation); @@ -116,9 +116,9 @@ public static IEnumerable DeserializeCollection(string contentType, string /// The content type of the stream. /// The stream to deserialize. #if NET5_0_OR_GREATER - public static IEnumerable DeserializeCollection<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)] T>(string contentType, Stream stream) where T : IParsable + public static IEnumerable? DeserializeCollection<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)] T>(string contentType, Stream stream) where T : IParsable #else - public static IEnumerable DeserializeCollection(string contentType, Stream stream) where T : IParsable + public static IEnumerable? DeserializeCollection(string contentType, Stream stream) where T : IParsable #endif => DeserializeCollection(contentType, stream, GetFactoryFromType()); /// @@ -127,9 +127,9 @@ public static IEnumerable DeserializeCollection(string contentType, Stream /// The content type of the stream. /// The serialized representation of the object. #if NET5_0_OR_GREATER - public static IEnumerable DeserializeCollection<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)] T>(string contentType, string serializedRepresentation) where T : IParsable + public static IEnumerable? DeserializeCollection<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)] T>(string contentType, string serializedRepresentation) where T : IParsable #else - public static IEnumerable DeserializeCollection(string contentType, string serializedRepresentation) where T : IParsable + public static IEnumerable? DeserializeCollection(string contentType, string serializedRepresentation) where T : IParsable #endif => DeserializeCollection(contentType, serializedRepresentation, GetFactoryFromType()); } \ No newline at end of file