-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
50 lines (46 loc) · 1.88 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
using Graphdotnetv4;
using Microsoft.Kiota.Abstractions.Authentication;
using Microsoft.Kiota.Abstractions.Serialization;
using Microsoft.Kiota.Http.HttpClientLibrary;
using System.Xml.Linq;
namespace DotnetUntypedNodeSample
{
internal class Program
{
static async Task Main(string[] args)
{
var requestAdapter = new HttpClientRequestAdapter(new AnonymousAuthenticationProvider());
var apiGuruClient = new ApiClient(requestAdapter);
var metrics = await apiGuruClient.MetricsJson.GetAsync();
// print out datasets property which is untyped json
var dataSets = metrics?.Datasets;
ParseUnknownObject(dataSets);
}
private static void ParseUnknownObject(UntypedNode untypedNode, string indent = "")
{
switch (untypedNode)
{
case UntypedObject untypedObject:
Console.WriteLine(indent + "Found object value: ");
var properties = untypedObject.GetValue();
foreach (var (name, node) in properties)
{
Console.WriteLine(indent + "Property Name: " + name);
ParseUnknownObject(node, indent + " ");
}
break;
case UntypedArray untypedArray:
Console.WriteLine(indent + "Found array value: ");
foreach (var item in untypedArray.GetValue())
{
Console.WriteLine(indent + "New Item: ");
ParseUnknownObject(item, indent + " ");
}
break;
default:
Console.WriteLine(indent + "Found scalar value : " + KiotaJsonSerializer.SerializeAsString(untypedNode));
break;
}
}
}
}