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 request, Action saveAction) { var properties = typeof(T).GetProperties(); foreach (var property in properties) { // 속성 Key 이름 var key = property.GetCustomAttribute()?.Name ?? property.Name; // 속성 값 var value = property.GetValue(request)?.ToString(); // 속성 표시 이름 var displayName = property.GetCustomAttribute()?.Name ?? key; saveAction(new Config { Key = key, Value = value?.ToString(), Description = displayName }); } } // Config 값 조회 public static string GetConfig(this Dictionary 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; } } }