1- using System ;
1+ using System ;
22using System . CodeDom . Compiler ;
33using System . Collections . Generic ;
44using System . Diagnostics . Contracts ;
@@ -32,8 +32,12 @@ public class CSharpCodeGenerator : ICodeGenerator
3232 [ typeof ( Utf16TextPtrNode ) ] = "IntPtr" ,
3333 [ typeof ( Utf32TextPtrNode ) ] = "IntPtr" ,
3434 [ typeof ( PointerNode ) ] = "IntPtr" ,
35- [ typeof ( VirtualMethodTableNode ) ] = "IntPtr"
36- } ;
35+ [ typeof ( VirtualMethodTableNode ) ] = "IntPtr" ,
36+
37+ [ typeof ( Vector2Node ) ] = "Vector2" ,
38+ [ typeof ( Vector3Node ) ] = "Vector3" ,
39+ [ typeof ( Vector4Node ) ] = "Vector4"
40+ } ;
3741
3842 public Language Language => Language . CSharp ;
3943
@@ -48,6 +52,9 @@ public string GenerateCode(IReadOnlyList<ClassNode> classes, IReadOnlyList<EnumD
4852 iw . WriteLine ( "// Warning: The C# code generator doesn't support all node types!" ) ;
4953 iw . WriteLine ( ) ;
5054 iw . WriteLine ( "using System.Runtime.InteropServices;" ) ;
55+
56+ iw . WriteLine ( "// optional namespace, only for vectors" ) ;
57+ iw . WriteLine ( "using System.Numerics;" ) ;
5158 iw . WriteLine ( ) ;
5259
5360 using ( var en = enums . GetEnumerator ( ) )
@@ -149,7 +156,7 @@ private static void WriteClass(IndentedTextWriter writer, ClassNode @class, ILog
149156 Contract . Requires ( logger != null ) ;
150157
151158 writer . WriteLine ( "[StructLayout(LayoutKind.Explicit)]" ) ;
152- writer . Write ( "class " ) ;
159+ writer . Write ( "public struct " ) ;
153160 writer . Write ( @class . Name ) ;
154161
155162 if ( ! string . IsNullOrEmpty ( @class . Comment ) )
@@ -170,16 +177,7 @@ private static void WriteClass(IndentedTextWriter writer, ClassNode @class, ILog
170177 var type = GetTypeDefinition ( node ) ;
171178 if ( type != null )
172179 {
173- writer . Write ( "[FieldOffset(" ) ;
174- writer . Write ( node . Offset ) ;
175- writer . WriteLine ( ")]" ) ;
176-
177- writer . Write ( "public " ) ;
178- writer . Write ( type ) ;
179- writer . Write ( " " ) ;
180- writer . Write ( node . Name ) ;
181- writer . Write ( "; //0x" ) ;
182- writer . Write ( $ "{ node . Offset : X04} ") ;
180+ writer . Write ( $ "[FieldOffset(0x{ node . Offset : X} )] public readonly { type } { node . Name } ;") ;
183181 if ( ! string . IsNullOrEmpty ( node . Comment ) )
184182 {
185183 writer . Write ( " " ) ;
0 commit comments