@@ -16,18 +16,46 @@ public class VaList : TypeMap
1616 public override bool IsIgnored => true ;
1717 }
1818
19+ [ TypeMap ( "int" , GeneratorKind = GeneratorKind . CSharp ) ]
20+ public class Int : TypeMap
21+ {
22+ public override Type CSharpSignatureType ( TypePrinterContext ctx ) =>
23+ CSharpTypePrinter . GetSignedType ( Context . TargetInfo . IntWidth ) ;
24+ }
25+
26+ [ TypeMap ( "unsigned int" , GeneratorKind = GeneratorKind . CSharp ) ]
27+ public class UnsignedInt : TypeMap
28+ {
29+ public override Type CSharpSignatureType ( TypePrinterContext ctx ) =>
30+ CSharpTypePrinter . GetUnsignedType ( Context . TargetInfo . IntWidth ) ;
31+ }
32+
33+ [ TypeMap ( "long" , GeneratorKind = GeneratorKind . CSharp ) ]
34+ public class Long : TypeMap
35+ {
36+ public override Type CSharpSignatureType ( TypePrinterContext ctx ) =>
37+ CSharpTypePrinter . GetSignedType ( Context . TargetInfo . LongWidth ) ;
38+ }
39+
40+ [ TypeMap ( "unsigned long" , GeneratorKind = GeneratorKind . CSharp ) ]
41+ public class UnsignedLong : TypeMap
42+ {
43+ public override Type CSharpSignatureType ( TypePrinterContext ctx ) =>
44+ CSharpTypePrinter . GetUnsignedType ( Context . TargetInfo . LongWidth ) ;
45+ }
46+
1947 [ TypeMap ( "char" , GeneratorKind = GeneratorKind . CSharp ) ]
2048 public class Char : TypeMap
2149 {
2250 public override Type CSharpSignatureType ( TypePrinterContext ctx )
2351 {
2452 return new CILType ( ctx . Kind == TypePrinterContextKind . Native ||
25- ! Options . MarshalCharAsManagedChar ? typeof ( sbyte ) : typeof ( char ) ) ;
53+ ! Context . Options . MarshalCharAsManagedChar ? typeof ( sbyte ) : typeof ( char ) ) ;
2654 }
2755
2856 public override void CSharpMarshalToNative ( CSharpMarshalContext ctx )
2957 {
30- if ( Options . MarshalCharAsManagedChar )
58+ if ( Context . Options . MarshalCharAsManagedChar )
3159 ctx . Return . Write ( "global::System.Convert.ToSByte({0})" ,
3260 ctx . Parameter . Name ) ;
3361 else
@@ -36,7 +64,7 @@ public override void CSharpMarshalToNative(CSharpMarshalContext ctx)
3664
3765 public override void CSharpMarshalToManaged ( CSharpMarshalContext ctx )
3866 {
39- if ( Options . MarshalCharAsManagedChar )
67+ if ( Context . Options . MarshalCharAsManagedChar )
4068 ctx . Return . Write ( "global::System.Convert.ToChar({0})" ,
4169 ctx . ReturnVarName ) ;
4270 else
@@ -51,16 +79,6 @@ public override Type CSharpSignatureType(TypePrinterContext ctx)
5179 {
5280 return new CILType ( typeof ( char ) ) ;
5381 }
54-
55- public override void CSharpMarshalToNative ( CSharpMarshalContext ctx )
56- {
57- ctx . Return . Write ( ctx . Parameter . Name ) ;
58- }
59-
60- public override void CSharpMarshalToManaged ( CSharpMarshalContext ctx )
61- {
62- ctx . Return . Write ( ctx . ReturnVarName ) ;
63- }
6482 }
6583
6684 [ TypeMap ( "wchar_t" , GeneratorKind = GeneratorKind . CSharp ) ]
@@ -70,16 +88,6 @@ public override Type CSharpSignatureType(TypePrinterContext ctx)
7088 {
7189 return new CILType ( typeof ( char ) ) ;
7290 }
73-
74- public override void CSharpMarshalToNative ( CSharpMarshalContext ctx )
75- {
76- ctx . Return . Write ( ctx . Parameter . Name ) ;
77- }
78-
79- public override void CSharpMarshalToManaged ( CSharpMarshalContext ctx )
80- {
81- ctx . Return . Write ( ctx . ReturnVarName ) ;
82- }
8391 }
8492
8593 [ TypeMap ( "const char*" , GeneratorKind = GeneratorKind . CSharp ) ]
@@ -92,13 +100,13 @@ public override Type CSharpSignatureType(TypePrinterContext ctx)
92100
93101 if ( ctx . Parameter == null || ctx . Parameter . Name == Helpers . ReturnIdentifier )
94102 return new CustomType ( CSharpTypePrinter . IntPtrType ) ;
95- if ( Options . Encoding == Encoding . ASCII )
103+ if ( Context . Options . Encoding == Encoding . ASCII )
96104 return new CustomType ( "[MarshalAs(UnmanagedType.LPStr)] string" ) ;
97- if ( Options . Encoding == Encoding . Unicode ||
98- Options . Encoding == Encoding . BigEndianUnicode )
105+ if ( Context . Options . Encoding == Encoding . Unicode ||
106+ Context . Options . Encoding == Encoding . BigEndianUnicode )
99107 return new CustomType ( "[MarshalAs(UnmanagedType.LPWStr)] string" ) ;
100108 throw new System . NotSupportedException (
101- $ "{ Options . Encoding . EncodingName } is not supported yet.") ;
109+ $ "{ Context . Options . Encoding . EncodingName } is not supported yet.") ;
102110 }
103111
104112 public override void CSharpMarshalToNative ( CSharpMarshalContext ctx )
@@ -111,19 +119,19 @@ public override void CSharpMarshalToNative(CSharpMarshalContext ctx)
111119 ctx . Return . Write ( ctx . Parameter . Name ) ;
112120 return ;
113121 }
114- if ( Equals ( Options . Encoding , Encoding . ASCII ) )
122+ if ( Equals ( Context . Options . Encoding , Encoding . ASCII ) )
115123 {
116124 ctx . Return . Write ( $ "Marshal.StringToHGlobalAnsi({ ctx . Parameter . Name } )") ;
117125 return ;
118126 }
119- if ( Equals ( Options . Encoding , Encoding . Unicode ) ||
120- Equals ( Options . Encoding , Encoding . BigEndianUnicode ) )
127+ if ( Equals ( Context . Options . Encoding , Encoding . Unicode ) ||
128+ Equals ( Context . Options . Encoding , Encoding . BigEndianUnicode ) )
121129 {
122130 ctx . Return . Write ( $ "Marshal.StringToHGlobalUni({ ctx . Parameter . Name } )") ;
123131 return ;
124132 }
125133 throw new System . NotSupportedException (
126- $ "{ Options . Encoding . EncodingName } is not supported yet.") ;
134+ $ "{ Context . Options . Encoding . EncodingName } is not supported yet.") ;
127135 }
128136
129137 public override void CSharpMarshalToManaged ( CSharpMarshalContext ctx )
@@ -144,7 +152,7 @@ public override void CSharpMarshalToManaged(CSharpMarshalContext ctx)
144152 var encoding = isChar ? Encoding . ASCII : Encoding . Unicode ;
145153
146154 if ( Equals ( encoding , Encoding . ASCII ) )
147- encoding = Options . Encoding ;
155+ encoding = Context . Options . Encoding ;
148156
149157 if ( Equals ( encoding , Encoding . ASCII ) )
150158 {
@@ -579,15 +587,5 @@ public override Type CSharpSignatureType(TypePrinterContext ctx)
579587 {
580588 return new CILType ( typeof ( System . IntPtr ) ) ;
581589 }
582-
583- public override void CSharpMarshalToNative ( CSharpMarshalContext ctx )
584- {
585- ctx . Return . Write ( ctx . Parameter . Name ) ;
586- }
587-
588- public override void CSharpMarshalToManaged ( CSharpMarshalContext ctx )
589- {
590- ctx . Return . Write ( ctx . ReturnVarName ) ;
591- }
592590 }
593591}
0 commit comments