private static LevelRequirement ReadLevelRequirement(
        JsonElement json,
        MissingMemberBehavior missingMemberBehavior
        )
    {
        RequiredMember <int> min = new("min");
        RequiredMember <int> max = new("max");

        foreach (var member in json.EnumerateObject())
        {
            if (member.NameEquals(min.Name))
            {
                min.Value = member.Value;
            }
            else if (member.NameEquals(max.Name))
            {
                max.Value = member.Value;
            }
            else if (missingMemberBehavior == MissingMemberBehavior.Error)
            {
                throw new InvalidOperationException(Strings.UnexpectedMember(member.Name));
            }
        }

        return(new LevelRequirement
        {
            Min = min.GetValue(),
            Max = max.GetValue()
        });
    }
Esempio n. 2
0
    public static Quaggan GetQuaggan(
        this JsonElement json,
        MissingMemberBehavior missingMemberBehavior
        )
    {
        RequiredMember <string> id  = new("id");
        RequiredMember <string> url = new("url");

        foreach (var member in json.EnumerateObject())
        {
            if (member.NameEquals(id.Name))
            {
                id.Value = member.Value;
            }
            else if (member.NameEquals(url.Name))
            {
                url.Value = member.Value;
            }
            else if (missingMemberBehavior == MissingMemberBehavior.Error)
            {
                throw new InvalidOperationException(Strings.UnexpectedMember(member.Name));
            }
        }

        return(new Quaggan
        {
            Id = id.GetValue(),
            PictureHref = url.GetValue()
        });
    }
Esempio n. 3
0
    private static SkillChallenge ReadSkillChallenge(
        JsonElement json,
        MissingMemberBehavior missingMemberBehavior
        )
    {
        RequiredMember <double> coordinates = new("coord");

        // The 'id' is missing from hero points in End of Dragon maps
        OptionalMember <string> id = new("id");

        foreach (var member in json.EnumerateObject())
        {
            if (member.NameEquals(coordinates.Name))
            {
                coordinates.Value = member.Value;
            }
            else if (member.NameEquals(id.Name))
            {
                id.Value = member.Value;
            }
            else if (missingMemberBehavior == MissingMemberBehavior.Error)
            {
                throw new InvalidOperationException(Strings.UnexpectedMember(member.Name));
            }
        }

        return(new SkillChallenge
        {
            Id = id.GetValueOrEmpty(),
            Coordinates = coordinates.SelectMany(value => value.GetDouble())
        });
    }
Esempio n. 4
0
    GetRace(this JsonElement json, MissingMemberBehavior missingMemberBehavior)
    {
        RequiredMember <RaceName> id     = new("id");
        RequiredMember <string>   name   = new("name");
        RequiredMember <int>      skills = new("skills");

        foreach (var member in json.EnumerateObject())
        {
            if (member.NameEquals(id.Name))
            {
                id.Value = member.Value;
            }
            else if (member.NameEquals(name.Name))
            {
                name.Value = member.Value;
            }
            else if (member.NameEquals(skills.Name))
            {
                skills.Value = member.Value;
            }
            else if (missingMemberBehavior == MissingMemberBehavior.Error)
            {
                throw new InvalidOperationException(Strings.UnexpectedMember(member.Name));
            }
        }

        return(new Race
        {
            Id = id.GetValue(missingMemberBehavior),
            Name = name.GetValue(),
            Skills = skills.SelectMany(value => value.GetInt32())
        });
    }
Esempio n. 5
0
    private static CoinsReward ReadCoinsReward(
        JsonElement json,
        MissingMemberBehavior missingMemberBehavior
        )
    {
        RequiredMember <int> coins = new("count");

        foreach (var member in json.EnumerateObject())
        {
            if (member.NameEquals("type"))
            {
                if (!member.Value.ValueEquals("Coins"))
                {
                    throw new InvalidOperationException(
                              Strings.InvalidDiscriminator(member.Value.GetString())
                              );
                }
            }
            else if (member.NameEquals(coins.Name))
            {
                coins.Value = member.Value;
            }
            else if (missingMemberBehavior == MissingMemberBehavior.Error)
            {
                throw new InvalidOperationException(Strings.UnexpectedMember(member.Name));
            }
        }

        return(new CoinsReward {
            Coins = coins.GetValue()
        });
    }
