AssemblyTitleAttribute Класс
Определение
Важно!
Некоторые сведения относятся к предварительной версии продукта, в которую до выпуска могут быть внесены существенные изменения. Майкрософт не предоставляет никаких гарантий, явных или подразумеваемых, относительно приведенных здесь сведений.
Задает описание сборки.
public ref class AssemblyTitleAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.Assembly, Inherited=false)]
public sealed class AssemblyTitleAttribute : Attribute
[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple=false)]
public sealed class AssemblyTitleAttribute : Attribute
[System.AttributeUsage(System.AttributeTargets.Assembly, Inherited=false)]
[System.Runtime.InteropServices.ComVisible(true)]
public sealed class AssemblyTitleAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Assembly, Inherited=false)>]
type AssemblyTitleAttribute = class
inherit Attribute
[<System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple=false)>]
type AssemblyTitleAttribute = class
inherit Attribute
[<System.AttributeUsage(System.AttributeTargets.Assembly, Inherited=false)>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type AssemblyTitleAttribute = class
inherit Attribute
Public NotInheritable Class AssemblyTitleAttribute
Inherits Attribute
- Наследование
- Атрибуты
Примеры
В следующем примере показано, как добавить атрибуты, включая атрибут , в AssemblyTitleAttribute динамическую сборку. В примере сборка сохраняется на диск, а значение атрибута можно просмотреть с помощью диалогового окна Свойства файла Windows .
using System;
using System.Reflection;
using System.Reflection.Emit;
class Example
{
public static void Main()
{
AssemblyName assemName = new AssemblyName();
assemName.Name = "EmittedAssembly";
// Create a dynamic assembly in the current application domain,
// specifying that the assembly is to be saved.
//
AssemblyBuilder myAssembly =
AppDomain.CurrentDomain.DefineDynamicAssembly(assemName,
AssemblyBuilderAccess.Save);
// To apply an attribute to a dynamic assembly, first get the
// attribute type. The AssemblyFileVersionAttribute sets the
// File Version field on the Version tab of the Windows file
// properties dialog.
//
Type attributeType = typeof(AssemblyFileVersionAttribute);
// To identify the constructor, use an array of types representing
// the constructor's parameter types. This ctor takes a string.
//
Type[] ctorParameters = { typeof(string) };
// Get the constructor for the attribute.
//
ConstructorInfo ctor = attributeType.GetConstructor(ctorParameters);
// Pass the constructor and an array of arguments (in this case,
// an array containing a single string) to the
// CustomAttributeBuilder constructor.
//
object[] ctorArgs = { "2.0.3033.0" };
CustomAttributeBuilder attribute =
new CustomAttributeBuilder(ctor, ctorArgs);
// Finally, apply the attribute to the assembly.
//
myAssembly.SetCustomAttribute(attribute);
// The pattern described above is used to create and apply
// several more attributes. As it happens, all these attributes
// have a constructor that takes a string, so the same ctorArgs
// variable works for all of them.
// The AssemblyTitleAttribute sets the Description field on
// the General tab and the Version tab of the Windows file
// properties dialog.
//
attributeType = typeof(AssemblyTitleAttribute);
ctor = attributeType.GetConstructor(ctorParameters);
ctorArgs = new object[] { "The Application Title" };
attribute = new CustomAttributeBuilder(ctor, ctorArgs);
myAssembly.SetCustomAttribute(attribute);
// The AssemblyCopyrightAttribute sets the Copyright field on
// the Version tab.
//
attributeType = typeof(AssemblyCopyrightAttribute);
ctor = attributeType.GetConstructor(ctorParameters);
ctorArgs = new object[] { "© My Example Company 1991-2005" };
attribute = new CustomAttributeBuilder(ctor, ctorArgs);
myAssembly.SetCustomAttribute(attribute);
// The AssemblyDescriptionAttribute sets the Comment item.
//
attributeType = typeof(AssemblyDescriptionAttribute);
ctor = attributeType.GetConstructor(ctorParameters);
attribute = new CustomAttributeBuilder(ctor,
new object[] { "This is a comment." });
myAssembly.SetCustomAttribute(attribute);
// The AssemblyCompanyAttribute sets the Company item.
//
attributeType = typeof(AssemblyCompanyAttribute);
ctor = attributeType.GetConstructor(ctorParameters);
attribute = new CustomAttributeBuilder(ctor,
new object[] { "My Example Company" });
myAssembly.SetCustomAttribute(attribute);
// The AssemblyProductAttribute sets the Product Name item.
//
attributeType = typeof(AssemblyProductAttribute);
ctor = attributeType.GetConstructor(ctorParameters);
attribute = new CustomAttributeBuilder(ctor,
new object[] { "My Product Name" });
myAssembly.SetCustomAttribute(attribute);
// Define the assembly's only module. For a single-file assembly,
// the module name is the assembly name.
//
ModuleBuilder myModule =
myAssembly.DefineDynamicModule(assemName.Name,
assemName.Name + ".exe");
// No types or methods are created for this example.
// Define the unmanaged version information resource, which
// contains the attribute informaion applied earlier, and save
// the assembly. Use the Windows Explorer to examine the properties
// of the .exe file.
//
myAssembly.DefineVersionInfoResource();
myAssembly.Save(assemName.Name + ".exe");
}
}
Imports System.Reflection
Imports System.Reflection.Emit
Module Example
Sub Main()
Dim assemName As New AssemblyName()
assemName.Name = "EmittedAssembly"
' Create a dynamic assembly in the current application domain,
' specifying that the assembly is to be saved.
'
Dim myAssembly As AssemblyBuilder = _
AppDomain.CurrentDomain.DefineDynamicAssembly(assemName, _
AssemblyBuilderAccess.Save)
' To apply an attribute to a dynamic assembly, first get the
' attribute type. The AssemblyFileVersionAttribute sets the
' File Version field on the Version tab of the Windows file
' properties dialog.
'
Dim attributeType As Type = GetType(AssemblyFileVersionAttribute)
' To identify the constructor, use an array of types representing
' the constructor's parameter types. This ctor takes a string.
'
Dim ctorParameters() As Type = { GetType(String) }
' Get the constructor for the attribute.
'
Dim ctor As ConstructorInfo = _
attributeType.GetConstructor(ctorParameters)
' Pass the constructor and an array of arguments (in this case,
' an array containing a single string) to the
' CustomAttributeBuilder constructor.
'
Dim ctorArgs() As Object = { "2.0.3033.0" }
Dim attribute As New CustomAttributeBuilder(ctor, ctorArgs)
' Finally, apply the attribute to the assembly.
'
myAssembly.SetCustomAttribute(attribute)
' The pattern described above is used to create and apply
' several more attributes. As it happens, all these attributes
' have a constructor that takes a string, so the same ctorArgs
' variable works for all of them.
' The AssemblyTitleAttribute sets the Description field on
' the General tab and the Version tab of the Windows file
' properties dialog.
'
attributeType = GetType(AssemblyTitleAttribute)
ctor = attributeType.GetConstructor(ctorParameters)
ctorArgs = New Object() { "The Application Title" }
attribute = New CustomAttributeBuilder(ctor, ctorArgs)
myAssembly.SetCustomAttribute(attribute)
' The AssemblyCopyrightAttribute sets the Copyright field on
' the Version tab.
'
attributeType = GetType(AssemblyCopyrightAttribute)
ctor = attributeType.GetConstructor(ctorParameters)
ctorArgs = New Object() { "© My Example Company 1991-2005" }
attribute = New CustomAttributeBuilder(ctor, ctorArgs)
myAssembly.SetCustomAttribute(attribute)
' The AssemblyDescriptionAttribute sets the Comment item.
'
attributeType = GetType(AssemblyDescriptionAttribute)
ctor = attributeType.GetConstructor(ctorParameters)
attribute = New CustomAttributeBuilder(ctor, _
New Object() { "This is a comment." })
myAssembly.SetCustomAttribute(attribute)
' The AssemblyCompanyAttribute sets the Company item.
'
attributeType = GetType(AssemblyCompanyAttribute)
ctor = attributeType.GetConstructor(ctorParameters)
attribute = New CustomAttributeBuilder(ctor, _
New Object() { "My Example Company" })
myAssembly.SetCustomAttribute(attribute)
' The AssemblyProductAttribute sets the Product Name item.
'
attributeType = GetType(AssemblyProductAttribute)
ctor = attributeType.GetConstructor(ctorParameters)
attribute = New CustomAttributeBuilder(ctor, _
New Object() { "My Product Name" })
myAssembly.SetCustomAttribute(attribute)
' Define the assembly's only module. For a single-file assembly,
' the module name is the assembly name.
'
Dim myModule As ModuleBuilder = _
myAssembly.DefineDynamicModule(assemName.Name, _
assemName.Name & ".exe")
' No types or methods are created for this example.
' Define the unmanaged version information resource, which
' contains the attribute informaion applied earlier, and save
' the assembly. Use the Windows Explorer to examine the properties
' of the .exe file.
'
myAssembly.DefineVersionInfoResource()
myAssembly.Save(assemName.Name & ".exe")
End Sub
End Module
Комментарии
Заголовок сборки — это понятное имя, которое может содержать пробелы.
В Windows Vista сведения, указанные для этого атрибута, отображаются на вкладке Сведения диалогового окна Свойства файла Windows для сборки. Имя свойства — File description. В Windows XP эти сведения отображаются на вкладке Версия диалогового окна Свойства файла Windows .
Конструкторы
AssemblyTitleAttribute(String) |
Инициализирует новый экземпляр класса AssemblyTitleAttribute. |
Свойства
Title |
Возвращает сведения о заголовке сборки. |
TypeId |
В случае реализации в производном классе возвращает уникальный идентификатор для этого атрибута Attribute. (Унаследовано от Attribute) |
Методы
Equals(Object) |
Возвращает значение, показывающее, равен ли экземпляр указанному объекту. (Унаследовано от Attribute) |
GetHashCode() |
Возвращает хэш-код данного экземпляра. (Унаследовано от Attribute) |
GetType() |
Возвращает объект Type для текущего экземпляра. (Унаследовано от Object) |
IsDefaultAttribute() |
При переопределении в производном классе указывает, является ли значение этого экземпляра значением по умолчанию для производного класса. (Унаследовано от Attribute) |
Match(Object) |
При переопределении в производном классе возвращает значение, указывающее, является ли этот экземпляр равным заданному объекту. (Унаследовано от Attribute) |
MemberwiseClone() |
Создает неполную копию текущего объекта Object. (Унаследовано от Object) |
ToString() |
Возвращает строку, представляющую текущий объект. (Унаследовано от Object) |
Явные реализации интерфейса
_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr) |
Сопоставляет набор имен соответствующему набору идентификаторов диспетчеризации. (Унаследовано от Attribute) |
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) |
Возвращает сведения о типе объекта, которые можно использовать для получения сведений о типе интерфейса. (Унаследовано от Attribute) |
_Attribute.GetTypeInfoCount(UInt32) |
Возвращает количество предоставляемых объектом интерфейсов для доступа к сведениям о типе (0 или 1). (Унаследовано от Attribute) |
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) |
Предоставляет доступ к открытым свойствам и методам объекта. (Унаследовано от Attribute) |