Skip to content

Commit a0da3b3

Browse files
committed
Simplify the generated C# for marshalling strings
Signed-off-by: Dimitar Dobrev <[email protected]>
1 parent 894799b commit a0da3b3

File tree

3 files changed

+2
-3
lines changed

3 files changed

+2
-3
lines changed

src/Generator/Generators/CSharp/CSharpTypePrinter.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public override TypePrinterResult VisitArrayType(ArrayType array,
129129
if (arrayType.IsPointerToPrimitiveType(PrimitiveType.Char))
130130
{
131131
var prefix = ContextKind == TypePrinterContextKind.Managed ? string.Empty :
132-
"[MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.LPStr)] ";
132+
"[MarshalAs(UnmanagedType.LPArray)] ";
133133
return $"{prefix}string[]";
134134
}
135135

src/Generator/Passes/DelegatesPass.cs

-1
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,6 @@ private static StringBuilder FormatTypesStringForIdentifier(StringBuilder types)
276276
{
277277
// TODO: all of this needs proper general fixing by only leaving type names
278278
return types.Replace("global::System.", string.Empty)
279-
.Replace("[MarshalAs(UnmanagedType.LPStr)] ", string.Empty)
280279
.Replace("[MarshalAs(UnmanagedType.LPWStr)] ", string.Empty)
281280
.Replace("global::", string.Empty).Replace("*", "Ptr")
282281
.Replace('.', '_').Replace(' ', '_').Replace("::", "_")

src/Generator/Types/Std/Stdlib.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ public override Type CSharpSignatureType(TypePrinterContext ctx)
155155
}
156156

157157
if (Context.Options.Encoding == Encoding.ASCII)
158-
return new CustomType("[MarshalAs(UnmanagedType.LPStr)] string");
158+
return new CustomType("string");
159159

160160
if (Context.Options.Encoding == Encoding.Unicode ||
161161
Context.Options.Encoding == Encoding.BigEndianUnicode)

0 commit comments

Comments
 (0)