Esempio n. 6
0
        public DynamicEntity(MissingMemberBehavior missingMemberBehavior,
			IDynamicEntityConverter converter = null, IEqualityComparer<string> comparer = null)
        {
            _missingMemberBehavior = missingMemberBehavior;
            _dataDictionary = new Dictionary<string, object>(comparer ?? StringComparer.InvariantCultureIgnoreCase);
            _converter = converter ?? new NullConverter();
        }
    public static CurrencyAmount GetCurrencyAmount(
        this JsonElement json,
        MissingMemberBehavior missingMemberBehavior
        )
    {
        RequiredMember <int> id    = new("id");
        RequiredMember <int> value = new("value");

        foreach (var member in json.EnumerateObject())
        {
            if (member.NameEquals(id.Name))
            {
                id.Value = member.Value;
            }
            else if (member.NameEquals(value.Name))
            {
                value.Value = member.Value;
            }
            else if (missingMemberBehavior == MissingMemberBehavior.Error)
            {
                throw new InvalidOperationException(Strings.UnexpectedMember(member.Name));
            }
        }

        return(new CurrencyAmount
        {
            CurrencyId = id.GetValue(),
            Amount = value.GetValue()
        });
    }
Esempio n. 8
0
    private static AchievementReward ReadAchievementReward(
        JsonElement json,
        MissingMemberBehavior missingMemberBehavior
        )
    {
        switch (json.GetProperty("type").GetString())
        {
        case "Coins":
            return(ReadCoinsReward(json, missingMemberBehavior));

        case "Item":
            return(ReadItemReward(json, missingMemberBehavior));

        case "Mastery":
            return(ReadMasteryReward(json, missingMemberBehavior));

        case "Title":
            return(ReadTitleReward(json, missingMemberBehavior));
        }

        // ReSharper disable once ForeachCanBePartlyConvertedToQueryUsingAnotherGetEnumerator
        foreach (var member in json.EnumerateObject())
        {
            if (missingMemberBehavior == MissingMemberBehavior.Error)
            {
                throw new InvalidOperationException(Strings.UnexpectedMember(member.Name));
            }
        }

        return(new AchievementReward());
    }
Esempio n. 9
0
    public static DeliveryBox GetDeliveryBox(
        this JsonElement json,
        MissingMemberBehavior missingMemberBehavior
        )
    {
        RequiredMember <Coin>          coins = new("coins");
        RequiredMember <DeliveredItem> items = new("items");

        foreach (var member in json.EnumerateObject())
        {
            if (member.NameEquals(coins.Name))
            {
                coins.Value = member.Value;
            }
            else if (member.NameEquals(items.Name))
            {
                items.Value = member.Value;
            }
            else if (missingMemberBehavior == MissingMemberBehavior.Error)
            {
                throw new InvalidOperationException(Strings.UnexpectedMember(member.Name));
            }
        }

        return(new DeliveryBox
        {
            Coins = coins.GetValue(),
            Items = items.SelectMany(item => ReadDeliveredItem(item, missingMemberBehavior))
        });
    }
Esempio n. 10
0
    private static DeliveredItem ReadDeliveredItem(
        JsonElement json,
        MissingMemberBehavior missingMemberBehavior
        )
    {
        RequiredMember <int> id    = new("id");
        RequiredMember <int> count = new("count");

        foreach (var member in json.EnumerateObject())
        {
            if (member.NameEquals(id.Name))
            {
                id.Value = member.Value;
            }
            else if (member.NameEquals(count.Name))
            {
                count.Value = member.Value;
            }
            else if (missingMemberBehavior == MissingMemberBehavior.Error)
            {
                throw new InvalidOperationException(Strings.UnexpectedMember(member.Name));
            }
        }

        return(new DeliveredItem
        {
            Id = id.GetValue(),
            Count = count.GetValue()
        });
    }
