Repository navigation
Expand file tree
/
Copy pathParseNode.cs
More file actions
137 lines (112 loc) · 4.73 KB
/
Copy pathParseNode.cs
File metadata and controls
137 lines (112 loc) · 4.73 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
// Copyright (c) The LEGO Group. All rights reserved.
namespace LEGO.AsyncAPI.Readers.ParseNodes
{
using System;
using System.Collections.Generic;
using System.Text.Json.Nodes;
using LEGO.AsyncAPI.Models;
using LEGO.AsyncAPI.Models.Interfaces;
using LEGO.AsyncAPI.Readers.Exceptions;
public abstract class ParseNode
{
protected ParseNode(ParsingContext parsingContext)
{
this.Context = parsingContext;
}
public ParsingContext Context { get; }
public MapNode CheckMapNode(string nodeName)
{
if (!(this is MapNode mapNode))
{
throw new AsyncApiReaderException($"{nodeName} must be a map/object", this.Context);
}
return mapNode;
}
public static ParseNode Create(ParsingContext context, JsonNode node)
{
if (node is JsonArray listNode)
{
return new ListNode(context, listNode);
}
if (node is JsonObject mapNode)
{
return new MapNode(context, mapNode);
}
return new ValueNode(context, node as JsonValue);
}
public virtual List<T> CreateList<T>(Func<MapNode, T> map)
{
throw new AsyncApiReaderException("Cannot create list from this type of node.", this.Context);
}
public virtual Dictionary<string, T> CreateMap<T>(Func<MapNode, T> map)
{
throw new AsyncApiReaderException("Cannot create map from this type of node.", this.Context);
}
public virtual Dictionary<string, T> CreateBindingMapWithReference<T>(
ReferenceType referenceType,
Func<ParseNode, T> map)
where T : class, IBinding
{
throw new AsyncApiReaderException("Cannot create map from this reference.", this.Context);
}
public virtual Dictionary<string, T> CreateMapWithReference<T>(
ReferenceType referenceType,
Func<MapNode, T> map)
where T : class, IAsyncApiReferenceable
{
throw new AsyncApiReaderException("Cannot create map from this reference.", this.Context);
}
public virtual List<T> CreateSimpleList<T>(Func<ValueNode, T> map)
{
throw new AsyncApiReaderException("Cannot create simple list from this type of node.", this.Context);
}
public virtual Dictionary<string, T> CreateSimpleMap<T>(Func<ValueNode, T> map)
{
throw new AsyncApiReaderException("Cannot create simple map from this type of node.", this.Context);
}
public virtual AsyncApiAny CreateAny()
{
throw new AsyncApiReaderException("Cannot create an Any object this type of node.", this.Context);
}
public virtual string GetRaw()
{
throw new AsyncApiReaderException("Cannot get raw value from this type of node.", this.Context);
}
public virtual string GetScalarValue()
{
throw new AsyncApiReaderException("Cannot create a scalar value from this type of node.", this.Context);
}
public virtual string GetScalarValueOrDefault(string defaultValue = null)
{
throw new AsyncApiReaderException("Cannot create a scalar value from this type of node.", this.Context);
}
public virtual bool GetBooleanValue()
{
throw new AsyncApiReaderException("Cannot create a scalar value from this type of node.", this.Context);
}
public virtual bool? GetBooleanValueOrDefault(bool? defaultValue = null)
{
throw new AsyncApiReaderException("Cannot create a scalar value from this type of node.", this.Context);
}
public virtual int GetIntegerValue()
{
throw new AsyncApiReaderException("Cannot create a scalar value from this type of node.", this.Context);
}
public virtual int? GetIntegerValueOrDefault(int? defaultValue = null)
{
throw new AsyncApiReaderException("Cannot create a scalar value from this type of node.", this.Context);
}
public virtual long GetLongValue()
{
throw new AsyncApiReaderException("Cannot create a scalar value from this type of node.", this.Context);
}
public virtual long? GetLongValueOrDefault(long? defaultValue = null)
{
throw new AsyncApiReaderException("Cannot create a scalar value from this type of node.", this.Context);
}
public virtual List<AsyncApiAny> CreateListOfAny()
{
throw new AsyncApiReaderException("Cannot create a list from this type of node.", this.Context);
}
}
}