12345678910111213141516171819202122 |
- using System;
- using System.Collections.Generic;
- namespace DhcpServer.Utils
- {
- internal static class ExtensionMethods
- {
- public static TR MapValue<TK, TV, TR>(this Dictionary<TK, TV> dic, TK key, Func<TV, TR> found)
- {
- return dic.TryGetValue(key, out var value)
- ? found(value)
- : default;
- }
- public static TR MapValue<TK, TV, TR>(this Dictionary<TK, TV> dic, TK key, Func<TV, TR> found, Func<TR> notFound)
- {
- return dic.TryGetValue(key, out var value)
- ? found(value)
- : notFound();
- }
- }
- }
|