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