Esempio n. 11
0
    private static DungeonPath ReadDungeonPath(
        JsonElement json,
        MissingMemberBehavior missingMemberBehavior
        )
    {
        RequiredMember <string>      id   = new("id");
        RequiredMember <DungeonKind> kind = new("type");

        foreach (var member in json.EnumerateObject())
        {
            if (member.NameEquals(id.Name))
            {
                id.Value = member.Value;
            }
            else if (member.NameEquals(kind.Name))
            {
                kind.Value = member.Value;
            }
            else if (missingMemberBehavior == MissingMemberBehavior.Error)
            {
                throw new InvalidOperationException(Strings.UnexpectedMember(member.Name));
            }
        }

        return(new DungeonPath
        {
            Id = id.GetValue(),
            Kind = kind.GetValue(missingMemberBehavior)
        });
    }
Esempio n. 12
0
    public static Dungeon GetDungeon(JsonElement json, MissingMemberBehavior missingMemberBehavior)
    {
        RequiredMember <string>      id    = new("id");
        RequiredMember <DungeonPath> paths = new("paths");

        foreach (var member in json.EnumerateObject())
        {
            if (member.NameEquals(id.Name))
            {
                id.Value = member.Value;
            }
            else if (member.NameEquals(paths.Name))
            {
                paths.Value = member.Value;
            }
            else if (missingMemberBehavior == MissingMemberBehavior.Error)
            {
                throw new InvalidOperationException(Strings.UnexpectedMember(member.Name));
            }
        }

        return(new Dungeon
        {
            Id = id.GetValue(),
            Paths = paths.SelectMany(value => ReadDungeonPath(value, missingMemberBehavior))
        });
    }
Esempio n. 13
0
    public static Mastery GetMastery(
        this JsonElement json,
        MissingMemberBehavior missingMemberBehavior
        )
    {
        RequiredMember <int>               id          = new("id");
        RequiredMember <string>            name        = new("name");
        RequiredMember <string>            requirement = new("requirement");
        RequiredMember <int>               order       = new("order");
        RequiredMember <string>            background  = new("background");
        RequiredMember <MasteryRegionName> region      = new("region");
        RequiredMember <MasteryLevel>      levels      = new("levels");

        foreach (var member in json.EnumerateObject())
        {
            if (member.NameEquals(id.Name))
            {
                id.Value = member.Value;
            }
            else if (member.NameEquals(name.Name))
            {
                name.Value = member.Value;
            }
            else if (member.NameEquals(requirement.Name))
            {
                requirement.Value = member.Value;
            }
            else if (member.NameEquals(order.Name))
            {
                order.Value = member.Value;
            }
            else if (member.NameEquals(background.Name))
            {
                background.Value = member.Value;
            }
            else if (member.NameEquals(region.Name))
            {
                region.Value = member.Value;
            }
            else if (member.NameEquals(levels.Name))
            {
                levels.Value = member.Value;
            }
            else if (missingMemberBehavior == MissingMemberBehavior.Error)
            {
                throw new InvalidOperationException(Strings.UnexpectedMember(member.Name));
            }
        }

        return(new Mastery
        {
            Id = id.GetValue(),
            Name = name.GetValue(),
            Requirement = requirement.GetValue(),
            Order = order.GetValue(),
            Background = background.GetValue(),
            Region = region.GetValue(missingMemberBehavior),
            Levels = levels.SelectMany(value => ReadLevel(value, missingMemberBehavior))
        });
    }
    public static AccountAchievement GetAccountAchievement(
        this JsonElement json,
        MissingMemberBehavior missingMemberBehavior
        )
    {
        RequiredMember <int>  id       = new("id");
        RequiredMember <int>  current  = new("current");
        RequiredMember <int>  max      = new("max");
        RequiredMember <bool> done     = new("done");
        OptionalMember <int>  bits     = new("bits");
        NullableMember <int>  repeated = new("repeated");
        NullableMember <bool> unlocked = new("unlocked");

        foreach (var member in json.EnumerateObject())
        {
            if (member.NameEquals(id.Name))
            {
                id.Value = member.Value;
            }
            else if (member.NameEquals(current.Name))
            {
                current.Value = member.Value;
            }
            else if (member.NameEquals(max.Name))
            {
                max.Value = member.Value;
            }
            else if (member.NameEquals(done.Name))
            {
                done.Value = member.Value;
            }
            else if (member.NameEquals(bits.Name))
            {
                bits.Value = member.Value;
            }
            else if (member.NameEquals(repeated.Name))
            {
                repeated.Value = member.Value;
            }
            else if (member.NameEquals(unlocked.Name))
            {
                unlocked.Value = member.Value;
            }
            else if (missingMemberBehavior == MissingMemberBehavior.Error)
            {
                throw new InvalidOperationException(Strings.UnexpectedMember(member.Name));
            }
        }

        return(new AccountAchievement
        {
            Id = id.GetValue(),
            Current = current.GetValue(),
            Max = max.GetValue(),
            Done = done.GetValue(),
            Bits = bits.SelectMany(value => value.GetInt32()),
            Repeated = repeated.GetValue(),
            Unlocked = unlocked.GetValue()
        });
    }
