diff --git a/CHANGELOG.md b/CHANGELOG.md index 653577a8..a1c96011 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [1.8.0] - 2024-03-18 + +### Added + +- Added support for untyped nodes. (https://github.com/microsoft/kiota-abstractions-dotnet/issues/175) + ## [1.7.12] - 2024-03-08 ### Changed diff --git a/src/Microsoft.Kiota.Abstractions.csproj b/src/Microsoft.Kiota.Abstractions.csproj index 151b4bd1..068559a7 100644 --- a/src/Microsoft.Kiota.Abstractions.csproj +++ b/src/Microsoft.Kiota.Abstractions.csproj @@ -14,7 +14,7 @@ https://aka.ms/kiota/docs true true - 1.7.12 + 1.8.0 true false diff --git a/src/serialization/UntypedArray.cs b/src/serialization/UntypedArray.cs new file mode 100644 index 00000000..2b3a0581 --- /dev/null +++ b/src/serialization/UntypedArray.cs @@ -0,0 +1,22 @@ +// ------------------------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information. +// ------------------------------------------------------------------------------ + +using System.Collections.Generic; + +namespace Microsoft.Kiota.Abstractions.Serialization +{ + /// + /// Represents an untyped node with the collection of untyped values. + /// + /// The collection of child nodes. + public class UntypedArray(IEnumerable value) : UntypedNode + { + private readonly IEnumerable _value = value; + /// + /// Gets the collection of untyped child nodes. + /// + /// The collection of untyped child nodes. + public new IEnumerable GetValue() => _value; + } +} diff --git a/src/serialization/UntypedBoolean.cs b/src/serialization/UntypedBoolean.cs new file mode 100644 index 00000000..ca40e101 --- /dev/null +++ b/src/serialization/UntypedBoolean.cs @@ -0,0 +1,20 @@ +// ------------------------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information. +// ------------------------------------------------------------------------------ + +namespace Microsoft.Kiota.Abstractions.Serialization +{ + /// + /// Represents an untyped node with boolean value. + /// + /// The boolean value associated with the node. + public class UntypedBoolean(bool value) : UntypedNode + { + private readonly bool _value = value; + /// + /// Gets the value associated with untyped boolean node. + /// + /// The value associated with untyped boolean node. + public new bool GetValue() => _value; + } +} diff --git a/src/serialization/UntypedDecimal.cs b/src/serialization/UntypedDecimal.cs new file mode 100644 index 00000000..d333a7ba --- /dev/null +++ b/src/serialization/UntypedDecimal.cs @@ -0,0 +1,20 @@ +// ------------------------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information. +// ------------------------------------------------------------------------------ + +namespace Microsoft.Kiota.Abstractions.Serialization +{ + /// + /// Represents an untyped node with decimal value. + /// + /// The decimal value associated with the node. + public class UntypedDecimal(decimal value) : UntypedNode + { + private readonly decimal _value = value; + /// + /// Gets the value associated with untyped decimal node. + /// + /// The value associated with untyped decimal node. + public new decimal GetValue() => _value; + } +} diff --git a/src/serialization/UntypedDouble.cs b/src/serialization/UntypedDouble.cs new file mode 100644 index 00000000..208ff69a --- /dev/null +++ b/src/serialization/UntypedDouble.cs @@ -0,0 +1,20 @@ +// ------------------------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information. +// ------------------------------------------------------------------------------ + +namespace Microsoft.Kiota.Abstractions.Serialization +{ + /// + /// Represents an untyped node with double value. + /// + /// The double value associated with the node. + public class UntypedDouble(double value) : UntypedNode + { + private readonly double _value = value; + /// + /// Gets the value associated with untyped double node. + /// + /// The value associated with untyped double node. + public new double GetValue() => _value; + } +} diff --git a/src/serialization/UntypedFloat.cs b/src/serialization/UntypedFloat.cs new file mode 100644 index 00000000..5d2bf368 --- /dev/null +++ b/src/serialization/UntypedFloat.cs @@ -0,0 +1,20 @@ +// ------------------------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information. +// ------------------------------------------------------------------------------ + +namespace Microsoft.Kiota.Abstractions.Serialization +{ + /// + /// Represents an untyped node with float value. + /// + /// The float value associated with the node. + public class UntypedFloat(float value) : UntypedNode + { + private readonly float _value = value; + /// + /// Gets the value associated with untyped float node. + /// + /// The value associated with untyped float node. + public new float GetValue() => _value; + } +} diff --git a/src/serialization/UntypedInteger.cs b/src/serialization/UntypedInteger.cs new file mode 100644 index 00000000..cc698f3b --- /dev/null +++ b/src/serialization/UntypedInteger.cs @@ -0,0 +1,20 @@ +// ------------------------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information. +// ------------------------------------------------------------------------------ + +namespace Microsoft.Kiota.Abstractions.Serialization +{ + /// + /// Represents an untyped node with integer value. + /// + /// The integer value associated with the node. + public class UntypedInteger(int value): UntypedNode + { + private readonly int _value = value; + /// + /// Gets the value associated with untyped integer node. + /// + /// The value associated with untyped integer node. + public new int GetValue() => _value; + } +} diff --git a/src/serialization/UntypedLong.cs b/src/serialization/UntypedLong.cs new file mode 100644 index 00000000..ded0bf3f --- /dev/null +++ b/src/serialization/UntypedLong.cs @@ -0,0 +1,23 @@ +// ------------------------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information. +// ------------------------------------------------------------------------------ + +namespace Microsoft.Kiota.Abstractions.Serialization +{ + /// + /// Represents an untyped node with long value. + /// + /// The long value associated with the node. + public class UntypedLong(long value) : UntypedNode + { + /// + /// The value associated with untyped long node. + /// + private readonly long _value = value; + /// + /// Gets the value associated with untyped long node. + /// + /// The value associated with untyped long node. + public new long GetValue() => _value; + } +} diff --git a/src/serialization/UntypedNode.cs b/src/serialization/UntypedNode.cs new file mode 100644 index 00000000..2abfc2d1 --- /dev/null +++ b/src/serialization/UntypedNode.cs @@ -0,0 +1,41 @@ +// ------------------------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information. +// ------------------------------------------------------------------------------ + +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; + +namespace Microsoft.Kiota.Abstractions.Serialization +{ + /// + /// Base class for untyped node. + /// + public class UntypedNode : IParsable + { + private static readonly IDictionary> _fieldDeserializers = new ReadOnlyDictionary>(new Dictionary>()); + /// + /// The deserialization information for the current model + /// + public virtual IDictionary> GetFieldDeserializers() => _fieldDeserializers; + /// + /// Serializes information the current object + /// Serialization writer to use to serialize this model + /// + public virtual void Serialize(ISerializationWriter writer) => _ = writer ?? throw new ArgumentNullException(nameof(writer)); + /// + /// Creates a new instance of the appropriate class based on discriminator value + /// + /// The parse node to use to read the discriminator value and create the object + public static UntypedNode CreateFromDiscriminatorValue(IParseNode parseNode) + { + _ = parseNode ?? throw new ArgumentNullException(nameof(parseNode)); + return new(); + } + /// + /// Gets the value assigned to untyped node. + /// + /// The value assigned to untyped node. + public object? GetValue() => throw new NotImplementedException(); + } +} diff --git a/src/serialization/UntypedNull.cs b/src/serialization/UntypedNull.cs new file mode 100644 index 00000000..883cadd4 --- /dev/null +++ b/src/serialization/UntypedNull.cs @@ -0,0 +1,18 @@ +// ------------------------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information. +// ------------------------------------------------------------------------------ + +namespace Microsoft.Kiota.Abstractions.Serialization +{ + /// + /// Represents an untyped node without the value. + /// + public class UntypedNull : UntypedNode + { + /// + /// Gets the value associated with untyped null node. + /// + /// The value associated with untyped null node. + public new object? GetValue() => null; + } +} diff --git a/src/serialization/UntypedObject.cs b/src/serialization/UntypedObject.cs new file mode 100644 index 00000000..6f3f4200 --- /dev/null +++ b/src/serialization/UntypedObject.cs @@ -0,0 +1,22 @@ +// ------------------------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information. +// ------------------------------------------------------------------------------ + +using System.Collections.Generic; + +namespace Microsoft.Kiota.Abstractions.Serialization +{ + /// + /// Represents an untyped node with object value. + /// + /// Properties associated with the node. + public class UntypedObject(IDictionary properties) : UntypedNode + { + private readonly IDictionary _properties = properties; + /// + /// Gets properties associated with untyped object node. + /// + /// Properties associated with untyped object node. + public new IDictionary GetValue() => _properties; + } +} diff --git a/src/serialization/UntypedString.cs b/src/serialization/UntypedString.cs new file mode 100644 index 00000000..bc90e9ad --- /dev/null +++ b/src/serialization/UntypedString.cs @@ -0,0 +1,20 @@ +// ------------------------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information. +// ------------------------------------------------------------------------------ + +namespace Microsoft.Kiota.Abstractions.Serialization +{ + /// + /// Represents an untyped node with string value. + /// + /// The string value associated with the node. + public class UntypedString(string? value) : UntypedNode + { + private readonly string? _value = value; + /// + /// Gets the string associated with untyped string node. + /// + /// The string associated with untyped string node. + public new string? GetValue() => _value; + } +}