OLD | NEW |
| (Empty) |
1 // Copyright (c) 2011 The Native Client Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #region | |
6 | |
7 using System.Collections.Generic; | |
8 | |
9 #endregion | |
10 | |
11 namespace Google.NaClVsx.DebugSupport.DWARF { | |
12 public static class ExtensionMethods { | |
13 public static T PeekOrDefault<T>(this Stack<T> s) where T : class { | |
14 if (s.Count == 0) { | |
15 return null; | |
16 } | |
17 return s.Peek(); | |
18 } | |
19 | |
20 public static T PeekOrDefault<T>(this Stack<T> s, T defaultValue) { | |
21 if (s.Count == 0) { | |
22 return defaultValue; | |
23 } | |
24 return s.Peek(); | |
25 } | |
26 | |
27 public static TV GetValueOrDefault<TK, TV>(this IDictionary<TK, TV> d, | |
28 TK key, | |
29 TV defaultValue) { | |
30 TV result; | |
31 if (!d.TryGetValue(key, out result)) { | |
32 result = defaultValue; | |
33 } | |
34 return result; | |
35 } | |
36 } | |
37 } | |
OLD | NEW |