@@ -55,7 +55,13 @@ fn ty_fmt<'a>(ctx: &'a GenCtx, ty: &'a AlgebraicType, namespace: &'a str) -> imp
55
55
}
56
56
// Arbitrary product types should fail.
57
57
AlgebraicType :: Product ( _) => unimplemented ! ( ) ,
58
- AlgebraicType :: Array ( ArrayType { elem_ty } ) => write ! ( f, "{}[]" , ty_fmt( ctx, elem_ty, namespace) ) ,
58
+ AlgebraicType :: Array ( ArrayType { elem_ty } ) => {
59
+ write ! (
60
+ f,
61
+ "System.Collections.Generic.List<{}>" ,
62
+ ty_fmt( ctx, elem_ty, namespace)
63
+ )
64
+ }
59
65
AlgebraicType :: Ref ( r) => {
60
66
let name = csharp_typename ( ctx, * r) ;
61
67
match & ctx. typespace [ * r] {
@@ -82,18 +88,17 @@ fn ty_fmt<'a>(ctx: &'a GenCtx, ty: &'a AlgebraicType, namespace: &'a str) -> imp
82
88
} )
83
89
}
84
90
85
- fn default_init ( ctx : & GenCtx , ty : & AlgebraicType , namespace : & str ) -> Option < String > {
91
+ fn default_init ( ctx : & GenCtx , ty : & AlgebraicType ) -> Option < & ' static str > {
86
92
match ty {
87
93
// Options have a default value of null which is fine for us, and simple enums have their own default.
88
94
AlgebraicType :: Sum ( sum_type) if sum_type. is_option ( ) || sum_type. is_simple_enum ( ) => None ,
89
95
// TODO: generate some proper default here (what would it be for tagged enums?).
90
- AlgebraicType :: Sum ( _) => Some ( "null!" . into ( ) ) ,
91
- AlgebraicType :: Array ( arr_ty) => Some ( format ! ( "Array.Empty<{}>()" , ty_fmt( ctx, & arr_ty. elem_ty, namespace) ) ) ,
92
- // For product types, we can use the default constructor.
93
- AlgebraicType :: Product ( _) => Some ( "new()" . into ( ) ) ,
96
+ AlgebraicType :: Sum ( _) => Some ( "null!" ) ,
97
+ // For product types and arrays, we can use the default constructor.
98
+ AlgebraicType :: Product ( _) | AlgebraicType :: Array ( _) => Some ( "new()" ) ,
94
99
// Strings must have explicit default value of "".
95
- AlgebraicType :: String => Some ( r#""""# . into ( ) ) ,
96
- AlgebraicType :: Ref ( r) => default_init ( ctx, & ctx. typespace [ * r] , namespace ) ,
100
+ AlgebraicType :: String => Some ( r#""""# ) ,
101
+ AlgebraicType :: Ref ( r) => default_init ( ctx, & ctx. typespace [ * r] ) ,
97
102
_ => {
98
103
debug_assert ! ( ty. is_scalar( ) ) ;
99
104
None
@@ -342,7 +347,7 @@ fn autogen_csharp_product_table_common(
342
347
writeln ! ( output, "public {name}()" ) ;
343
348
indented_block ( output, |output| {
344
349
for ( ( field_name, _ty) , field) in fields. iter ( ) . zip ( & * product_type. elements ) {
345
- if let Some ( default) = default_init ( ctx, & field. algebraic_type , namespace ) {
350
+ if let Some ( default) = default_init ( ctx, & field. algebraic_type ) {
346
351
writeln ! ( output, "this.{field_name} = {default};" ) ;
347
352
}
348
353
}
@@ -524,7 +529,7 @@ pub fn autogen_csharp_reducer(ctx: &GenCtx, reducer: &ReducerDef, namespace: &st
524
529
525
530
write ! ( output, "public {arg_type_str} {field_name}" ) ;
526
531
// Skip default initializer if it's the same as the implicit default.
527
- if let Some ( default) = default_init ( ctx, & arg. algebraic_type , namespace ) {
532
+ if let Some ( default) = default_init ( ctx, & arg. algebraic_type ) {
528
533
write ! ( output, " = {default}" ) ;
529
534
}
530
535
writeln ! ( output, ";" ) ;
0 commit comments