using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;

namespace HuanMeng.DotNetCore.Utility.AssemblyHelper
{
    /// <summary>
    /// 用于检索程序集信息的辅助类。
    /// </summary>
    public static class AssemblyInfoHelper
    {
        /// <summary>
        /// 从正在执行的程序集检索各种属性，并返回一个 AssemblyInfo 对象。
        /// </summary>
        /// <returns>包含程序集属性的 AssemblyInfo 对象。</returns>
        public static AssemblyInfo GetAssemblyInfo()
        {
            // 获取正在执行的程序集
            Assembly assembly = Assembly.GetExecutingAssembly();

            // 创建并填充 AssemblyInfo 对象的相关属性
            var assemblyInfo = new AssemblyInfo
            {
                Version = assembly.GetName().Version.ToString(),
                FileVersion = assembly.GetCustomAttributes<AssemblyFileVersionAttribute>().FirstOrDefault()?.Version ?? "",
                AssemblyVersion = assembly.GetCustomAttributes<AssemblyVersionAttribute>().FirstOrDefault()?.Version ?? "",
                InformationalVersion = assembly.GetCustomAttributes<AssemblyInformationalVersionAttribute>().FirstOrDefault()?.InformationalVersion ?? "",
                //Company = assembly.GetCustomAttributes<AssemblyCompanyAttribute>().FirstOrDefault()?.Company ?? "",
                //Product = assembly.GetCustomAttributes<AssemblyProductAttribute>().FirstOrDefault()?.Product ?? "",
                Copyright = assembly.GetCustomAttributes<AssemblyCopyrightAttribute>().FirstOrDefault()?.Copyright ?? "",
                Description = assembly.GetCustomAttributes<AssemblyDescriptionAttribute>().FirstOrDefault()?.Description ?? ""
            };

            return assemblyInfo;
        }
    }
}
