/// <inheritdoc /> public Weapon Convert(ItemDTO value, object state) { var entity = new UnknownWeapon(); this.Merge(entity, value, state); return(entity); }
/// <summary>Converts the given object of type <see cref="DetailsDataContract"/> to an object of type <see cref="Weapon"/>.</summary> /// <param name="value">The value to convert.</param> /// <param name="state"></param> /// <returns>The converted value.</returns> public Weapon Convert(DetailsDataContract value, object state) { if (value == null) { throw new ArgumentNullException("value", "Precondition: value != null"); } Weapon weapon; IConverter <DetailsDataContract, Weapon> converter; if (this.typeConverters.TryGetValue(value.Type, out converter)) { weapon = converter.Convert(value, state); } else { weapon = new UnknownWeapon(); } weapon.DamageType = this.converterForDamageType.Convert(value.DamageType, state); weapon.MinimumPower = value.MinimumPower.GetValueOrDefault(); weapon.MaximumPower = value.MaximumPower.GetValueOrDefault(); weapon.Defense = value.Defense.GetValueOrDefault(); var infusionSlotDataContracts = value.InfusionSlots; if (infusionSlotDataContracts != null) { weapon.InfusionSlots = this.converterForInfusionSlotCollection.Convert(infusionSlotDataContracts, state); } var infixUpgradeDataContract = value.InfixUpgrade; if (infixUpgradeDataContract != null) { weapon.InfixUpgrade = this.converterForInfixUpgrade.Convert(infixUpgradeDataContract, state); } weapon.SuffixItemId = value.SuffixItemId; int secondarySuffixItemId; if (int.TryParse(value.SecondarySuffixItemId, out secondarySuffixItemId)) { weapon.SecondarySuffixItemId = secondarySuffixItemId; } return(weapon); }
// Implement this method in a buddy class to set properties that are specific to 'UnknownWeapon' (if any) partial void Merge(UnknownWeapon entity, ItemDTO dto, object state);
/// <inheritdoc /> public Weapon Convert(ItemDataContract value, object state) { if (value == null) { throw new ArgumentNullException("value", "Precondition: value != null"); } Weapon weapon; var weaponDataContract = value.Weapon; IConverter <WeaponDataContract, Weapon> converter; if (weaponDataContract != null && this.typeConverters.TryGetValue(weaponDataContract.Type, out converter)) { weapon = converter.Convert(weaponDataContract, state); } else { weapon = new UnknownWeapon(); } int defaultSkinId; if (int.TryParse(value.DefaultSkin, out defaultSkinId)) { weapon.DefaultSkinId = defaultSkinId; } if (weaponDataContract == null) { return(weapon); } weapon.DamageType = this.converterForDamageType.Convert(weaponDataContract.DamageType, state); int minimumPower; if (int.TryParse(weaponDataContract.MinimumPower, out minimumPower)) { weapon.MinimumPower = minimumPower; } int maximumPower; if (int.TryParse(weaponDataContract.MaximumPower, out maximumPower)) { weapon.MaximumPower = maximumPower; } int defense; if (int.TryParse(weaponDataContract.Defense, out defense)) { weapon.Defense = defense; } var infusionSlotDataContracts = weaponDataContract.InfusionSlots; if (infusionSlotDataContracts != null) { weapon.InfusionSlots = this.converterForInfusionSlotCollection.Convert(infusionSlotDataContracts, state); } var infixUpgradeDataContract = weaponDataContract.InfixUpgrade; if (infixUpgradeDataContract != null) { weapon.InfixUpgrade = this.converterForInfixUpgrade.Convert(infixUpgradeDataContract, state); } int suffixItemId; if (int.TryParse(weaponDataContract.SuffixItemId, out suffixItemId)) { weapon.SuffixItemId = suffixItemId; } int secondarySuffixItemId; if (int.TryParse(weaponDataContract.SecondarySuffixItemId, out secondarySuffixItemId)) { weapon.SecondarySuffixItemId = secondarySuffixItemId; } return(weapon); }