C#C
C#4y ago
Pdawg

❔ Adding logic into a JSON serializer

Hey everyone! I need to add logic into a json object, but I can't add any code in there or else it'll break. Here is what I mean: If I have a Dictionary named Icons, I need to say foreach item selected from the filepicker, create a new keypair in the Dictionary. Basically, the user selects a few .png files, the code needs to copy them to a folder and add those names to the dictionary. Here is my current code that is a static dictionary:

private async void SerializeJSON()
        {
            var model = new ObjectModel
            {
                ManifestVersion = 1,
                Name = TileTitle,
                Description = DescriptionTile,
                Version = 1,
                VersionString = "1",
                Author = AuthorTile,
                Organization = OrgTile,
                ContactEmail = TileEmail,
                TileIcon = new Dictionary<int, string>
                {
                    [46] = "icons/tileIcon.png"
                },
                BadgeIcon = new Dictionary<int, string>
                {
                    [24] = "icons/badgeIcon.png"
                },
                Icons = new Dictionary<string, string>
                {
                    ["iconTest"] = "newIcon1.png" // I need to add more items here when needed, based on what is pulled from the filepicker
                },
            };
        }
Was this page helpful?