您的位置:首页 > 其它

Assembly attributes in .net

2009-05-05 12:34 225 查看
C#:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Reflection;

namespace AssemblyAttributesCS

{

    class Program

    {

        static void Main(string[] args)

        {

            Assembly a = Assembly.GetExecutingAssembly();

            Type assemblyType = typeof(AssemblyDescriptionAttribute);

            object[] attributes = a.GetCustomAttributes(assemblyType, false);

            if (attributes.Length > 0)

            {

                AssemblyDescriptionAttribute ada = attributes[0] as AssemblyDescriptionAttribute;

                Console.WriteLine("Description is {0}", ada.Description);

            }

            Console.Read();

        }

    }

}

VB.NET:

Imports System.Reflection

Module Module1

    Sub Main()

        Dim a As Assembly = Assembly.GetExecutingAssembly()

        Dim assemblyType As Type = GetType(AssemblyDescriptionAttribute)

        Dim attributes As Object() = a.GetCustomAttributes(assemblyType, False)

        If attributes.Length > 0 Then

            Dim ada As AssemblyDescriptionAttribute = CType(attributes(0), AssemblyDescriptionAttribute)

            Console.WriteLine("Description is {0}", ada.Description)

        End If

        Console.Read()

    End Sub

End Module

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: