From 434a188d7913670c238999075dc8f2eaea4ff084 Mon Sep 17 00:00:00 2001 From: Mingun Date: Sat, 6 Apr 2024 21:58:55 +0500 Subject: [PATCH] C#: add ability to generate full names of types, for test generator --- .../struct/languages/CSharpCompiler.scala | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/shared/src/main/scala/io/kaitai/struct/languages/CSharpCompiler.scala b/shared/src/main/scala/io/kaitai/struct/languages/CSharpCompiler.scala index b3570f1b6..d62d4fcc8 100644 --- a/shared/src/main/scala/io/kaitai/struct/languages/CSharpCompiler.scala +++ b/shared/src/main/scala/io/kaitai/struct/languages/CSharpCompiler.scala @@ -624,9 +624,11 @@ object CSharpCompiler extends LanguageCompilerStatic * Determine .NET data type corresponding to a KS data type. * * @param attrType KS data type + * @param absolute If `true` then the full name (with namespaces and enclosing types) + of the type will be generated. `true` is used in the test generator * @return .NET data type */ - def kaitaiType2NativeType(importList: ImportList, attrType: DataType): String = { + def kaitaiType2NativeType(importList: ImportList, attrType: DataType, absolute: Boolean = false): String = { attrType match { case Int1Type(false) => "byte" case IntMultiType(false, Width2, _) => "ushort" @@ -654,15 +656,25 @@ object CSharpCompiler extends LanguageCompilerStatic case KaitaiStructType | CalcKaitaiStructType(_) => kstructName case KaitaiStreamType | OwnedKaitaiStreamType => kstreamName - case t: UserType => types2class(t.name) - case EnumType(name, _) => types2class(name) + case t: UserType => + types2class(if (absolute) { + t.classSpec.get.name + } else { + t.name + }) + case t: EnumType => + types2class(if (absolute) { + t.enumSpec.get.name + } else { + t.name + }) case at: ArrayType => { importList.add("System.Collections.Generic") - s"List<${kaitaiType2NativeType(importList, at.elType)}>" + s"List<${kaitaiType2NativeType(importList, at.elType, absolute)}>" } - case st: SwitchType => kaitaiType2NativeType(importList, st.combinedType) + case st: SwitchType => kaitaiType2NativeType(importList, st.combinedType, absolute) } }