using System.Reflection;
namespace XFEExtension.NetCore.ProfileExtension;
///
/// 配置文件信息
///
/// 配置文件类型
/// 配置文件储存位置
/// 配置文件描述
public class ProfileInfo(Type profileType, string path = "", string description = "")
{
///
/// 配置文件类型
///
public Type Profile { get; init; } = profileType;
///
/// 配置文件储存位置
///
public string Path { get; init; } = path == "" ? $"{((XFEProfile.ProfilesRootPath[^1] == '/' || XFEProfile.ProfilesRootPath[^1] == '\\') ? $"{XFEProfile.ProfilesRootPath}{profileType.Name}.xfe" : $"{XFEProfile.ProfilesRootPath}/{profileType.Name}.xfe")}" : path;
///
/// 配置文件描述
///
public string? Description { get; set; } = description;
///
/// 配置文件属性列表
///
public List PropertiesInfo { get; init; } = GetPropertiesWithProfileAttribute(profileType);
internal static List GetPropertiesWithProfileAttribute(Type type)
{
var profileEntryList = new List();
foreach (var propertyInfo in type.GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static))
if (propertyInfo.GetCustomAttribute() is not null)
profileEntryList.Add(new ProfileEntryInfo(propertyInfo.Name, propertyInfo));
return profileEntryList;
}
///
/// 配置文件类型生成
///
///
public static implicit operator ProfileInfo(Type profileType) => new(profileType);
}