private static UnitType ParseUnitType(string[] equipmentDetails, int index, UnitType defaultValue) { Contract.Requires<ArgumentOutOfRangeException>(index >= 0); Contract.Requires<ArgumentNullException>(equipmentDetails != null); Contract.Requires<ArgumentOutOfRangeException>(defaultValue.IsValid()); UnitType parsedUnitType; if (index < equipmentDetails.Length) { int parsedInt; if (Int32.TryParse(equipmentDetails[index], out parsedInt)) { if (((UnitType)parsedInt).IsValid()) { Contract.Assume(Enum.IsDefined(typeof(UnitType), (UnitType)parsedInt)); parsedUnitType = (UnitType)parsedInt; } else { parsedUnitType = defaultValue; } } else { parsedUnitType = defaultValue; } } else { parsedUnitType = defaultValue; } return parsedUnitType; }
/// <summary> /// Finds the <see cref="Equipment" /> with the specified short name. /// </summary> /// <param name="shortName">The short name of the <see cref="Equipment" />.</param> /// <param name="nationality">The nationality of the <see cref="Equipment" />.</param> /// <param name="type">The type.</param> /// <returns> /// The <see cref="Equipment" /> with the specified short name and nationality or the default if no such equipment /// could be found. /// </returns> /// <exception cref="System.NotImplementedException"></exception> public Equipment Find(string shortName, Nationality nationality, UnitType type) { Contract.Requires<ArgumentNullException>(shortName != null); Contract.Requires<ArgumentOutOfRangeException>(nationality.IsValid()); Contract.Requires<ArgumentOutOfRangeException>(type.IsValid()); throw new NotImplementedException(); }