Skip to content

Commit

Permalink
Used Enumerable.SingleOrDefault instead of Enumerable.Single, in orde…
Browse files Browse the repository at this point in the history
…r to avoid a try/catch block.
  • Loading branch information
moodmosaic committed Sep 26, 2014
1 parent 1758161 commit 3bb1136
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions AtomEventStore/TypeResolutionTable.cs
Expand Up @@ -78,24 +78,19 @@ public Type Resolve(string localName, string xmlNamespace)
if (xmlNamespace == null)
throw new ArgumentNullException("xmlNamespace");

try
{
return this.entries
.Single(x =>
x.LocalName == localName &&
x.XmlNamespace == xmlNamespace)
.ResolvedType;
}
catch (InvalidOperationException e)
{
var result = this.entries
.SingleOrDefault(x =>
x.LocalName == localName &&
x.XmlNamespace == xmlNamespace);

if (result == null)
throw new ArgumentException(
string.Format(
System.Globalization.CultureInfo.CurrentCulture,
"The provided local name ({0}) and XML namespace ({1}) could not be mapped to a proper type.",
localName,
xmlNamespace),
e);
}
xmlNamespace));
return result.ResolvedType;
}

/// <summary>
Expand Down

0 comments on commit 3bb1136

Please sign in to comment.