11using CppSharp . AST ;
22using CppSharp . Generators ;
3+ using CppSharp . Generators . C ;
4+ using CppSharp . Passes ;
35using CppSharp . Types ;
46using CppSharp . Utils ;
57
@@ -19,6 +21,42 @@ public override void CLIMarshalToManaged(MarshalContext ctx)
1921 }
2022 }
2123
24+ [ TypeMap ( "TestMappedTypeNonConstRefParam" ) ]
25+ public class TestMappedTypeNonConstRefParamTypeMap : TypeMap
26+ {
27+ public override Type CLISignatureType ( TypePrinterContext ctx )
28+ {
29+ return new CILType ( typeof ( string ) ) ;
30+ }
31+
32+ public override Type CppSignatureType ( TypePrinterContext ctx )
33+ {
34+ var tagType = ctx . Type as TagType ;
35+ var typePrinter = new CppTypePrinter ( Context ) ;
36+ return new CustomType ( tagType . Declaration . Visit ( typePrinter ) ) ;
37+ }
38+
39+ public override void CLIMarshalToManaged ( MarshalContext ctx )
40+ {
41+ ctx . Return . Write ( "clix::marshalString<clix::E_UTF8>({0}.m_str)" , ctx . ReturnVarName ) ;
42+ }
43+
44+ public override void CLIMarshalToNative ( MarshalContext ctx )
45+ {
46+ if ( ctx . Parameter . Usage == ParameterUsage . InOut )
47+ {
48+ ctx . Before . WriteLine ( $ "System::String^ _{ ctx . Parameter . Name } = { ctx . Parameter . Name } ;") ;
49+ }
50+
51+ string paramName = ctx . Parameter . Usage == ParameterUsage . InOut ? $ "_{ ctx . Parameter . Name } " : ctx . Parameter . Name ;
52+
53+ ctx . Before . WriteLine (
54+ $ "::TestMappedTypeNonConstRefParam _{ ctx . ArgName } = clix::marshalString<clix::E_UTF8>({ paramName } );") ;
55+
56+ ctx . Return . Write ( "_{0}" , ctx . ArgName ) ;
57+ }
58+ }
59+
2260 public class CLITestsGenerator : GeneratorTest
2361 {
2462 public CLITestsGenerator ( GeneratorKind kind )
@@ -33,6 +71,12 @@ public override void Setup(Driver driver)
3371 base . Setup ( driver ) ;
3472 }
3573
74+ public override void Preprocess ( Driver driver , ASTContext ctx )
75+ {
76+ LibraryHelpers . SetMethodParameterUsage ( ctx , "TestMappedTypeNonConstRefParamConsumer" ,
77+ "ChangePassedMappedTypeNonConstRefParam" , 1 , ParameterUsage . InOut ) ;
78+ }
79+
3680 public static void Main ( string [ ] args )
3781 {
3882 ConsoleDriver . Run ( new CLITestsGenerator ( GeneratorKind . CLI ) ) ;
0 commit comments