How to get all the information required by "AboutDialog".

本文介绍了如何在桌面应用程序中实现关于产品信息的显示,包括产品名称、版本等关键属性的获取方法。

Usually, while designing a desktop application, we need a "AboutDialog" to show the product information, such as "Product Name", "Version" etc. Here are the code about it:

 

1. Get Assembly Title 

ExpandedBlockStart.gifView Code
 1         private string AssemblyTitle
 2         {
 3             get
 4             {
 5                 object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyTitleAttribute), false);
 6                 if (attributes.Length > 0)
 7                 {
 8                     AssemblyTitleAttribute titleAttribute = (AssemblyTitleAttribute)attributes[0];
 9                     if (titleAttribute.Title != "")
10                     {
11                         return titleAttribute.Title;
12                     }
13                 }
14                 return System.IO.Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().CodeBase);
15             }
16         }

 

2. Get Assembly Version

ExpandedBlockStart.gifView Code
        private static string GetProductVersion()
        {
            string version = String.Empty;

            object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyInformationalVersionAttribute), false);
            if (attributes.Length == 0)
            {
                //just in case fall back to the regular dll version which is always there.
                version = Assembly.GetExecutingAssembly().GetName().Version.ToString();
            }
            else
            {
                version = ((AssemblyInformationalVersionAttribute)attributes[0]).InformationalVersion;
            }

            return version;
        }

 

3. Get Development Company

ExpandedBlockStart.gifView Code
        private string AssemblyCompany
        {
            get
            {
                object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCompanyAttribute), false);
                if (attributes.Length == 0)
                {
                    return "";
                }
                return ((AssemblyCompanyAttribute)attributes[0]).Company;
            }
        }


4. Get Product Information

ExpandedBlockStart.gifView Code
        private string AssemblyProduct
        {
            get
            {
                object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyProductAttribute), false);
                if (attributes.Length == 0)
                {
                    return "";
                }
                return ((AssemblyProductAttribute)attributes[0]).Product;
            }
        }


 

转载于:https://www.cnblogs.com/craystall/archive/2012/08/08/2628308.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值