Esempio n. 15
0
    private static SkillReference ReadSkill(
        JsonElement json,
        MissingMemberBehavior missingMemberBehavior
        )
    {
        RequiredMember <int>       id   = new("id");
        RequiredMember <SkillSlot> slot = new("slot");

        foreach (var member in json.EnumerateObject())
        {
            if (member.NameEquals(id.Name))
            {
                id.Value = member.Value;
            }
            else if (member.NameEquals(slot.Name))
            {
                slot.Value = member.Value;
            }
            else if (missingMemberBehavior == MissingMemberBehavior.Error)
            {
                throw new InvalidOperationException(Strings.UnexpectedMember(member.Name));
            }
        }

        return(new SkillReference
        {
            Id = id.GetValue(),
            Slot = slot.GetValue(missingMemberBehavior)
        });
    }
Esempio n. 16
0
    private static AchievementTextBit ReadAchievementTextBit(
        JsonElement json,
        MissingMemberBehavior missingMemberBehavior
        )
    {
        RequiredMember <string> text = new("text");

        foreach (var member in json.EnumerateObject())
        {
            if (member.NameEquals("type"))
            {
                if (!member.Value.ValueEquals("Text"))
                {
                    throw new InvalidOperationException(
                              Strings.InvalidDiscriminator(member.Value.GetString())
                              );
                }
            }
            else if (member.NameEquals(text.Name))
            {
                text.Value = member.Value;
            }
            else if (missingMemberBehavior == MissingMemberBehavior.Error)
            {
                throw new InvalidOperationException(Strings.UnexpectedMember(member.Name));
            }
        }

        return(new AchievementTextBit {
            Text = text.GetValue()
        });
    }
Esempio n. 17
0
    public static World GetWorld(this JsonElement json, MissingMemberBehavior missingMemberBehavior)
    {
        RequiredMember <int>             id         = new("id");
        RequiredMember <string>          name       = new("name");
        RequiredMember <WorldPopulation> population = new("population");

        foreach (var member in json.EnumerateObject())
        {
            if (member.NameEquals(id.Name))
            {
                id.Value = member.Value;
            }
            else if (member.NameEquals(name.Name))
            {
                name.Value = member.Value;
            }
            else if (member.NameEquals(population.Name))
            {
                population.Value = member.Value;
            }
            else if (missingMemberBehavior == MissingMemberBehavior.Error)
            {
                throw new InvalidOperationException(Strings.UnexpectedMember(member.Name));
            }
        }

        return(new World
        {
            Id = id.GetValue(),
            Name = name.GetValue(),
            Population = population.GetValue(missingMemberBehavior)
        });
    }
