Replace catch(KeyNotFoundException) with TryGetValue()
This commit is contained in:
@@ -30,33 +30,33 @@ namespace OpenRA.Graphics
|
|||||||
|
|
||||||
public Sequence GetSequence(string unitName, string sequenceName)
|
public Sequence GetSequence(string unitName, string sequenceName)
|
||||||
{
|
{
|
||||||
try
|
Lazy<IReadOnlyDictionary<string, Sequence>> unitSeq;
|
||||||
{
|
if (!sequences.Value.TryGetValue(unitName, out unitSeq))
|
||||||
return sequences.Value[unitName].Value[sequenceName];
|
throw new InvalidOperationException("Unit `{0}` does not have any sequences defined.".F(unitName));
|
||||||
}
|
|
||||||
catch (KeyNotFoundException)
|
Sequence seq;
|
||||||
{
|
if (!unitSeq.Value.TryGetValue(sequenceName, out seq))
|
||||||
if (sequences.Value.ContainsKey(unitName))
|
throw new InvalidOperationException("Unit `{0}` does not have a sequence named `{1}`".F(unitName, sequenceName));
|
||||||
throw new InvalidOperationException("Unit `{0}` does not have a sequence `{1}`".F(unitName, sequenceName));
|
|
||||||
else
|
return seq;
|
||||||
throw new InvalidOperationException("Unit `{0}` does not have all sequences defined.".F(unitName));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool HasSequence(string unitName, string sequenceName)
|
public bool HasSequence(string unitName, string sequenceName)
|
||||||
{
|
{
|
||||||
if (!sequences.Value.ContainsKey(unitName))
|
Lazy<IReadOnlyDictionary<string, Sequence>> unitSeq;
|
||||||
throw new InvalidOperationException("Unit `{0}` does not have sequence `{1}` defined.".F(unitName, sequenceName));
|
if (!sequences.Value.TryGetValue(unitName, out unitSeq))
|
||||||
|
throw new InvalidOperationException("Unit `{0}` does not have any sequences defined.".F(unitName));
|
||||||
|
|
||||||
return sequences.Value[unitName].Value.ContainsKey(sequenceName);
|
return unitSeq.Value.ContainsKey(sequenceName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<string> Sequences(string unitName)
|
public IEnumerable<string> Sequences(string unitName)
|
||||||
{
|
{
|
||||||
if (!sequences.Value.ContainsKey(unitName))
|
Lazy<IReadOnlyDictionary<string, Sequence>> unitSeq;
|
||||||
throw new InvalidOperationException("Unit `{0}` does not have all sequences defined.".F(unitName));
|
if (!sequences.Value.TryGetValue(unitName, out unitSeq))
|
||||||
|
throw new InvalidOperationException("Unit `{0}` does not have any sequences defined.".F(unitName));
|
||||||
|
|
||||||
return sequences.Value[unitName].Value.Keys;
|
return unitSeq.Value.Keys;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user