Introduce FirstOrDefault extensions method for Array.Find and List.Find.
This allows the LINQ spelling to be used, but benefits from the performance improvement of the specific methods for these classes that provide the same result.
This commit is contained in:
@@ -9,7 +9,6 @@
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Eluant;
|
||||
using OpenRA.Mods.Common.Traits;
|
||||
@@ -34,7 +33,7 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
"If duration > 0 the condition will be automatically revoked after the defined number of ticks.")]
|
||||
public int GrantCondition(string condition, int duration = 0)
|
||||
{
|
||||
var external = Array.Find(externalConditions, t => t.Info.Condition == condition && t.CanGrantCondition(this));
|
||||
var external = externalConditions.FirstOrDefault(t => t.Info.Condition == condition && t.CanGrantCondition(this));
|
||||
|
||||
if (external == null)
|
||||
throw new LuaException($"Condition `{condition}` has not been listed on an enabled ExternalCondition trait");
|
||||
|
||||
Reference in New Issue
Block a user