Esempio n. 18
0
    private static TitleReward ReadTitleReward(
        JsonElement json,
        MissingMemberBehavior missingMemberBehavior
        )
    {
        RequiredMember <int> id = new("id");

        foreach (var member in json.EnumerateObject())
        {
            if (member.NameEquals("type"))
            {
                if (!member.Value.ValueEquals("Title"))
                {
                    throw new InvalidOperationException(
                              Strings.InvalidDiscriminator(member.Value.GetString())
                              );
                }
            }
            else if (member.NameEquals(id.Name))
            {
                id.Value = member.Value;
            }
            else if (missingMemberBehavior == MissingMemberBehavior.Error)
            {
                throw new InvalidOperationException(Strings.UnexpectedMember(member.Name));
            }
        }

        return(new TitleReward {
            Id = id.GetValue()
        });
    }
Esempio n. 19
0
 public DynamicEntity(MissingMemberBehavior missingMemberBehavior,
                      IDynamicEntityConverter converter = null, IEqualityComparer <string> comparer = null)
 {
     _missingMemberBehavior = missingMemberBehavior;
     _dataDictionary        = new Dictionary <string, object>(comparer ?? StringComparer.InvariantCultureIgnoreCase);
     _converter             = converter ?? new NullConverter();
 }
Esempio n. 20
0
    private static AchievementTier ReadAchievementTier(
        JsonElement json,
        MissingMemberBehavior missingMemberBehavior
        )
    {
        RequiredMember <int> count  = new("count");
        RequiredMember <int> points = new("points");

        foreach (var member in json.EnumerateObject())
        {
            if (member.NameEquals(count.Name))
            {
                count.Value = member.Value;
            }
            else if (member.NameEquals(points.Name))
            {
                points.Value = member.Value;
            }
            else if (missingMemberBehavior == MissingMemberBehavior.Error)
            {
                throw new InvalidOperationException(Strings.UnexpectedMember(member.Name));
            }
        }

        return(new AchievementTier
        {
            Count = count.GetValue(),
            Points = points.GetValue()
        });
    }
Esempio n. 21
0
    public static MasteryProgress GetMasteryProgress(
        this JsonElement json,
        MissingMemberBehavior missingMemberBehavior
        )
    {
        RequiredMember <int> id    = new("id");
        RequiredMember <int> level = new("level");

        foreach (var member in json.EnumerateObject())
        {
            if (member.NameEquals(id.Name))
            {
                id.Value = member.Value;
            }
            else if (member.NameEquals(level.Name))
            {
                level.Value = member.Value;
            }
            else if (missingMemberBehavior == MissingMemberBehavior.Error)
            {
                throw new InvalidOperationException(Strings.UnexpectedMember(member.Name));
            }
        }

        return(new MasteryProgress
        {
            Id = id.GetValue(),
            Level = level.GetValue()
        });
    }
Esempio n. 22
0
    private static PointF ReadPointF(JsonElement json, MissingMemberBehavior missingMemberBehavior)
    {
        var x = json[0].GetSingle();
        var y = json[1].GetSingle();

        return(new PointF(x, y));
    }
Esempio n. 23
0
    public static Emblem GetEmblem(
        this JsonElement json,
        MissingMemberBehavior missingMemberBehavior
        )
    {
        RequiredMember <int>    id     = new("id");
        RequiredMember <string> layers = new("layers");

        foreach (var member in json.EnumerateObject())
        {
            if (member.NameEquals(id.Name))
            {
                id.Value = member.Value;
            }
            else if (member.NameEquals(layers.Name))
            {
                layers.Value = member.Value;
            }
            else if (missingMemberBehavior == MissingMemberBehavior.Error)
            {
                throw new InvalidOperationException(Strings.UnexpectedMember(member.Name));
            }
        }

        return(new Emblem
        {
            Id = id.GetValue(),
            Layers = layers.SelectMany(value => value.GetStringRequired())
        });
    }
