Skip to content

Commit de77ec1

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

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

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

+17-5
Original file line numberDiff line numberDiff line change
@@ -657,9 +657,11 @@ object CSharpCompiler extends LanguageCompilerStatic
657657
* Determine .NET data type corresponding to a KS data type.
658658
*
659659
* @param attrType KS data type
660+
* @param absolute If `true` then the full name (with namespaces and enclosing types)
661+
of the type will be generated. `true` is used in the test generator
660662
* @return .NET data type
661663
*/
662-
def kaitaiType2NativeType(importList: ImportList, attrType: DataType): String = {
664+
def kaitaiType2NativeType(importList: ImportList, attrType: DataType, absolute: Boolean = false): String = {
663665
attrType match {
664666
case Int1Type(false) => "byte"
665667
case IntMultiType(false, Width2, _) => "ushort"
@@ -687,15 +689,25 @@ object CSharpCompiler extends LanguageCompilerStatic
687689
case KaitaiStructType | CalcKaitaiStructType(_) => kstructName
688690
case KaitaiStreamType | OwnedKaitaiStreamType => kstreamName
689691

690-
case t: UserType => types2class(t.name)
691-
case EnumType(name, _) => types2class(name)
692+
case t: UserType =>
693+
types2class(if (absolute) {
694+
t.classSpec.get.name
695+
} else {
696+
t.name
697+
})
698+
case t: EnumType =>
699+
types2class(if (absolute) {
700+
t.enumSpec.get.name
701+
} else {
702+
t.name
703+
})
692704

693705
case at: ArrayType => {
694706
importList.add("System.Collections.Generic")
695-
s"List<${kaitaiType2NativeType(importList, at.elType)}>"
707+
s"List<${kaitaiType2NativeType(importList, at.elType, absolute)}>"
696708
}
697709

698-
case st: SwitchType => kaitaiType2NativeType(importList, st.combinedType)
710+
case st: SwitchType => kaitaiType2NativeType(importList, st.combinedType, absolute)
699711
}
700712
}
701713

0 commit comments

Comments
 (0)