diff --git a/src/SmartFormat/Core/Parsing/Parser.cs b/src/SmartFormat/Core/Parsing/Parser.cs index 9cbfc6a6..4ba977d5 100644 --- a/src/SmartFormat/Core/Parsing/Parser.cs +++ b/src/SmartFormat/Core/Parsing/Parser.cs @@ -856,7 +856,7 @@ private Format HandleParsingErrors(ParsingErrors parsingErrors, Format currentRe // Placeholder without issues are left unmodified for (var i = 0; i < currentResult.Items.Count; i++) { - if (currentResult.Items[i] is Placeholder ph && parsingErrors.Issues.Any(errItem => errItem.Index >= currentResult.Items[i].StartIndex && errItem.Index <= currentResult.Items[i].EndIndex)) + if (currentResult.Items[i] is Placeholder ph && parsingErrors.Issues.Exists(errItem => errItem.Index >= currentResult.Items[i].StartIndex && errItem.Index <= currentResult.Items[i].EndIndex)) { var parent = ph.Format ?? FormatPool.Instance.Get().Initialize(Settings, ph.BaseString); currentResult.Items[i] = LiteralTextPool.Instance.Get().Initialize(Settings, parent, parent.BaseString, ph.StartIndex, ph.EndIndex); @@ -867,7 +867,7 @@ private Format HandleParsingErrors(ParsingErrors parsingErrors, Format currentRe // Replace erroneous Placeholders with an empty LiteralText for (var i = 0; i < currentResult.Items.Count; i++) { - if (currentResult.Items[i] is Placeholder ph && parsingErrors.Issues.Any(errItem => errItem.Index >= currentResult.Items[i].StartIndex && errItem.Index <= currentResult.Items[i].EndIndex)) + if (currentResult.Items[i] is Placeholder ph && parsingErrors.Issues.Exists(errItem => errItem.Index >= currentResult.Items[i].StartIndex && errItem.Index <= currentResult.Items[i].EndIndex)) { var parent = ph.Format ?? FormatPool.Instance.Get().Initialize(Settings, ph.BaseString); currentResult.Items[i] = LiteralTextPool.Instance.Get().Initialize(Settings, parent, parent.BaseString, ph.StartIndex, ph.StartIndex); @@ -884,4 +884,4 @@ private Format HandleParsingErrors(ParsingErrors parsingErrors, Format currentRe } #endregion -} \ No newline at end of file +} diff --git a/src/SmartFormat/Core/Settings/ParserSettings.cs b/src/SmartFormat/Core/Settings/ParserSettings.cs index 8eec8d8f..f454d302 100644 --- a/src/SmartFormat/Core/Settings/ParserSettings.cs +++ b/src/SmartFormat/Core/Settings/ParserSettings.cs @@ -82,7 +82,7 @@ public void AddCustomOperatorChars(IList characters) { foreach (var c in characters) { - if(DisallowedSelectorChars().Where(_ => OperatorChars().All(ch => ch != c)).Contains(c) || + if(DisallowedSelectorChars().Where(_ => OperatorChars().TrueForAll(ch => ch != c)).Contains(c) || SelectorChars().Contains(c) || CustomSelectorChars().Contains(c)) throw new ArgumentException($"Cannot add '{c}' as a custom operator character. It is disallowed or in use as a selector."); @@ -190,4 +190,4 @@ public void AddCustomOperatorChars(IList characters) FormatterNameSeparator, FormatterOptionsBeginChar, FormatterOptionsEndChar, PlaceholderBeginChar, PlaceholderEndChar }; -} \ No newline at end of file +} diff --git a/src/SmartFormat/Extensions/ChooseFormatter.cs b/src/SmartFormat/Extensions/ChooseFormatter.cs index 012a5af9..ca32b0d8 100644 --- a/src/SmartFormat/Extensions/ChooseFormatter.cs +++ b/src/SmartFormat/Extensions/ChooseFormatter.cs @@ -48,7 +48,7 @@ public bool TryEvaluateFormat(IFormattingInfo formattingInfo) var formats = formattingInfo.Format?.Split(SplitChar); // Check whether arguments can be handled by this formatter - if (formats is null || formats.Count < 2 || chooseOptions is null) + if (formats is null || formats.Count < 2) { // Auto detection calls just return a failure to evaluate if (string.IsNullOrEmpty(formattingInfo.Placeholder?.FormatterName)) diff --git a/src/SmartFormat/SmartFormatter.cs b/src/SmartFormat/SmartFormatter.cs index 78f4ff03..a897d221 100644 --- a/src/SmartFormat/SmartFormatter.cs +++ b/src/SmartFormat/SmartFormatter.cs @@ -95,7 +95,7 @@ public SmartFormatter AddExtensions(params ISource[] sourceExtensions) _ = InsertExtension(index, source); // Also add the class as a formatter, if possible - if (source is IFormatter formatter && FormatterExtensions.All(fx => fx.GetType() != formatter.GetType())) AddExtensions(formatter); + if (source is IFormatter formatter && FormatterExtensions.TrueForAll(fx => fx.GetType() != formatter.GetType())) AddExtensions(formatter); } return this; @@ -123,7 +123,7 @@ public SmartFormatter AddExtensions(params IFormatter[] formatterExtensions) _ = InsertExtension(index, formatter); // Also add the class as a source, if possible - if (formatter is ISource source && SourceExtensions.All(sx => sx.GetType() != source.GetType())) AddExtensions(source); + if (formatter is ISource source && SourceExtensions.TrueForAll(sx => sx.GetType() != source.GetType())) AddExtensions(source); } return this; @@ -144,7 +144,7 @@ public SmartFormatter AddExtensions(params IFormatter[] formatterExtensions) /// public SmartFormatter InsertExtension(int position, ISource sourceExtension) { - if (_sourceExtensions.Any(sx => sx.GetType() == sourceExtension.GetType())) return this; + if (_sourceExtensions.Exists(sx => sx.GetType() == sourceExtension.GetType())) return this; if (sourceExtension is IInitializer sourceToInitialize) sourceToInitialize.Initialize(this); @@ -169,10 +169,10 @@ public SmartFormatter InsertExtension(int position, ISource sourceExtension) /// public SmartFormatter InsertExtension(int position, IFormatter formatterExtension) { - if (_formatterExtensions.Any(sx => sx.GetType() == formatterExtension.GetType())) return this; + if (_formatterExtensions.Exists(sx => sx.GetType() == formatterExtension.GetType())) return this; // Extension name is in use by a different type - if(_formatterExtensions.Any(fx => fx.Name.Equals(formatterExtension.Name))) + if(_formatterExtensions.Exists(fx => fx.Name.Equals(formatterExtension.Name))) throw new ArgumentException($"Formatter '{formatterExtension.GetType().Name}' uses existing name.", nameof(formatterExtension)); if (formatterExtension is IInitializer formatterToInitialize)