| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- using bitforum.Models;
- using Microsoft.AspNetCore.Mvc;
- using System.ComponentModel.DataAnnotations;
- using System.Reflection;
- namespace bitforum.Helpers
- {
- public static class Func
- {
- // SaveConfig 함수는 Config 모델에 대한 정보를 저장하는 함수
- public static void SaveConfig<T>(T request, Action<Config> saveAction)
- {
- var properties = typeof(T).GetProperties();
- foreach (var property in properties)
- {
- // 속성 Key 이름
- var key = property.GetCustomAttribute<BindPropertyAttribute>()?.Name ?? property.Name;
- // 속성 값
- var value = property.GetValue(request)?.ToString();
- // 속성 표시 이름
- var displayName = property.GetCustomAttribute<DisplayAttribute>()?.Name ?? key;
- saveAction(new Config
- {
- Key = key,
- Value = value?.ToString(),
- Description = displayName
- });
- }
- }
- // Config 값 조회
- public static string GetConfig(this Dictionary<string, string> dictionary, string key)
- {
- if (dictionary != null && dictionary.ContainsKey(key))
- {
- return dictionary[key];
- }
- return string.Empty;
- }
- // 날짜 포맷 조회
- public static string GetDateAt(this DateTime? dateTime, string format = "yyyy.MM.dd HH:mm:ss")
- {
- return dateTime.HasValue ? dateTime.Value.ToString(format) : string.Empty;
- }
- }
- }
|