public static class ClassExtensions
  {
    public static TResult GetProperty<TClass, TResult>(this TClass obj, Func<TClass, TResult> func) where TClass : class
    {
      if ((object) obj == null)
        return default (TResult);
      else
        return func(obj);
    }

    public static TResult GetProperty<TKey, TResult>(this IDictionary<TKey, TResult> dict, TKey key)
    {
      if (dict == null || !dict.ContainsKey(key))
        return default (TResult);
      else
        return dict[key];
    }

    public static TResult GetProperty<TKey, TValue, TResult>(this IDictionary<TKey, TValue> dict, TKey key, Func<TValue, TResult> func)
    {
      if (dict == null || !dict.ContainsKey(key))
        return default (TResult);
      TValue obj = dict[key];
      return func(obj);
    }

 

相关文章:

  • 2022-12-23
  • 2022-01-19
  • 2022-12-23
  • 2022-02-11
  • 2022-12-23
  • 2022-01-21
猜你喜欢
  • 2022-12-23
  • 2022-01-05
  • 2021-06-20
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-22
相关资源
相似解决方案