public static GradeModifier GetModifier(this ICollection <WeaponTypeGradePair> pairs, WeaponType weaponType) { foreach (var pair in pairs) { if (pair.WeaponType.GetInstanceID() == weaponType.GetInstanceID()) { return(pair.Modifier); } } throw new System.Exception("no matching weapon type found"); }