simple-odata-client / Simple.OData.Client

MIT License
330 stars 196 forks source link

Automatic Subtype Expansion #575

Open phatcher opened 5 years ago

phatcher commented 5 years ago

At the moment if you have a type hierarchy you have to use a custom converter to correctly populate the subtypes, since the ToObject does not use the ODataEntryAnnotations.TypeName to select the correct CLR type, just taking the provided value. For example, given the class hierarchy

public class Animal 
{
    public Id { get; set; }

    public string Name { get; set; }
}

public class Dog : Animal 
{
    public string FavouriteToy { get; set; }
}

public class Cat : Animal 
{
    public string FavouriteSleepingPlace { get; set; }
}

var pets = await client.For<Animal>().FindEntriesAsync();

All the values returned will be of type Animal; this applies whether you are retrieving it as a pure retrieval or via an expand.

With the introduction of the ITypeCache etc, we have all the information necessary to automatically determine the type to match to and can avoid needing the custom converter finally addressing #158

weitzhandler commented 5 years ago

@object Can we push this forward? Is there an injectable temporary workaround that will enable reading the type from the json and metadata and decide on which object it should be deserialized to? I'm willing to help.

phatcher commented 4 years ago

@weitzhandler I've just issued a pull request for this

weitzhandler commented 4 years ago

Thank you! ❤