Summary
When a field.enum field is declared on an object.value (owned value object / JSON POCO), the C# EntityGenerator emits string instead of the enum's C# type, even when the enum is declared as @provided with a mapped C# namespace via GenConfig.PackageNamespaces.
The same field.enum declaration on an object.entity correctly emits the resolved enum type (e.g. Perspective3.Core.DataEnums.ContactMethod?). The gap is specific to value object POCOs.
Reproduction
Given a @provided abstract enum in metadata:
- field.enum:
name: ContactMethod
abstract: true
"@provided": true
"@values": [Phone, Email, Fax]
And a value object using it:
- object.value:
name: ContactInfo
children:
- field.enum:
name: contactMethod
"@required": true
extends: p3::common::ContactMethod
With GenConfig.PackageNamespaces["p3::common"] = "Acme.DataEnums" wired in Program.cs.
Expected ContactInfo.g.cs:
public ContactMethod ContactMethod { get; set; }
Actual ContactInfo.g.cs:
public string ContactMethod { get; set; } = default!;
Impact
All consumers of the value object must use nameof(ContactMethod.Phone) string comparisons instead of clean enum comparisons. This defeats the purpose of field.enum on the metadata and forces hand-maintained string literals throughout the codebase.
The same pattern works correctly for object.entity fields — EmitValueObjectPoco appears to not participate in the enum-type resolution that EmitMappedClass does.
Workaround
Post-processing the emitted file in a subclassed EntityGenerator (via EmitValueObjectPoco override or Generate() file-level post-processing). Works but is a subclassing burden that the framework should handle.
Version
MetaObjects.Codegen 0.16.0 (NuGet), C# port.
Summary
When a
field.enumfield is declared on anobject.value(owned value object / JSON POCO), the C# EntityGenerator emitsstringinstead of the enum's C# type, even when the enum is declared as@providedwith a mapped C# namespace viaGenConfig.PackageNamespaces.The same
field.enumdeclaration on anobject.entitycorrectly emits the resolved enum type (e.g.Perspective3.Core.DataEnums.ContactMethod?). The gap is specific to value object POCOs.Reproduction
Given a
@providedabstract enum in metadata:And a value object using it:
With
GenConfig.PackageNamespaces["p3::common"] = "Acme.DataEnums"wired inProgram.cs.Expected
ContactInfo.g.cs:Actual
ContactInfo.g.cs:Impact
All consumers of the value object must use
nameof(ContactMethod.Phone)string comparisons instead of clean enum comparisons. This defeats the purpose offield.enumon the metadata and forces hand-maintained string literals throughout the codebase.The same pattern works correctly for
object.entityfields —EmitValueObjectPocoappears to not participate in the enum-type resolution thatEmitMappedClassdoes.Workaround
Post-processing the emitted file in a subclassed
EntityGenerator(viaEmitValueObjectPocooverride orGenerate()file-level post-processing). Works but is a subclassing burden that the framework should handle.Version
MetaObjects.Codegen 0.16.0 (NuGet), C# port.