Esempio n. 1
0
        /// <summary>
        /// 어셈블리 버전에 대해 특정 버전 번호를 구합니다.
        /// </summary>
        /// <param name="assembly">구하려는 어셈블리</param>
        /// <returns>어셈블리 버전에 대해 특정 버전 번호를 반환합니다.</returns>
        public static string GetAssemblyVersion(this Assembly assembly)
        {
            AssemblyVersionAttribute assemblyGetCustomAttributes = assembly.GetCustomAttributes <AssemblyVersionAttribute>().FirstOrDefault();

            if (assemblyGetCustomAttributes != null)
            {
                var version = assemblyGetCustomAttributes.Version;

                if (version == string.Empty)
                {
                    version = assembly.GetName().Version.ToString();
                }

                return(version);
            }

            return(string.Empty);
        }
Esempio n. 2
0
 private string GetAssembly(Type type)
 {
     if (type.ToString() == "System.Reflection.AssemblyVersionAttribute")
     {//程序集版本号,要用这个方法获取,无法用下边的方法获取,原因不知
         return(System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString());
     }
     object[] attributes = System.Reflection.Assembly.GetExecutingAssembly().GetCustomAttributes(type, false);
     if (attributes.Length > 0)
     {
         if (type.ToString() == "System.Reflection.AssemblyCompanyAttribute")
         {
             #region//公司
             System.Reflection.AssemblyCompanyAttribute company = (System.Reflection.AssemblyCompanyAttribute)attributes[0];
             if (company.Company != "")
             {
                 return(company.Company);
             }
             #endregion
         }
         else if (type.ToString() == "System.Reflection.AssemblyCopyrightAttribute")
         {
             #region//版权
             System.Reflection.AssemblyCopyrightAttribute company = (System.Reflection.AssemblyCopyrightAttribute)attributes[0];
             if (company.Copyright != "")
             {
                 return(company.Copyright);
             }
             #endregion
         }
         else if (type.ToString() == "System.Reflection.AssemblyTitleAttribute")
         {
             #region//标题
             System.Reflection.AssemblyTitleAttribute company = (System.Reflection.AssemblyTitleAttribute)attributes[0];
             if (company.Title != "")
             {
                 return(company.Title);
             }
             #endregion
         }
         else if (type.ToString() == "System.Reflection.AssemblyDescriptionAttribute")
         {
             #region//备注
             System.Reflection.AssemblyDescriptionAttribute company = (System.Reflection.AssemblyDescriptionAttribute)attributes[0];
             if (company.Description != "")
             {
                 return(company.Description);
             }
             #endregion
         }
         else if (type.ToString() == "System.Reflection.AssemblyProductAttribute")
         {
             #region//产品名称
             System.Reflection.AssemblyProductAttribute company = (System.Reflection.AssemblyProductAttribute)attributes[0];
             if (company.Product != "")
             {
                 return(company.Product);
             }
             #endregion
         }
         else if (type.ToString() == "System.Reflection.AssemblyTrademarkAttribute")
         {
             #region//商标
             System.Reflection.AssemblyTrademarkAttribute company = (System.Reflection.AssemblyTrademarkAttribute)attributes[0];
             if (company.Trademark != "")
             {
                 return(company.Trademark);
             }
             #endregion
         }
         else if (type.ToString() == "System.Reflection.AssemblyConfigurationAttribute")
         {
             #region//获取程序集配置信息,具体什么内容,不清楚
             System.Reflection.AssemblyConfigurationAttribute company = (System.Reflection.AssemblyConfigurationAttribute)attributes[0];
             if (company.Configuration != "")
             {
                 return(company.Configuration);
             }
             #endregion
         }
         else if (type.ToString() == "System.Reflection.AssemblyCultureAttribute")
         {
             #region//获取属性化程序集支持的区域性,具体什么内容,不清楚
             System.Reflection.AssemblyCultureAttribute company = (System.Reflection.AssemblyCultureAttribute)attributes[0];
             if (company.Culture != "")
             {
                 return(company.Culture);
             }
             #endregion
         }
         else if (type.ToString() == "System.Reflection.AssemblyVersionAttribute")
         {
             #region//程序集版本号
             System.Reflection.AssemblyVersionAttribute company = (System.Reflection.AssemblyVersionAttribute)attributes[0];
             if (company.Version != "")
             {
                 return(company.Version);
             }
             #endregion
         }
         else if (type.ToString() == "System.Reflection.AssemblyFileVersionAttribute")
         {
             #region//文件版本号
             System.Reflection.AssemblyFileVersionAttribute company = (System.Reflection.AssemblyFileVersionAttribute)attributes[0];
             if (company.Version != "")
             {
                 return(company.Version);
             }
             #endregion
         }
         else if (type.ToString() == "System.Reflection.AssemblyInformationalVersionAttribute")
         {
             #region//产品版本号
             System.Reflection.AssemblyInformationalVersionAttribute company = (System.Reflection.AssemblyInformationalVersionAttribute)attributes[0];
             if (company.InformationalVersion != "")
             {
                 return(company.InformationalVersion);
             }
             #endregion
         }
     }
     //如果没有  属性,或者  属性为一个空字符串,则返回 .exe 的名称
     return(System.IO.Path.GetFileNameWithoutExtension(System.Reflection.Assembly.GetExecutingAssembly().CodeBase));
 }