Files
懒得勤快 f100bf46aa 清理代码
2023-05-30 22:03:35 +08:00

21 lines
582 B
C#

using Microsoft.AspNetCore.Mvc.ViewFeatures;
namespace Masuit.Tools.AspNetCore.Extensions;
public static class ViewDataDictionaryExt
{
public static T GetValue<T>(this ViewDataDictionary dic, string s) where T : class
{
return dic[s] as T;
}
public static T GetValueOrDefault<T>(this ViewDataDictionary dic, string s, T defaultValue)
{
return (T)(dic[s] ?? defaultValue);
}
public static T GetValueOrDefault<T>(this ViewDataDictionary dic, string s, Func<T> defaultValue)
{
return (T)(dic[s] ?? defaultValue());
}
}