zoukankan      html  css  js  c++  java
  • 获取程序集信息

    /// <summary>
    /// 返回程序集的Title
    /// </summary>
    /// <param name="assembly">程序集</param>
    /// <returns>Title</returns>
    public static  string GetAssemblyTitle(Assembly assembly)
    {
        string title = GetAssemblyInfo<AssemblyTitleAttribute>(assembly );
        if(string.IsNullOrEmpty(title))
        {
            return System.IO.Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().CodeBase);
        }
        return title;
    }
    
    /// <summary>
    /// 返回程序集的版本信息
    /// </summary>
    /// <param name="assembly">程序集</param>
    /// <returns>版本信息</returns>
    public static string GetAssemblyVersion(Assembly assembly)
    {
        return assembly.GetName().Version.ToString();
    }
    /// <summary>
    /// 返回程序集的文本说明
    /// </summary>
    /// <param name="assembly">程序集</param>
    /// <returns>文本说明</returns>
    public static string GetAssemblyDescription(Assembly assembly)
    {
        return GetAssemblyInfo<AssemblyDescriptionAttribute>(assembly);
    }
    
    /// <summary>
    /// 返回程序集的产品名
    /// </summary>
    /// <param name="assembly">程序集</param>
    /// <returns>产品名</returns>
    public static string GetAssemblyProduct(Assembly assembly)
    {
        return GetAssemblyInfo<AssemblyProductAttribute>(assembly);
    }
    
    /// <summary>
    /// 返回程序集的版权
    /// </summary>
    /// <param name="assembly">程序集</param>
    /// <returns>版权</returns>
    public static string GetAssemblyCopyright(Assembly assembly)
    {
        return GetAssemblyInfo<AssemblyCopyrightAttribute>(assembly);
    }
    
    /// <summary>
    /// 返回程序集的公司名称
    /// </summary>
    /// <param name="assembly">程序集</param>
    /// <returns>公司名称</returns>
    public static string GetAssemblyCompany(Assembly assembly)
    {
        return GetAssemblyInfo<AssemblyCompanyAttribute>(assembly);
    }
    
    /// <summary>
    /// 获取程序集的相关信息
    /// </summary>
    /// <typeparam name="TAttribute">特性类型</typeparam>
    /// <param name="assembly">程序集</param>
    /// <returns>返回的信息。如果没有找到,则返回特性类型名称;如果不具有相关特性,则返回空白字符串</returns>
    public static string GetAssemblyInfo<TAttribute>(Assembly assembly)where TAttribute : Attribute
    {
        Type type =typeof(TAttribute);
        object[] attributes = assembly.GetCustomAttributes(type, false);
        if(attributes!=null&& attributes.Length>0)
        {
            PropertyInfo[]  propertyInfos = type.GetProperties();
            foreach (PropertyInfo property in propertyInfos)
            {
                if (typeof(string).Equals(property.PropertyType))
                {
                    return property.GetValue(attributes[0]).ToString();
                }
            }
        }
        return string.Empty;
    }
  • 相关阅读:
    凹凸函数
    HashMap数据类型使用注意不能使用基本数据类型
    Tomcat部署发布JSP应用程序的三种方法
    Ubuntu忘记密码,进不了系统的解决方法
    matlab之运算符及其优先级
    java和tomcat配置
    MySQL中 MySQL X.X Command Line Client 一闪而过
    Pearson(皮尔逊)相关系数
    CG, DCG, NDCG
    C#中ListBox中SelectedItem使用注意
  • 原文地址:https://www.cnblogs.com/pilgrim/p/11191681.html
Copyright © 2011-2022 走看看