/// <summary> /// Attempts to parse an <see cref="Effect"/>, and add its modifier to the provided <see cref="CountryModifierBuilder"/>. /// </summary> /// <param name="effect">The <see cref="Effect"/> to parse.</param> /// <param name="country">The country to parse the effect for.</param> /// <param name="context">The database to use.</param> /// <param name="builder">The <see cref="CountryModifierBuilder"/> to add modifiers to.</param> /// <param name="doApplyPermanent">If effects that have permanenet effects should be applied.</param> /// <returns>If the effect was parsed by the parser.</returns> /// <exception cref="ArgumentNullException">Thrown if an argument was null.</exception> public virtual bool TryParse(Effect effect, Country country, UnderSeaDatabaseContext context, CountryModifierBuilder builder, bool doApplyPermanent) { if (effect == null) { throw new ArgumentNullException(nameof(effect)); } if (country == null) { throw new ArgumentNullException(nameof(country)); } if (builder == null) { throw new ArgumentNullException(nameof(builder)); } if (effect.Name.Equals(HandledEffectName, StringComparison.OrdinalIgnoreCase)) { OnParse(effect, country, context, builder, doApplyPermanent); return(true); } else { return(false); } }
/// <summary> /// Tries to parse the provided <see cref="Effect"/> with the parsers in the container. /// </summary> /// <param name="effect">The <see cref="Effect"/> to parse.</param> /// <param name="country">The country to parse the effect for.</param> /// <param name="context">The database to use.</param> /// <param name="builder">The <see cref="CountryModifierBuilder"/> to store the effect's effects in.</param> /// <param name="doApplyPermanent">If effects that have permanenet effects should be applied.</param> /// <returns>If the effect was parsed by any parsers.</returns> /// <exception cref="ArgumentNullException"> Thrown if an argument was null.</exception> /// <remarks> /// If multiple parsers match the effect only the first matching parser is executed. /// </remarks> public bool TryParse(Effect effect, Country country, UnderSeaDatabaseContext context, CountryModifierBuilder builder, bool doApplyPermanent) { if (effect == null) { throw new ArgumentNullException(nameof(effect)); } if (country == null) { throw new ArgumentNullException(nameof(country)); } if (builder == null) { throw new ArgumentNullException(nameof(builder)); } foreach (var p in Parsers) { if (p.TryParse(effect, country, context, builder, doApplyPermanent)) { return(true); } } return(false); }