From 96280a7706dc21cf476edde040f9938f1b20edaf Mon Sep 17 00:00:00 2001 From: muhammed-abdulkadir Date: Tue, 26 May 2026 15:14:35 +0100 Subject: [PATCH] fix(csharp): emit required for non-optional arrays of scalar and enum types Signed-off-by: muhammed-abdulkadir --- lib/codegen/fromcto/csharp/csharpvisitor.js | 3 ++- test/codegen/fromcto/csharp/csharpvisitor.js | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/codegen/fromcto/csharp/csharpvisitor.js b/lib/codegen/fromcto/csharp/csharpvisitor.js index 3e2c857a..2180705f 100644 --- a/lib/codegen/fromcto/csharp/csharpvisitor.js +++ b/lib/codegen/fromcto/csharp/csharpvisitor.js @@ -637,11 +637,12 @@ class CSharpVisitor { if (!parameters.useRequiredForNonOptionalReferenceTypes) {return false;} if (options.nullableType) {return false;} if (options.hasDefault) {return false;} + if (options.isArray) {return true;} // Scalar aliases are generated as record structs (value types), not reference types. if (options.isScalarAlias) {return false;} if (options.isEnum) {return false;} if (!options.csharpType) {return false;} - return this.isCSharpReferenceType(options.csharpType, !!options.isArray); + return this.isCSharpReferenceType(options.csharpType, false); } /** diff --git a/test/codegen/fromcto/csharp/csharpvisitor.js b/test/codegen/fromcto/csharp/csharpvisitor.js index 8575918c..2a14af25 100644 --- a/test/codegen/fromcto/csharp/csharpvisitor.js +++ b/test/codegen/fromcto/csharp/csharpvisitor.js @@ -922,8 +922,10 @@ public class SampleModel : Concept { o Integer count o String nick optional o SSN ssn + o SSN[] ssns o Status status default="ACTIVE" o Status state + o Status[] states o Child child o Child[] children } @@ -935,8 +937,10 @@ public class SampleModel : Concept { file1.should.match(/public int count \{ get; set; \}/); file1.should.match(/public string\? nick \{ get; set; \}/); file1.should.match(/public SSN ssn \{ get; set; \}/); + file1.should.match(/public required SSN\[\] ssns \{ get; set; \}/); file1.should.match(/public Status status \{ get; set; \} = Status.Active;/); file1.should.match(/public Status state \{ get; set; \}/); + file1.should.match(/public required Status\[\] states \{ get; set; \}/); file1.should.match(/public required Child child \{ get; set; \}/); file1.should.match(/public required Child\[\] children \{ get; set; \}/); file1.should.not.match(/public required SSN ssn \{ get; set; \}/);