Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
Asn1Choice.cs
1using System;
2using System.Collections.Generic;
3using System.Text;
4using System.Threading.Tasks;
6
8{
12 public class Asn1Choice : Asn1List
13 {
20 public Asn1Choice(string Name, bool TypeDef, Asn1Node[] Nodes)
21 : base(Name, TypeDef, Nodes)
22 {
23 }
24
28 public override bool ConstructedType => true;
29
36 public override Asn1Node Parse(Asn1Document Document, Asn1Macro Macro)
37 {
38 int Bak = Document.pos;
39
40 foreach (Asn1Node Choice in this.Nodes)
41 {
42 if (Choice is Asn1Type Type)
43 {
44 try
45 {
46 Document.pos = Bak;
47 return Type.Parse(Document, Macro);
48 }
49 catch (Exception)
50 {
51 // Ignore
52 }
53 }
54 }
55
56 throw Document.SyntaxError("Unable to parse choices.");
57 }
58
66 public override async Task ExportCSharp(StringBuilder Output, CSharpExportState State,
67 int Indent, CSharpExportPass Pass)
68 {
69 if (Pass == CSharpExportPass.Explicit && !this.TypeDefinition)
70 {
71 Output.Append(ToCSharp(this.Name));
72 Output.Append("Choice");
73 }
74 else
75 {
76 if (Pass == CSharpExportPass.Implicit)
77 {
78 State.ClosePending(Output);
79
80 foreach (Asn1Node Node in this.Nodes)
81 await Node.ExportCSharp(Output, State, Indent, Pass);
82
83 Output.Append(Tabs(Indent));
84 Output.Append("public enum ");
85 Output.Append(ToCSharp(this.Name));
86 Output.AppendLine("Enum");
87
88 Output.Append(Tabs(Indent));
89 Output.Append("{");
90
91 Indent++;
92
93 bool First = true;
94
95 foreach (Asn1Node Node in this.Nodes)
96 {
97 if (Node is Asn1FieldDefinition Field)
98 {
99 if (First)
100 First = false;
101 else
102 Output.Append(',');
103
104 Output.AppendLine();
105 Output.Append(Tabs(Indent));
106 Output.Append(Field.Name);
107 }
108 }
109
110 Indent--;
111
112 Output.AppendLine();
113 Output.Append(Tabs(Indent));
114 Output.AppendLine("}");
115 Output.AppendLine();
116 }
117
118 if (Pass == CSharpExportPass.Implicit || Pass == CSharpExportPass.Explicit)
119 {
120 Output.Append(Tabs(Indent));
121 Output.Append("public class ");
122 Output.Append(ToCSharp(this.Name));
123 if (!this.TypeDefinition)
124 Output.Append("Choice");
125 Output.AppendLine();
126
127 Output.Append(Tabs(Indent));
128 Output.AppendLine("{");
129
130 Indent++;
131
132 Output.Append(Tabs(Indent));
133 Output.Append("public ");
134 Output.Append(ToCSharp(this.Name));
135 if (!this.TypeDefinition)
136 Output.Append("Enum");
137 Output.AppendLine(" _choice;");
138
139 foreach (Asn1Node Node in this.Nodes)
140 await Node.ExportCSharp(Output, State, Indent, CSharpExportPass.Explicit);
141
142 Indent--;
143
144 Output.Append(Tabs(Indent));
145 Output.AppendLine("}");
146 Output.AppendLine();
147 }
148 }
149 }
150 }
151}
Represents an ASN.1 document.
Definition: Asn1Document.cs:21
void ClosePending(StringBuilder Output)
Close pending actions
Represents a ASN.1 CHOICE construct.
Definition: Asn1Choice.cs:13
Asn1Choice(string Name, bool TypeDef, Asn1Node[] Nodes)
Represents a ASN.1 CHOICE construct.
Definition: Asn1Choice.cs:20
override async Task ExportCSharp(StringBuilder Output, CSharpExportState State, int Indent, CSharpExportPass Pass)
Exports to C#
Definition: Asn1Choice.cs:66
override bool ConstructedType
If the type is a constructed type.
Definition: Asn1Choice.cs:28
override Asn1Node Parse(Asn1Document Document, Asn1Macro Macro)
Parses the portion of the document at the current position, according to the type.
Definition: Asn1Choice.cs:36
string Name
Optional field or type name.
bool TypeDefinition
If construct is part of a type definition.
Represents an ASN.1 field definition.
Abstract base class for list constructs.
Definition: Asn1List.cs:11
Base class for all ASN.1 nodes.
Definition: Asn1Node.cs:38
virtual Task ExportCSharp(StringBuilder Output, CSharpExportState State, int Indent, CSharpExportPass Pass)
Exports to C#
Definition: Asn1Node.cs:46
Abstract base class for ASN.1 types.
Definition: Asn1Type.cs:13
CSharpExportPass
Defines different C# export passes.
Definition: Asn1Node.cs:12