Skip to content

Commit fda728b

Browse files
dmealingclaude
andcommitted
refactor(#234): extract C# IsStrictNetField SSOT predicate (simplify-review)
Code-simplification review's one finding: EntityGenerator expressed the strict-net predicate twice (HasStrictNetField lambda + AppendNetConverterAttribute guard). Extracted a single IsStrictNetField(MetaField) helper, aligning C# with the Java/Kotlin ports that already factor it this way. Behavior-preserving — same logic, generated output byte-identical (C# Codegen.Tests 334, no fixture drift). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014xy8powhHYJ6gfFt9Ut8dL
1 parent 96401fe commit fda728b

1 file changed

Lines changed: 13 additions & 8 deletions

File tree

server/csharp/MetaObjects.Codegen/Generators/EntityGenerator.cs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -825,21 +825,26 @@ private string ApplyPropertyAttributes(string member, MetaObject owner, MetaFiel
825825
return member[..idx] + hook + member[idx..];
826826
}
827827

828-
// #234 — true iff the entity has a (single, non-array) STRICT field.uri / field.inet — the
829-
// fields carrying the generated [JsonConverter] + backing MetaNetValidation. A @lenient uri/inet
830-
// is a plain string with no converter, so it does not count.
831-
private static bool HasStrictNetField(MetaObject entity) =>
832-
entity.Fields().Any(f => !f.ResolvedIsArray()
833-
&& (f.SubType == FIELD_SUBTYPE_URI || f.SubType == FIELD_SUBTYPE_INET)
834-
&& !CSharpNaming.IsLenientNet(f));
828+
// #234 — true iff FIELD is a (single, non-array) STRICT field.uri / field.inet — the fields
829+
// carrying the generated [JsonConverter] + backing MetaNetValidation. A @lenient uri/inet is a
830+
// plain string with no converter, so it does not count. Single SSOT predicate for both the
831+
// per-entity emit gate and the per-property attribute guard (mirrors the Java/Kotlin ports'
832+
// own isStrictNetField).
833+
private static bool IsStrictNetField(MetaField field) =>
834+
!field.ResolvedIsArray()
835+
&& (field.SubType == FIELD_SUBTYPE_URI || field.SubType == FIELD_SUBTYPE_INET)
836+
&& !CSharpNaming.IsLenientNet(field);
837+
838+
// #234 — true iff the entity has any strict field.uri / field.inet (needs MetaNetValidation).
839+
private static bool HasStrictNetField(MetaObject entity) => entity.Fields().Any(IsStrictNetField);
835840

836841
// #234 — append the [JsonConverter(typeof(…))] binding a strict field.uri / field.inet property
837842
// to the same-namespace generated MetaNetValidation converter. No-op for a @lenient uri/inet
838843
// (a plain string) or any other field. An @isArray uri/inet (element-wise converter) is a
839844
// follow-up (no validation-conformance case).
840845
private static void AppendNetConverterAttribute(StringBuilder sb, MetaField field)
841846
{
842-
if (field.ResolvedIsArray() || CSharpNaming.IsLenientNet(field)) return;
847+
if (!IsStrictNetField(field)) return; // strict predicate guarantees a non-array uri/inet
843848
if (field.SubType == FIELD_SUBTYPE_URI)
844849
sb.AppendLine(" [JsonConverter(typeof(MetaNetValidation.AbsoluteUriJsonConverter))]");
845850
else if (field.SubType == FIELD_SUBTYPE_INET)

0 commit comments

Comments
 (0)