Skip to content

Commit cbaca9d

Browse files
committed
C#: add ability to generate full names of types, for test generator
1 parent fd25942 commit cbaca9d

1 file changed

Lines changed: 17 additions & 5 deletions

File tree

shared/src/main/scala/io/kaitai/struct/languages/CSharpCompiler.scala

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -677,9 +677,11 @@ object CSharpCompiler extends LanguageCompilerStatic
677677
* Determine .NET data type corresponding to a KS data type.
678678
*
679679
* @param attrType KS data type
680+
* @param absolute If `true` then the full name (with namespaces and enclosing types)
681+
of the type will be generated. `true` is used in the test generator
680682
* @return .NET data type
681683
*/
682-
def kaitaiType2NativeType(importList: ImportList, attrType: DataType): String = {
684+
def kaitaiType2NativeType(importList: ImportList, attrType: DataType, absolute: Boolean = false): String = {
683685
attrType match {
684686
case Int1Type(false) => "byte"
685687
case IntMultiType(false, Width2, _) => "ushort"
@@ -707,15 +709,25 @@ object CSharpCompiler extends LanguageCompilerStatic
707709
case KaitaiStructType | CalcKaitaiStructType(_) => kstructName
708710
case KaitaiStreamType | OwnedKaitaiStreamType => kstreamName
709711

710-
case t: UserType => types2class(t.name)
711-
case EnumType(name, owner, _) => types2class(owner :+ name)
712+
case t: UserType =>
713+
types2class(if (absolute) {
714+
t.classSpec.get.name
715+
} else {
716+
t.name
717+
})
718+
case t: EnumType =>
719+
types2class(if (absolute) {
720+
t.enumSpec.get.name
721+
} else {
722+
t.owner :+ t.name
723+
})
712724

713725
case at: ArrayType => {
714726
importList.add("System.Collections.Generic")
715-
s"List<${kaitaiType2NativeType(importList, at.elType)}>"
727+
s"List<${kaitaiType2NativeType(importList, at.elType, absolute)}>"
716728
}
717729

718-
case st: SwitchType => kaitaiType2NativeType(importList, st.combinedType)
730+
case st: SwitchType => kaitaiType2NativeType(importList, st.combinedType, absolute)
719731
}
720732
}
721733

0 commit comments

Comments
 (0)