-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use Dictionary.TryAdd for minor perf improvements in entityset add
- Loading branch information
1 parent
e32f5ca
commit 6be87ba
Showing
2 changed files
with
33 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace OpenRiaServices.Client | ||
{ | ||
#if !NET | ||
/// <summary> | ||
/// Helper methods to allow "newer" | ||
/// </summary> | ||
static class Polyfills | ||
{ | ||
public static bool TryAdd<TKey, TValue>(this IDictionary<TKey, TValue> dictionary, TKey key, TValue value) | ||
{ | ||
// This is expected to be used in scenarios where the add vill almost always succeed, so we pay the cost of an exception | ||
// on duplicates instead of checking if the Key exists first | ||
try | ||
{ | ||
dictionary.Add(key, value); | ||
return true; | ||
} | ||
// Duplicate key | ||
catch (ArgumentException) | ||
{ | ||
return false; | ||
} | ||
} | ||
} | ||
#endif | ||
} |