Я толкаю документацию, но я также хочу охватить каждого, чтобы вы все, если есть известное решение моей проблемы или потери JSON в разные классы.[
{
"id": "sword",
"viewModelId": "sword_01",
"itemType": "Weapon",
"damage": "1d10"
},
{
"id": "shield",
"viewModelId": "shield_02",
"itemType": "Armour", // Fixed, thank you Yong
"armour": "3"
}
]
< /code>
У меня есть класс, охватывающий концепцию элементов < /p>
[System.Serializable]
public class Item
{
public string id;
public string viewModelId;
}
< /code>
и один из каждого из itemtypes < /p>
[System.Serializable]
public class Weapon : Item
{
public string damage;
}
< /code>
[System.Serializable]
public class Armour : Item
{
public int armour;
}
< /code>
Figuring this out is important to me because down the line I will want potions, and scrolls, and tools, and treasure, and so on and so forth. I'd like to not handle this with one big Item Class, but instead Subclasses I can add ItemType specific variables and methods into.
I am also open to alternative approaches, like breaking up each ItemType. That is a file for Weapons, a file for Armor, a file for etc.
Thanks
Подробнее здесь: https://stackoverflow.com/questions/797 ... nt-classes
Опустошение для разных классов ⇐ C#
Место общения программистов C#
1754326150
Anonymous
Я толкаю документацию, но я также хочу охватить каждого, чтобы вы все, если есть известное решение моей проблемы или потери JSON в разные классы.[
{
"id": "sword",
"viewModelId": "sword_01",
"itemType": "Weapon",
"damage": "1d10"
},
{
"id": "shield",
"viewModelId": "shield_02",
"itemType": "Armour", // Fixed, thank you Yong
"armour": "3"
}
]
< /code>
У меня есть класс, охватывающий концепцию элементов < /p>
[System.Serializable]
public class Item
{
public string id;
public string viewModelId;
}
< /code>
и один из каждого из itemtypes < /p>
[System.Serializable]
public class Weapon : Item
{
public string damage;
}
< /code>
[System.Serializable]
public class Armour : Item
{
public int armour;
}
< /code>
Figuring this out is important to me because down the line I will want potions, and scrolls, and tools, and treasure, and so on and so forth. I'd like to not handle this with one big Item Class, but instead Subclasses I can add ItemType specific variables and methods into.
I am also open to alternative approaches, like breaking up each ItemType. That is a file for Weapons, a file for Armor, a file for etc.
Thanks
Подробнее здесь: [url]https://stackoverflow.com/questions/79724486/deserialization-to-different-classes[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия