1

I have an Action method that returns an object derived from the class 'List':

class Derived<T> : List<T>
{
    public int AdditionalProperty { get; set; }
}

and then:

[HttpGet]
public Derived<string> MyActionMethod()
{
    var results = new Derived<string> { AdditionalProperty = 123 };
    results.Add("ABCD");
    results.Add("EFGH");
    return results;
}

When I call the action method (I use swagger to test), I have only the List returned, not the Derived class. Here is the result:

[
    "ABCD",
    "EFGH"
]

The desired result would have the AdditionalProperty included in the serialization.

I really would like to understand why is that happening. And How can I make the action method return the Derived class?

Abdelhakim
  • 815
  • 1
  • 5
  • 19

0 Answers0