Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
Asn1Definitions.cs
1using System;
2using System.Collections.Generic;
3using System.Text;
4using System.Threading.Tasks;
6
8{
12 public enum Asn1Tags
13 {
17 Automatic,
18
22 Implicit,
23
27 Explicit
28 }
29
34 {
35 private readonly string identifier;
36 private readonly Asn1Oid oid;
37 private readonly Asn1Tags? tags;
38 private readonly bool _abstract;
39 private readonly Asn1Module body;
40 private readonly Asn1Document document;
41
53 {
54 this.identifier = Identifier;
55 this.oid = Oid;
56 this.tags = Tags;
57 this._abstract = Abstract;
58 this.body = Body;
59 this.document = Document;
60 }
61
65 public string Identifier => this.identifier;
66
70 public Asn1Oid Oid => this.oid;
71
75 public Asn1Tags? Tags => this.tags;
76
80 public bool Abstract => this._abstract;
81
85 public Asn1Module Body => this.body;
86
90 public Asn1Document Document => this.document;
91
99 public override async Task ExportCSharp(StringBuilder Output, CSharpExportState State,
100 int Indent, CSharpExportPass Pass)
101 {
102 if (Pass == CSharpExportPass.Explicit && !(this.body is null))
103 {
104 if (!(this.body.Imports is null))
105 {
106 foreach (Asn1Import Import in this.body.Imports)
107 {
108 if (string.IsNullOrEmpty(Import.Module))
109 continue;
110
111 Asn1Document ImportedDocument;
112
113 if (State.Settings.ContainsCode(Import.Module))
114 ImportedDocument = State.Settings.GetDocument(Import.Module);
115 else
116 {
117 ImportedDocument = await Import.LoadDocument();
118 string CSharp = ImportedDocument.ExportCSharp(State.Settings);
119 State.Settings.AddCode(Import.Module, CSharp, ImportedDocument);
120 }
121
122 Output.Append("using ");
123 Output.Append(State.Settings.Namespace(Import.Module));
124 Output.AppendLine(";");
125 }
126
127 Output.AppendLine();
128 }
129 else
130 Output.AppendLine();
131
132 Output.Append(Tabs(Indent));
133 Output.Append("namespace ");
134 Output.Append(State.Settings.BaseNamespace);
135 Output.Append('.');
136 Output.AppendLine(ToCSharp(this.identifier));
137 Output.Append(Tabs(Indent));
138 Output.AppendLine("{");
139 Indent++;
140
141 if (!(this.body.Imports is null))
142 {
143 foreach (Asn1Import Import in this.body.Imports)
144 {
145 if (string.IsNullOrEmpty(Import.Module))
146 continue;
147
148 Asn1Document ImportedDocument = State.Settings.GetDocument(Import.Module);
149 Asn1Node[] Nodes = ImportedDocument.Root?.Body?.Items;
150
151 if (!(Nodes is null))
152 {
153 foreach (Asn1Node Node in Nodes)
154 {
155 if (Node is Asn1TypeDefinition TypeDef &&
156 !TypeDef.ConstructedType &&
157 Array.IndexOf(Import.Identifiers, TypeDef.Name) >= 0)
158 {
159 await TypeDef.ExportCSharp(Output, State, Indent, CSharpExportPass.Preprocess);
160 }
161 }
162 }
163 }
164 }
165
166 await this.body.ExportCSharp(Output, State, Indent, CSharpExportPass.Preprocess);
167 State.ClosePending(Output);
168
169 await this.body.ExportCSharp(Output, State, Indent, CSharpExportPass.Variables);
170 State.ClosePending(Output);
171
172 await this.body.ExportCSharp(Output, State, Indent, CSharpExportPass.Explicit);
173 State.ClosePending(Output);
174
175 Indent--;
176 Output.Append(Tabs(Indent));
177 Output.AppendLine("}");
178 }
179 }
180 }
181}
Generic array.
Definition: Array.cs:12
Represents an ASN.1 document.
Definition: Asn1Document.cs:21
string ExportCSharp(CSharpExportSettings Settings)
Exports ASN.1 schemas to C#
Asn1Definitions Root
ASN.1 Root node
Definition: Asn1Document.cs:62
void AddCode(string Identifier, string Code, Asn1Document Document)
Adds C# code for a given identifier.
bool ContainsCode(string Identifier)
If C# code is available for a given identifier.
Asn1Document GetDocument(string Identifier)
Gets C# code for a given identifier.
string Namespace(string Identifier)
Namespace for a given identifier.
CSharpExportSettings Settings
C# export settings.
void ClosePending(StringBuilder Output)
Close pending actions
Represents a collection of ASN.1 definitions.
bool Abstract
If abstract syntax is used.
Asn1Definitions(string Identifier, Asn1Oid Oid, Asn1Tags? Tags, bool Abstract, Asn1Module Body, Asn1Document Document)
Represents a collection of ASN.1 definitions.
Asn1Document Document
ASN.1 document of which the definition is part.
Asn1Tags? Tags
How tags are handled.
override async Task ExportCSharp(StringBuilder Output, CSharpExportState State, int Indent, CSharpExportPass Pass)
Exports to C#
Represents one import instruction.
Definition: Asn1Import.cs:14
string[] Identifiers
Identifiers to import.
Definition: Asn1Import.cs:37
async Task< Asn1Document > LoadDocument()
Loads the ASN.1 document to import.
Definition: Asn1Import.cs:48
string Module
Module reference.
Definition: Asn1Import.cs:42
Represents an ASN.1 module.
Definition: Asn1Module.cs:12
Base class for all ASN.1 nodes.
Definition: Asn1Node.cs:38
Represents an ASN.1 Type definition.
virtual bool ConstructedType
If the type is a constructed type.
Definition: Asn1Type.cs:105
Represents an ASN.1 Object ID
Definition: Asn1Oid.cs:12
Asn1Tags
How ASN.1 tags are managed.
CSharpExportPass
Defines different C# export passes.
Definition: Asn1Node.cs:12