edjCase / ICP.NET

A library for .NET/C#/Unity to natively communicate with the Internet Computer (ICP)
MIT License
53 stars 5 forks source link

Custom serialization attibutes for dictionary -> vec record #90

Closed Gekctek closed 1 year ago

Gekctek commented 1 year ago
public class ItemService
{
    public List<Item> dictionary {get; set; }
}

vs

public class ItemService
{
    [SerializeAsList]
    public Dictionary<string, Item> dictionary {get; set; }
}
LorenzGit commented 1 year ago

Just to clarify, adding here the current implementation and the proposal:


// Candid:
type ItemService = record {
    dictionary : Items_Dictionary;
};
type Items_Dictionary = vec record { 
    text; Item 
};
type Item = record {
    name : text;
};

// Current C# generated code:
public class ItemService
{
    public List<Items_DictionaryItem> dictionary { get; set; }
}
public class Items_DictionaryItem
{
    [CandidTag(0U)] public string F0 { get; set; }
    [CandidTag(1U)] public Item F1 { get; set; }
}
public class Item
{
    public string name { get; set; }
}

// Proposal:
public class ItemService
{
    [SerializeAsList] public Dictionary<string, Item> dictionary { get; set; }
}
public class Item
{
    public string name { get; set; }
}
Gekctek commented 1 year ago

Done. Dictionaries are treated as vec rec {t1;t2;}