mirror of
https://github.com/ldqk/Masuit.Tools.git
synced 2026-10-19 06:58:32 +08:00
21 lines
582 B
C#
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());
|
|
}
|
|
} |