Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create types for untyped nodes #177

Merged
merged 12 commits into from
Mar 20, 2024
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.Kiota.Abstractions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<PackageProjectUrl>https://aka.ms/kiota/docs</PackageProjectUrl>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<Deterministic>true</Deterministic>
<VersionPrefix>1.7.12</VersionPrefix>
<VersionPrefix>1.8.0</VersionPrefix>
<VersionSuffix></VersionSuffix>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<SignAssembly>false</SignAssembly>
Expand Down
22 changes: 22 additions & 0 deletions src/serialization/UntypedArray.cs
Original file line number Diff line number Diff line change
@@ -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
{
/// <summary>
/// Represents an untyped node with the collection of untyped values.
/// </summary>
/// <param name="value">The collection of child nodes.</param>
public class UntypedArray(IEnumerable<UntypedNode> value) : UntypedNode
{
private readonly IEnumerable<UntypedNode> _value = value;
/// <summary>
/// Gets the collection of untyped child nodes.
/// </summary>
/// <returns>The collection of untyped child nodes.</returns>
public new IEnumerable<UntypedNode> GetValue() => _value;
}
}
20 changes: 20 additions & 0 deletions src/serialization/UntypedBoolean.cs
Original file line number Diff line number Diff line change
@@ -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
{
/// <summary>
/// Represents an untyped node with boolean value.
/// </summary>
/// <param name="value">The boolean value associated with the node.</param>
public class UntypedBoolean(bool value) : UntypedNode
{
private readonly bool _value = value;
/// <summary>
/// Gets the value associated with untyped boolean node.
/// </summary>
/// <returns>The value associated with untyped boolean node.</returns>
public new bool GetValue() => _value;
}
}
20 changes: 20 additions & 0 deletions src/serialization/UntypedDecimal.cs
Original file line number Diff line number Diff line change
@@ -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
{
/// <summary>
/// Represents an untyped node with decimal value.
/// </summary>
/// <param name="value">The decimal value associated with the node.</param>
public class UntypedDecimal(decimal value) : UntypedNode
{
private readonly decimal _value = value;
/// <summary>
/// Gets the value associated with untyped decimal node.
/// </summary>
/// <returns>The value associated with untyped decimal node.</returns>
public new decimal GetValue() => _value;
}
}
20 changes: 20 additions & 0 deletions src/serialization/UntypedDouble.cs
Original file line number Diff line number Diff line change
@@ -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
{
/// <summary>
/// Represents an untyped node with double value.
/// </summary>
/// <param name="value">The double value associated with the node.</param>
public class UntypedDouble(double value) : UntypedNode
{
private readonly double _value = value;
/// <summary>
/// Gets the value associated with untyped double node.
/// </summary>
/// <returns>The value associated with untyped double node.</returns>
public new double GetValue() => _value;
}
}
20 changes: 20 additions & 0 deletions src/serialization/UntypedFloat.cs
Original file line number Diff line number Diff line change
@@ -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
{
/// <summary>
/// Represents an untyped node with float value.
/// </summary>
/// <param name="value">The float value associated with the node.</param>
public class UntypedFloat(float value) : UntypedNode
{
private readonly float _value = value;
/// <summary>
/// Gets the value associated with untyped float node.
/// </summary>
/// <returns>The value associated with untyped float node.</returns>
public new float GetValue() => _value;
}
}
20 changes: 20 additions & 0 deletions src/serialization/UntypedInteger.cs
Original file line number Diff line number Diff line change
@@ -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
{
/// <summary>
/// Represents an untyped node with integer value.
/// </summary>
/// <param name="value">The integer value associated with the node.</param>
public class UntypedInteger(int value): UntypedNode
{
private readonly int _value = value;
/// <summary>
/// Gets the value associated with untyped integer node.
/// </summary>
/// <returns>The value associated with untyped integer node.</returns>
public new int GetValue() => _value;
}
}
23 changes: 23 additions & 0 deletions src/serialization/UntypedLong.cs
Original file line number Diff line number Diff line change
@@ -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
{
/// <summary>
/// Represents an untyped node with long value.
/// </summary>
/// <param name="value">The long value associated with the node.</param>
public class UntypedLong(long value) : UntypedNode
{
/// <summary>
/// The value associated with untyped long node.
/// </summary>
private readonly long _value = value;
/// <summary>
/// Gets the value associated with untyped long node.
/// </summary>
/// <returns>The value associated with untyped long node.</returns>
public new long GetValue() => _value;
}
}
41 changes: 41 additions & 0 deletions src/serialization/UntypedNode.cs
Original file line number Diff line number Diff line change
@@ -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
{
/// <summary>
/// Base class for untyped node.
/// </summary>
public class UntypedNode : IParsable
baywet marked this conversation as resolved.
Show resolved Hide resolved
{
private static readonly IDictionary<string, Action<IParseNode>> _fieldDeserializers = new ReadOnlyDictionary<string, Action<IParseNode>>(new Dictionary<string, Action<IParseNode>>());
/// <summary>
/// The deserialization information for the current model
/// </summary>
public virtual IDictionary<string, Action<IParseNode>> GetFieldDeserializers() => _fieldDeserializers;
/// <summary>
/// Serializes information the current object
/// <param name="writer">Serialization writer to use to serialize this model</param>
/// </summary>
public virtual void Serialize(ISerializationWriter writer) => _ = writer ?? throw new ArgumentNullException(nameof(writer));
/// <summary>
/// Creates a new instance of the appropriate class based on discriminator value
/// </summary>
/// <param name="parseNode">The parse node to use to read the discriminator value and create the object</param>
public static UntypedNode CreateFromDiscriminatorValue(IParseNode parseNode)
{
_ = parseNode ?? throw new ArgumentNullException(nameof(parseNode));
return new();
}
/// <summary>
/// Gets the value assigned to untyped node.
/// </summary>
/// <returns>The value assigned to untyped node.</returns>
public object? GetValue() => throw new NotImplementedException();
}
}
18 changes: 18 additions & 0 deletions src/serialization/UntypedNull.cs
Original file line number Diff line number Diff line change
@@ -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
{
/// <summary>
/// Represents an untyped node without the value.
/// </summary>
public class UntypedNull : UntypedNode
{
/// <summary>
/// Gets the value associated with untyped null node.
/// </summary>
/// <returns>The value associated with untyped null node.</returns>
public new object? GetValue() => null;
}
}
22 changes: 22 additions & 0 deletions src/serialization/UntypedObject.cs
Original file line number Diff line number Diff line change
@@ -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
{
/// <summary>
/// Represents an untyped node with object value.
/// </summary>
/// <param name="properties">Properties associated with the node.</param>
public class UntypedObject(IDictionary<string, UntypedNode> properties) : UntypedNode
{
private readonly IDictionary<string, UntypedNode> _properties = properties;
/// <summary>
/// Gets properties associated with untyped object node.
/// </summary>
/// <returns>Properties associated with untyped object node.</returns>
public new IDictionary<string, UntypedNode> GetValue() => _properties;
}
}
20 changes: 20 additions & 0 deletions src/serialization/UntypedString.cs
Original file line number Diff line number Diff line change
@@ -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
{
/// <summary>
/// Represents an untyped node with string value.
/// </summary>
/// <param name="value">The string value associated with the node.</param>
public class UntypedString(string? value) : UntypedNode
{
private readonly string? _value = value;
/// <summary>
/// Gets the string associated with untyped string node.
/// </summary>
/// <returns>The string associated with untyped string node.</returns>
public new string? GetValue() => _value;
}
}
Loading