Esempio n. 24
0
    private static GodShrine ReadGodShrine(
        JsonElement json,
        MissingMemberBehavior missingMemberBehavior
        )
    {
        RequiredMember <int>    id                = new("id");
        RequiredMember <string> name              = new("name");
        RequiredMember <string> nameContested     = new("name_contested");
        RequiredMember <int>    pointOfInterestId = new("poi_id");
        RequiredMember <double> coordinates       = new("coord");
        RequiredMember <string> icon              = new("icon");
        RequiredMember <string> iconContested     = new("icon_contested");

        foreach (var member in json.EnumerateObject())
        {
            if (member.NameEquals(id.Name))
            {
                id.Value = member.Value;
            }
            else if (member.NameEquals(name.Name))
            {
                name.Value = member.Value;
            }
            else if (member.NameEquals(nameContested.Name))
            {
                nameContested.Value = member.Value;
            }
            else if (member.NameEquals(pointOfInterestId.Name))
            {
                pointOfInterestId.Value = member.Value;
            }
            else if (member.NameEquals(coordinates.Name))
            {
                coordinates.Value = member.Value;
            }
            else if (member.NameEquals(icon.Name))
            {
                icon.Value = member.Value;
            }
            else if (member.NameEquals(iconContested.Name))
            {
                iconContested.Value = member.Value;
            }
            else if (missingMemberBehavior == MissingMemberBehavior.Error)
            {
                throw new InvalidOperationException(Strings.UnexpectedMember(member.Name));
            }
        }

        return(new GodShrine
        {
            Id = id.GetValue(),
            Name = name.GetValue(),
            NameContested = nameContested.GetValue(),
            PointOfInterestId = pointOfInterestId.GetValue(),
            Coordinates = coordinates.SelectMany(value => value.GetDouble()),
            Icon = icon.GetValue(),
            IconContested = iconContested.GetValue()
        });
    }
Esempio n. 25
0
    private static Specialization ReadSpecialization(
        JsonElement json,
        MissingMemberBehavior missingMemberBehavior
        )
    {
        NullableMember <int>  id     = new("id");
        RequiredMember <int?> traits = new("traits");

        foreach (var member in json.EnumerateObject())
        {
            if (member.NameEquals(id.Name))
            {
                id.Value = member.Value;
            }
            else if (member.NameEquals(traits.Name))
            {
                traits.Value = member.Value;
            }
            else if (missingMemberBehavior == MissingMemberBehavior.Error)
            {
                throw new InvalidOperationException(Strings.UnexpectedMember(member.Name));
            }
        }

        return(new Specialization
        {
            Id = id.GetValue(),
            Traits = traits.SelectMany(
                value => value.ValueKind == JsonValueKind.Null ? null : value.GetInt32()
                )
        });
    }
    public static BackstoryAnswer GetBackstoryAnswer(
        this JsonElement json,
        MissingMemberBehavior missingMemberBehavior
        )
    {
        RequiredMember <string>         id          = new("id");
        RequiredMember <string>         title       = new("title");
        RequiredMember <string>         description = new("description");
        RequiredMember <string>         journal     = new("journal");
        RequiredMember <int>            question    = new("question");
        OptionalMember <ProfessionName> professions = new("professions");
        OptionalMember <RaceName>       races       = new("races");

        foreach (var member in json.EnumerateObject())
        {
            if (member.NameEquals(id.Name))
            {
                id.Value = member.Value;
            }
            else if (member.NameEquals(title.Name))
            {
                title.Value = member.Value;
            }
            else if (member.NameEquals(description.Name))
            {
                description.Value = member.Value;
            }
            else if (member.NameEquals(journal.Name))
            {
                journal.Value = member.Value;
            }
            else if (member.NameEquals(question.Name))
            {
                question.Value = member.Value;
            }
            else if (member.NameEquals(professions.Name))
            {
                professions.Value = member.Value;
            }
            else if (member.NameEquals(races.Name))
            {
                races.Value = member.Value;
            }
            else if (missingMemberBehavior == MissingMemberBehavior.Error)
            {
                throw new InvalidOperationException(Strings.UnexpectedMember(member.Name));
            }
        }

        return(new BackstoryAnswer
        {
            Id = id.GetValue(),
            Title = title.GetValue(),
            Description = description.GetValue(),
            Journal = journal.GetValue(),
            Question = question.GetValue(),
            Professions = professions.GetValues(missingMemberBehavior),
            Races = races.GetValues(missingMemberBehavior)
        });
    }
Esempio n. 27
0
    private static PetSkillBar ReadPets(
        JsonElement json,
        MissingMemberBehavior missingMemberBehavior
        )
    {
        RequiredMember <int?> terrestrial = new("terrestrial");
        RequiredMember <int?> aquatic     = new("aquatic");

        foreach (var member in json.EnumerateObject())
        {
            if (member.NameEquals(terrestrial.Name))
            {
                terrestrial.Value = member.Value;
            }
            else if (member.NameEquals(aquatic.Name))
            {
                aquatic.Value = member.Value;
            }
            else if (missingMemberBehavior == MissingMemberBehavior.Error)
            {
                throw new InvalidOperationException(Strings.UnexpectedMember(member.Name));
            }
        }

        return(new PetSkillBar
        {
            Terrestrial =
                terrestrial.SelectMany(
                    value => value.ValueKind == JsonValueKind.Null ? null : value.GetInt32()
                    ),
            Aquatic = aquatic.SelectMany(
                value => value.ValueKind == JsonValueKind.Null ? null : value.GetInt32()
                )
        });
    }
    private static ProductRequirement ReadProductRequirement(
        JsonElement json,
        MissingMemberBehavior missingMemberBehavior
        )
    {
        RequiredMember <ProductName>     product   = new("product");
        RequiredMember <AccessCondition> condition = new("condition");

        foreach (var member in json.EnumerateObject())
        {
            if (member.NameEquals(product.Name))
            {
                product.Value = member.Value;
            }
            else if (member.NameEquals(condition.Name))
            {
                condition.Value = member.Value;
            }
            else if (missingMemberBehavior == MissingMemberBehavior.Error)
            {
                throw new InvalidOperationException(Strings.UnexpectedMember(member.Name));
            }
        }

        return(new ProductRequirement
        {
            Product = product.GetValue(missingMemberBehavior),
            Condition = condition.GetValue(missingMemberBehavior)
        });
    }
Esempio n. 29
0
    private static SizeF ReadSizeF(JsonElement json, MissingMemberBehavior missingMemberBehavior)
    {
        var width  = json[0].GetSingle();
        var height = json[1].GetSingle();

        return(new SizeF(width, height));
    }
Esempio n. 30
0
    public static File GetFile(this JsonElement json, MissingMemberBehavior missingMemberBehavior)
    {
        RequiredMember <string> id   = new("id");
        RequiredMember <string> icon = new("icon");

        foreach (var member in json.EnumerateObject())
        {
            if (member.NameEquals(id.Name))
            {
                id.Value = member.Value;
            }
            else if (member.NameEquals(icon.Name))
            {
                icon.Value = member.Value;
            }
            else if (missingMemberBehavior == MissingMemberBehavior.Error)
            {
                throw new InvalidOperationException(Strings.UnexpectedMember(member.Name));
            }
        }

        return(new File
        {
            Id = id.GetValue(),
            Icon = icon.GetValue()
        });
    }
Esempio n. 31
0
    private static WvwAbility ReadWvwAbility(
        JsonElement json,
        MissingMemberBehavior missingMemberBehavior
        )
    {
        RequiredMember <int> id   = new("id");
        RequiredMember <int> rank = new("rank");

        foreach (var member in json.EnumerateObject())
        {
            if (member.NameEquals(id.Name))
            {
                id.Value = member.Value;
            }
            else if (member.NameEquals(rank.Name))
            {
                rank.Value = member.Value;
            }
            else if (missingMemberBehavior == MissingMemberBehavior.Error)
            {
                throw new InvalidOperationException(Strings.UnexpectedMember(member.Name));
            }
        }

        return(new WvwAbility
        {
            Id = id.GetValue(),
            Rank = rank.GetValue()
        });
    }