Skip to content

[REQ][CSHARP] Implicit casts on Option<> types break when contained type in an interface, allow explicit .Value #21476

Open
@EraYaN

Description

@EraYaN

Is your feature request related to a problem? Please describe.

When using a type-mapping for the lists and array to IEnumerable or ICollection, the option implicit cast does not work. Using command line argument --type-mapping=list=IEnumerable,array=IEnumerable

Describe the solution you'd like

Something like in modelGeneric.mustache because implicit casts are not allowed if the type is an interface.

-public {{{datatypeWithEnum}}}{{#lambda.first}}{{#isNullable}}{{>NullConditionalProperty}}  {{/isNullable}}{{^required}}{{nrt?}}{{^nrt}}{{#vendorExtensions.x-is-value-type}}?{{/vendorExtensions.x-is-value-type}}{{/nrt}}  {{/required}}{{/lambda.first}} {{#lambda.titlecase}}{{baseType}}{{/lambda.titlecase}} {{#required}}{ get; {{^isReadOnly}}set; {{/isReadOnly}}}{{/required}}{{^required}}{ get { return this.{{#lambda.titlecase}}{{name}}{{/lambda.titlecase}}Option; } {{^isReadOnly}}set { this.{{#lambda.titlecase}}{{name}}{{/lambda.titlecase}}Option = new{{^net70OrLater}} Option<{{{datatypeWithEnum}}}{{>NullConditionalProperty}}>{{/net70OrLater}}(value); } {{/isReadOnly}}}{{/required}}
+public {{{datatypeWithEnum}}}{{#lambda.first}}{{#isNullable}}{{>NullConditionalProperty}}  {{/isNullable}}{{^required}}{{nrt?}}{{^nrt}}{{#vendorExtensions.x-is-value-type}}?{{/vendorExtensions.x-is-value-type}}{{/nrt}}  {{/required}}{{/lambda.first}} {{#lambda.titlecase}}{{baseType}}{{/lambda.titlecase}} {{#required}}{ get; {{^isReadOnly}}set; {{/isReadOnly}}}{{/required}}{{^required}}{ get { return this.{{#lambda.titlecase}}{{name}}{{/lambda.titlecase}}Option.Value; } {{^isReadOnly}}set { this.{{#lambda.titlecase}}{{name}}{{/lambda.titlecase}}Option = new{{^net70OrLater}} Option<{{{datatypeWithEnum}}}{{>NullConditionalProperty}}>{{/net70OrLater}}(value); } {{/isReadOnly}}}{{/required}}

Describe alternatives you've considered

I can of course duplicate the modelGeneric.template, but this is quite a large template, I'd rather not maintain that and keep it check with new versions.
The other solution it to add some extra configuration to also support interface type collections. Although relying on implicit casts in general for the option types is probably not a good idea in general.

Additional context

Collection is a type that is hard to use because it's sort of separate to all the other Collections. ICollection would be better honestly. We would like to use IEnumerable since mapping those to other collections in auto-generated mapper code is much easier.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions