Skip to content

[feature/dataflow] Support DynamicallyAccessedMemberKinds.RecursiveProperties #1087

@eerhardt

Description

@eerhardt

For (de)serialization cases, like in System.Text.Json, we need a way to tell the linker to keep the properties of type T, and also the properties of any types referenced by T's properties recursively.

Take the example in https://docs.microsoft.com/en-us/dotnet/standard/serialization/system-text-json-how-to:

public class WeatherForecast
{
    public DateTimeOffset Date { get; set; }
    public int TemperatureCelsius { get; set; }
    public string Summary { get; set; }
    public string SummaryField;
    public IList<DateTimeOffset> DatesAvailable { get; set; }
    public Dictionary<string, HighLowTemps> TemperatureRanges { get; set; }
    public string[] SummaryWords { get; set; }
}

public class HighLowTemps
{
    public int High { get; set; }
    public int Low { get; set; }
}

...

jsonString = File.ReadAllText(fileName);
weatherForecast = JsonSerializer.Deserialize<WeatherForecast>(jsonString);

Note that the properties of HighLowTemps need to be preserved even though I didn't directly pass HighLowTemps into JsonSerializer.Deserialize. Also note that when walking the properties recursively, we need to handle generic collections: Dictionary<string, HighLowTemps>.

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