Skip to content

C# EntityGenerator: field.enum on object.value POCOs generates string instead of enum type #205

Description

@dmealing

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions