Skip to content
Ruhrpottpatriot edited this page Sep 1, 2015 · 2 revisions

The items service is without question the most complicated API. It is impossible to cover every use case. Use your .NET knowledge to build on some of the ideas that are outlined on this page. In particular, LINQ and PLINQ are immensely powerful tools when working with the items service.

Get and print a list of items

Newcomers: use this as a starter template.

using GW2NET;
using GW2NET.Common;

IItemRepository service = GW2.V2.Items.ForDefaultCulture();

// Get contextual information
IPageContext ctx = service.FindPage(pageSize: 200, pageIndex: 0);

// Iterate over all available pages
foreach (var page in service.FindAllPages(ctx.PageSize, ctx.PageCount))
{
    foreach (var item in page.Value)
    {
        Console.WriteLine(item.Name);
    }
}

Get an item's in-game icon as a bitmap

using GW2NET;
using GW2NET.Common;

IItemRepository service = GW2.V2.Items.ForDefaultCulture();
IRenderService iconService = GW2.Rendering.RenderService;
IPageContext ctx = service.FindPage(pageSize: 200, pageIndex: 0);
foreach (var page in service.FindAllPages(ctx.PageSize, ctx.PageCount))
{
    foreach (var item in page.Value)
    {
        byte[] jpg = iconService.GetImage(item, "jpg");
        byte[] png = iconService.GetImage(item, "png");
    }
}

Get an item's Chatlink

using GW2NET;
using GW2NET.Common;

IItemRepository service = GW2.V2.Items.ForDefaultCulture();
IPageContext ctx = service.FindPage(pageSize: 200, pageIndex: 0);
foreach (var page in service.FindAllPages(ctx.PageSize, ctx.PageCount))
{
    foreach (var item in page.Value)
    {
        string chatLink = item.GetItemChatLink().ToString();
    }
}

Inheritance tree

All items derive from abstract class Item. Each item type has a derived class that defines additional properties for that specific item type. In order to access type-specific item details, cast the item object to its actual type.

Tip: use the Enumerable.OfType<T>() extension method

var service     = new ServiceManager();
var items       = service.GetItems().Take(100).AsParallel().Select(service.GetItemDetails).ToList();
var armors      = items.OfType<Armor>();
var backpacks   = items.OfType<Backpack>();
var bags        = items.OfType<Bag>();
var consumables = items.OfType<Consumable>();
var containers  = items.OfType<Container>();
var materials   = items.OfType<CraftingMaterial>();
var gathering   = items.OfType<GatheringTool>();
var gizmos      = items.OfType<Gizmo>();
var minipets    = items.OfType<MiniPet>();
var tools       = items.OfType<Tool>();
var trinkets    = items.OfType<Trinket>();
var trophies    = items.OfType<Trophy>();
var upgrades    = items.OfType<UpgradeComponent>();
var weapons     = items.OfType<Weapon>();

You can define even more specific filters, so long as you know the type name.

var aquatics  = armors.OfType<AquaticHelm>();
var boots     = armors.OfType<Boots>();
var coats     = armors.OfType<Coat>();
var gloves    = armors.OfType<Gloves>();
var helms     = armors.OfType<Helm>();
var leggings  = armors.OfType<Leggings>();
var shoulders = armors.OfType<Shoulders>();

Cheat Sheet

Below is a quick reference of the item inheritance tree.

Item

  • Armor
    • AquaticHelm
    • Boots
    • Coat
    • Gloves
    • Helm
    • Leggings
    • Shoulders
    • UnknownArmor
  • Backpack
  • Bag
  • Consumable
    • AppearanceChanger
    • Unlocker
      • BagSlotUnlocker
      • BankTabUnlocker
      • CollectibleCapacityUnlocker
      • ContentUnlocker
      • CraftingRecipeUnlocker
      • DyeUnlocker
      • UnknownUnlocker
    • Booze
    • ContractNpc
    • Food
    • GenericConsumable
    • HalloweenConsumable
    • ImmediateConsumable
    • Transmutation
    • UnknownConsumable
    • UnTransmutation
    • UpgradeRemoval
    • Utility
  • Container
    • DefaultContainer
    • GiftBox
    • OpenUiContainer
    • UnknownContainer
  • CraftingMaterial
  • GatheringTool
    • ForagingTool
    • LoggingTool
    • MiningTool
    • UnknownGatheringTool
  • Gizmo
    • ContainerKey
    • DefaultGizmo
    • RentableContractNpc
    • UnknownGizmo
    • UnlimitedConsumable
  • MiniPet
  • Tool
    • SalvageTool
    • UnknownTool
  • Trinket
    • Accessory
    • Amulet
    • Ring
    • UnknownTrinket
  • Trophy
  • UnknownItem
  • UpgradeComponent
    • DefaultUpgradeComponent
    • Gem
    • Rune
    • Sigil
    • UnknownUpgradeComponent
  • Weapon
    • Axe
    • Dagger
    • Focus
    • GreatSword
    • Hammer
    • Harpoon
    • LargeBundle
    • LongBow
    • Mace
    • Pistol
    • Rifle
    • Scepter
    • Shield
    • ShortBow
    • SmallBundle
    • SpearGun
    • Staff
    • Sword
    • Torch
    • ToyWeapon
    • Trident
    • TwoHandedToyWeapon
    • UnknownWeapon
    • WarHorn