lundi 17 octobre 2022

How to convert LINQ Select-like statement to JSON / DQL query

I am trying to build a .NET extension method that will take a type parameter and a .Select() statement and convert it to JSON, but I am not sure how I can access subobjects and lists using reflection.

string str = Extensions.GetJson((DataItemList element) => new
{
    name = element.Name,
    subObject = element.Subobject,
    data = element.DataItems.Select(x => new
    {
        x.Id,
        x.Name
    })
});

I don't have an actual instance of the class at all, as I would want to use reflection to make that .GetJson() return something like this (I know it's not exactly JSON, but I want something like this. I am essentially trying to dynamically create a DQL query for Dgraph:

{
    name
    element {
        prop1
        prop2
    },
    data
    {
        id
        name
    }
}




Aucun commentaire:

Enregistrer un commentaire