Forum Discussion

junyan2000's avatar
junyan2000
New Contributor
4 years ago

How NOT to use Dictionary in generated C# class

When I choose csharp-dotnet2 to generate C# classes on https://editor.swagger.io/,
Dictionary is used as type in the resulting class (see example below). Is there a way to not use Dictionary?

I need C# classes that can be serialized as XML, and Dictionary simply breaks it.

Here is the use case: I will use XSLT to construct an XML document, then deserialize it
into a Swagger object. then I will invoke api (using json).

"attributes": {
"type": "object",
"additionalProperties": {
"type": "object",
"additionalProperties": false
},
"description": "Any attributes associated with the item.",
"nullable": true
}

[DataMember(Name="attributes", EmitDefaultValue=false)]
[JsonProperty(PropertyName = "attributes")]
public Dictionary<string, Object> Attributes { get; set; }

1 Reply

  • junyan2000's avatar
    junyan2000
    New Contributor

    Also, enum appears to be broken. The generated class has no data member for an enum as below:

     

    "Product.Api.Models.Enums.ProductStatus": {
    "enum": [
    "inactive",
    "active"
    ],
    "type": "string"
    }