private bool FinishItem(PgQuestRewardWorkOrderCurrency item, Dictionary <string, object> contentTable, Dictionary <string, Json.Token> contentTypeTable, List <object> itemCollection, Json.Token lastItemType, string parsedFile, string parsedKey)
        {
            if (contentTable.Count != 1)
            {
                return(Program.ReportFailure(parsedFile, parsedKey, "Invalid currency reward object"));
            }

            foreach (KeyValuePair <string, object> Entry in contentTable)
            {
                string CurrencyKey = Entry.Key;
                object Value       = Entry.Value;

                if (!StringToEnumConversion <Currency> .TryParse(CurrencyKey, out Currency Currency))
                {
                    return(false);
                }

                if (!(Value is int Amount))
                {
                    return(Program.ReportFailure($"Value '{Value}' was expected to be an int"));
                }

                item.Currency  = Currency;
                item.RawAmount = Amount;
            }

            return(true);
        }
Example #2
0
        private static bool FinishItemWorkOrderCurrency(ref object?item, Dictionary <string, object> contentTable, Dictionary <string, Json.Token> contentTypeTable, List <object> itemCollection, Json.Token lastItemType, List <string> knownFieldList, List <string> usedFieldList, string parsedFile, string parsedKey)
        {
            PgQuestRewardWorkOrderCurrency NewItem = new PgQuestRewardWorkOrderCurrency();

            bool Result = true;

            foreach (KeyValuePair <string, object> Entry in contentTable)
            {
                string Key   = Entry.Key;
                object Value = Entry.Value;

                if (!knownFieldList.Contains(Key))
                {
                    Result = Program.ReportFailure($"Unknown field {Key}");
                }
                else
                {
                    usedFieldList.Add(Key);

                    switch (Key)
                    {
                    case "T":
                        break;

                    case "Currency":
                        Result = StringToEnumConversion <Currency> .SetEnum((Currency valueEnum) => NewItem.Currency = valueEnum, Value);

                        break;

                    case "Amount":
                        Result = SetIntProperty((int valueInt) => NewItem.RawAmount = valueInt, Value);
                        break;

                    default:
                        Result = Program.ReportFailure("Unexpected failure");
                        break;
                    }
                }

                if (!Result)
                {
                    break;
                }
            }

            if (Result)
            {
                item = NewItem;
                return(true);
            }
            else
            {
                return(false);
            }
        }