-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #177 from MartinM85/feature/175-untyped-nodes
Create types for untyped nodes
- Loading branch information
Showing
13 changed files
with
253 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
{ | ||
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |