@@ -441,11 +441,22 @@ impl WorldGenerator for CSharp {
441
441
files. push ( & format ! ( "{name}.cs" ) , indent ( & src) . as_bytes ( ) ) ;
442
442
443
443
let generate_stub =
444
- |name : String , files : & mut Files , fragments : & Vec < InterfaceFragment > | {
444
+ |name : String , files : & mut Files , stubs : Stubs | {
445
445
let stub_file_name = format ! ( "{name}Impl" ) ;
446
446
let interface_name = CSharp :: get_class_name_from_qualified_name ( name. clone ( ) ) ;
447
447
let stub_class_name = format ! ( "{interface_name}Impl" ) ;
448
448
449
+ let ( fragments, fully_qaulified_namespace) = match stubs {
450
+ Stubs :: World ( fragments) => {
451
+ let fully_qaulified_namespace = format ! ( "{namespace}" ) ;
452
+ ( fragments, fully_qaulified_namespace)
453
+ } ,
454
+ Stubs :: Interface ( fragments) => {
455
+ let fully_qaulified_namespace = format ! ( "{namespace}.{name}" ) ;
456
+ ( fragments, fully_qaulified_namespace)
457
+ } ,
458
+ } ;
459
+
449
460
let body = fragments
450
461
. iter ( )
451
462
. map ( |f| f. stub . deref ( ) )
@@ -456,7 +467,7 @@ impl WorldGenerator for CSharp {
456
467
"// Generated by `wit-bindgen` {version}. DO NOT EDIT!
457
468
{CSHARP_IMPORTS}
458
469
459
- namespace {namespace}.{name };
470
+ namespace {fully_qaulified_namespace };
460
471
461
472
public partial class {stub_class_name} : {interface_name} {{
462
473
{body}
@@ -467,10 +478,9 @@ impl WorldGenerator for CSharp {
467
478
files. push ( & format ! ( "{stub_file_name}.cs" ) , indent ( & body) . as_bytes ( ) ) ;
468
479
} ;
469
480
470
- // TODO: is the world Impl class useful?
471
- // if self.opts.generate_stub {
472
- // generate_stub(format!("{name}"), files);
473
- // }
481
+ if self . opts . generate_stub {
482
+ generate_stub ( format ! ( "{name}World" ) , files, Stubs :: World ( & self . world_fragments ) ) ;
483
+ }
474
484
475
485
files. push (
476
486
& format ! ( "{snake}_component_type.o" , ) ,
@@ -529,7 +539,7 @@ impl WorldGenerator for CSharp {
529
539
files. push ( & format ! ( "{name}Interop.cs" ) , indent ( & body) . as_bytes ( ) ) ;
530
540
531
541
if interface_type_and_fragments. is_export && self . opts . generate_stub {
532
- generate_stub ( format ! ( "{name}" ) , files, fragments) ;
542
+ generate_stub ( format ! ( "{name}" ) , files, Stubs :: Interface ( fragments) ) ;
533
543
}
534
544
}
535
545
}
@@ -1259,6 +1269,11 @@ impl<'a> wit_bindgen_core::InterfaceGenerator<'a> for InterfaceGenerator<'a> {
1259
1269
}
1260
1270
}
1261
1271
1272
+ enum Stubs < ' a > {
1273
+ World ( & ' a Vec < InterfaceFragment > ) ,
1274
+ Interface ( & ' a Vec < InterfaceFragment > )
1275
+ }
1276
+
1262
1277
struct Block {
1263
1278
_body : String ,
1264
1279
_results : Vec < String > ,
0 commit comments