@@ -49,7 +49,7 @@ static void GenerateImport (this INativeCallable callable, IGeneratable parent,
49
49
{
50
50
var retType = GetReturnCSharpType ( callable , writer ) ;
51
51
52
- var ( typesAndNames , names ) = BuildParameters ( callable , writer . Options , appendInstanceParameters : true ) ;
52
+ var parameters = BuildParameters ( callable , writer . Options , appendInstanceParameters : true ) ;
53
53
54
54
// TODO: Better than using the constant string, insert a custom generatable which contains the import string as a constant.
55
55
/* i.e.
@@ -59,7 +59,7 @@ static class <LibraryName>Constants
59
59
}
60
60
*/
61
61
//writer.WriteLine ($"[DllImport (\"{writer.Options.LibraryName}\", CallingConvention=CallingConvention.Cdecl)]");
62
- writer . WriteLine ( $ "static extern { retType } { callable . CIdentifier } ({ typesAndNames } );") ;
62
+ writer . WriteLine ( $ "static extern { retType } { callable . CIdentifier } ({ parameters . MarshalTypesAndNames } );") ;
63
63
writer . WriteLine ( ) ;
64
64
}
65
65
@@ -87,8 +87,8 @@ public static void GenerateCallableDefinition (this INativeCallable callable, IG
87
87
var returnType = callable . GetReturnCSharpType ( writer ) ;
88
88
89
89
// generate ReturnValue then Parameters
90
- var ( typesAndNames , names ) = BuildParameters ( callable , writer . Options , ! callable . IsInstanceCallable ( gen , writer . Options ) ) ;
91
- writer . Write ( string . Format ( "{0} {1} ({2});" , returnType , callable . Name . ToCSharp ( ) , typesAndNames ) ) ;
90
+ var result = BuildParameters ( callable , writer . Options , ! callable . IsInstanceCallable ( gen , writer . Options ) ) ;
91
+ writer . Write ( string . Format ( "{0} {1} ({2});" , returnType , callable . Name . ToCSharp ( ) , result . TypesAndNames ) ) ;
92
92
writer . WriteLine ( ) ;
93
93
}
94
94
@@ -98,17 +98,18 @@ public static void GenerateConstructor (this INativeCallable callable, IGenerata
98
98
99
99
var modifier = callable . GetModifiers ( parent , writer . Options ) ;
100
100
101
- var ( typesAndNames , names ) = BuildParameters ( callable , writer . Options , ! callable . IsInstanceCallable ( parent , writer . Options ) ) ;
101
+ var result = BuildParameters ( callable , writer . Options , ! callable . IsInstanceCallable ( parent , writer . Options ) ) ;
102
102
103
103
// FIXME, should check to see if it is deprecated
104
- writer . WriteLine ( $ "{ modifier } { parent . Name } ({ typesAndNames } ) : base ({ names } )") ;
104
+ writer . WriteLine ( $ "{ modifier } { parent . Name } ({ result . TypesAndNames } ) : base ({ result . Names } )") ;
105
105
writer . WriteLine ( "{" ) ;
106
106
writer . WriteLine ( "}" ) ;
107
107
}
108
108
109
- public static ( string both , string names ) BuildParameters ( this IMethodLike callable , GenerationOptions opts , bool appendInstanceParameters )
109
+ public static BuildParametersResult BuildParameters ( this IMethodLike callable , GenerationOptions opts , bool appendInstanceParameters )
110
110
{
111
111
var parameters = callable . Parameters ;
112
+ var marshalTypeAndName = new List < string > ( parameters . Count ) ;
112
113
var typeAndName = new List < string > ( parameters . Count ) ;
113
114
var parameterNames = new List < string > ( parameters . Count ) ;
114
115
@@ -124,20 +125,36 @@ public static (string both, string names) BuildParameters (this IMethodLike call
124
125
}
125
126
126
127
var symbol = parameter . Resolve ( opts ) ;
127
- typeAndName . Add ( symbol . CSharpType + " " + parameter . Name ) ;
128
+ marshalTypeAndName . Add ( symbol . CSharpType + " " + parameter . Name ) ;
129
+ typeAndName . Add ( symbol . CSharpType + ( parameter . Array != null ? "[]" : "" ) + " " + parameter . Name ) ;
128
130
parameterNames . Add ( parameter . Name ) ;
129
131
}
130
132
131
133
// PERF: Use an array as the string[] overload of Join is way more efficient than the IEnumerable<string> one.
134
+ string marshalParameterString = string . Join ( ", " , marshalTypeAndName . ToArray ( ) ) ;
132
135
string parameterString = string . Join ( ", " , typeAndName . ToArray ( ) ) ;
133
136
string baseParams = string . Join ( ", " , parameterNames . ToArray ( ) ) ;
134
137
135
- return ( parameterString , baseParams ) ;
138
+ return new BuildParametersResult ( marshalParameterString , parameterString , baseParams ) ;
136
139
}
137
140
138
141
static IEnumerable < IMemberGeneratable > GetMemberGeneratables ( this IGeneratable gen )
139
142
{
140
143
return Utils . GetAllCollectionMembers < IMemberGeneratable > ( gen ) ;
141
144
}
142
145
}
146
+
147
+ public class BuildParametersResult
148
+ {
149
+ public string MarshalTypesAndNames { get ; }
150
+ public string TypesAndNames { get ; }
151
+ public string Names { get ; }
152
+
153
+ public BuildParametersResult ( string marshalTypesAndNames , string typesAndNames , string names )
154
+ {
155
+ MarshalTypesAndNames = marshalTypesAndNames ;
156
+ TypesAndNames = typesAndNames ;
157
+ Names = names ;
158
+ }
159
+ }
143
160
}
0 commit comments