예제 #1
0
        public static bool TryGetByName <T>(this IStringLookup headers, string name, out T value)
        {
            if (headers.TryGetByName(name, out var stringValue))
            {
                value = (T)Convert.ChangeType(stringValue, typeof(T), CultureInfo.InvariantCulture);
                return(true);
            }

            value = default;
            return(false);
        }
예제 #2
0
 public static T GetByNameOrDefault <T>(this IStringLookup headers, string name, T defaultValue)
 {
     return(headers.TryGetByName(name, out T value) ? value : defaultValue);
 }
예제 #3
0
 public static T GetByName <T>(this IStringLookup headers, string name)
 {
     return(headers.TryGetByName(name, out T value)
         ? value
         : throw new EntryNotFoundException($"Could not find '{name}' in lookup.", name));
 }
예제 #4
0
 public bool TryGetByName(string name, out string value)
 => _values.TryGetValue(name, out value) ||
 _parent.TryGetByName(name, out value);