• [C#] 常用工具类——应用程序属性信息访问类


    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Reflection;
    namespace Utils
    {
        /// <summary>
        /// <para> </para>
        ///  常用工具类——应用程序属性信息访问类
        /// <para> -------------------------------------------</para>
        /// <para> GetAssemblyTitle:获取应用程序集的标题</para>
        /// <para> GetAssemblyProduct:获取应用程序产品名称</para>
        /// <para> GetAssemblyVersion:获取应用程序版本</para>
        /// <para> GetAssemblyDescription:获取应用程序说明</para>
        /// <para> GetAssemblyCopyright:获取应用程序版权信息</para>
        /// <para> GetAssemblyCompany:获取应用程序公司名称</para>
        /// <para> GetAssemblyAppFullName:获取应用程序显示名称</para>
        /// </summary>
        public class AssemblyHelper
        {
            #region 获取应用程序集的标题
            /// <summary>
            /// 获取应用程序集的标题
            /// </summary>
            /// <returns></returns>
            public static string GetAssemblyTitle()
            {
                object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyTitleAttribute), false);
                if (attributes.Length > 0)
                {
                    AssemblyTitleAttribute titleAttribute = (AssemblyTitleAttribute)attributes[0];
                    if (titleAttribute.Title != "")
                    {
                        return titleAttribute.Title;
                    }
                }
                return System.IO.Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().CodeBase);
            }
            #endregion
            #region 获取应用程序产品名称
            /// <summary>
            /// 获取应用程序产品名称
            /// </summary>
            /// <returns></returns>
            public static string GetAssemblyProduct()
            {
                object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyProductAttribute), false);
                if (attributes.Length == 0)
                {
                    return "";
                }
                return ((AssemblyProductAttribute)attributes[0]).Product;
            }
            #endregion
            #region 获取应用程序版本
            /// <summary>
            /// 获取应用程序版本
            /// </summary>
            /// <returns></returns>
            public static string GetAssemblyVersion()
            {
                return Assembly.GetExecutingAssembly().GetName().Version.ToString();
            }
            #endregion
            #region 获取应用程序说明
            /// <summary>
            /// 获取应用程序说明
            /// </summary>
            /// <returns></returns>
            public static string GetAssemblyDescription()
            {
                object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyDescriptionAttribute), false);
                if (attributes.Length == 0)
                {
                    return "";
                }
                return ((AssemblyDescriptionAttribute)attributes[0]).Description;
            }
            #endregion
            #region 获取应用程序版权信息
            /// <summary>
            /// 获取应用程序版权信息
            /// </summary>
            /// <returns></returns>
            public static string GetAssemblyCopyright()
            {
                object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false);
                if (attributes.Length == 0)
                {
                    return "";
                }
                return ((AssemblyCopyrightAttribute)attributes[0]).Copyright;
            }
            #endregion
            #region 获取应用程序公司名称
            /// <summary>
            /// 获取应用程序公司名称
            /// </summary>
            /// <returns></returns>
            public static string GetAssemblyCompany()
            {
                object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCompanyAttribute), false);
                if (attributes.Length == 0)
                {
                    return "";
                }
                return ((AssemblyCompanyAttribute)attributes[0]).Company;
            }
            #endregion
            #region 获取应用程序显示名称
            /// <summary>
            /// 获取应用程序显示名称
            /// </summary>
            /// <returns></returns>
            public static string GetAssemblyAppFullName()
            {
                return Assembly.GetExecutingAssembly().FullName.ToString();
            }
            #endregion
        }
    }
    

      

  • 相关阅读:
    mysql基本命令(转)
    查找大文件
    vim/vi 复制,删除,粘贴,查找,替换
    redhat 6用yum方式安装nginx
    解决yum安装时 Cannot retrieve repository metadata (repomd.xml) for repository
    RHEL6解决无法使用YUM源问题(转)
    Linux 信号概念
    Linux 进程通信(共享内存区)
    Linux 进程通信(有名管道)
    Linux 进程通信(无名管道)
  • 原文地址:https://www.cnblogs.com/51net/p/3916039.html
Copyright © 2020-2023  润新知