Export (0) Print
Expand All

AssemblyCompanyAttribute Class

Defines a company name custom attribute for an assembly manifest.

System::Object
  System::Attribute
    System.Reflection::AssemblyCompanyAttribute

Namespace:  System.Reflection
Assembly:  mscorlib (in mscorlib.dll)

[AttributeUsageAttribute(AttributeTargets::Assembly, Inherited = false)]
[ComVisibleAttribute(true)]
public ref class AssemblyCompanyAttribute sealed : public Attribute

The AssemblyCompanyAttribute type exposes the following members.

  NameDescription
Public methodSupported by the XNA FrameworkSupported by Portable Class LibraryAssemblyCompanyAttributeInitializes a new instance of the AssemblyCompanyAttribute class.
Top

  NameDescription
Public propertySupported by the XNA FrameworkSupported by Portable Class LibraryCompanyGets company name information.
Public propertyTypeIdWhen implemented in a derived class, gets a unique identifier for this Attribute. (Inherited from Attribute.)
Top

  NameDescription
Public methodSupported by the XNA FrameworkSupported by Portable Class LibraryEqualsInfrastructure. Returns a value that indicates whether this instance is equal to a specified object. (Inherited from Attribute.)
Public methodSupported by the XNA FrameworkSupported by Portable Class LibraryGetHashCodeReturns the hash code for this instance. (Inherited from Attribute.)
Public methodSupported by the XNA FrameworkSupported by Portable Class LibraryGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodIsDefaultAttributeWhen overridden in a derived class, indicates whether the value of this instance is the default value for the derived class. (Inherited from Attribute.)
Public methodSupported by the XNA FrameworkMatchWhen overridden in a derived class, returns a value that indicates whether this instance equals a specified object. (Inherited from Attribute.)
Public methodSupported by the XNA FrameworkSupported by Portable Class LibraryToStringReturns a string that represents the current object. (Inherited from Object.)
Top

  NameDescription
Explicit interface implemetationPrivate method_Attribute::GetIDsOfNamesMaps a set of names to a corresponding set of dispatch identifiers. (Inherited from Attribute.)
Explicit interface implemetationPrivate method_Attribute::GetTypeInfoRetrieves the type information for an object, which can be used to get the type information for an interface. (Inherited from Attribute.)
Explicit interface implemetationPrivate method_Attribute::GetTypeInfoCountRetrieves the number of type information interfaces that an object provides (either 0 or 1). (Inherited from Attribute.)
Explicit interface implemetationPrivate method_Attribute::InvokeProvides access to properties and methods exposed by an object. (Inherited from Attribute.)
Top

The following example shows how to apply attributes, including the AssemblyCompanyAttribute attribute, to a dynamic assembly. The example saves the assembly to disk, and the attribute value can be viewed by using the Windows File Properties dialog.

using namespace System;
using namespace System::Reflection;
using namespace System::Reflection::Emit;


/*
// Create the callee transient dynamic assembly.
static Type^ CreateAssembly( AppDomain^ myDomain )
{
   AssemblyName^ myAssemblyName = gcnew AssemblyName;
   myAssemblyName->Name = "MyEmittedAssembly";
   AssemblyBuilder^ myAssembly = myDomain->DefineDynamicAssembly( myAssemblyName, AssemblyBuilderAccess::Save );

   // Set Company Attribute to the assembly.
   Type^ companyAttribute = AssemblyCompanyAttribute::typeid;
   array<Type^>^types1 = {String::typeid};
   ConstructorInfo^ myConstructorInfo1 = companyAttribute->GetConstructor( types1 );
   array<Object^>^obj1 = {"Microsoft Corporation"};
   CustomAttributeBuilder^ attributeBuilder1 = gcnew CustomAttributeBuilder( myConstructorInfo1,obj1 );
   myAssembly->SetCustomAttribute( attributeBuilder1 );

   // Set Copyright Attribute to the assembly.
   Type^ copyrightAttribute = AssemblyCopyrightAttribute::typeid;
   array<Type^>^types2 = {String::typeid};
   ConstructorInfo^ myConstructorInfo2 = copyrightAttribute->GetConstructor( types2 );
   array<Object^>^obj2 = {"@Copyright Microsoft Corp. 1990-2001"};
   CustomAttributeBuilder^ attributeBuilder2 = gcnew CustomAttributeBuilder( myConstructorInfo2,obj2 );
   myAssembly->SetCustomAttribute( attributeBuilder2 );
   ModuleBuilder^ myModule = myAssembly->DefineDynamicModule( "EmittedModule", "EmittedModule.mod" );

   // Define a public class named S"HelloWorld" in the assembly.
   TypeBuilder^ helloWorldClass = myModule->DefineType( "HelloWorld", TypeAttributes::Public );

   // Define the Display method.
   MethodBuilder^ myMethod = helloWorldClass->DefineMethod( "Display", MethodAttributes::Public, String::typeid, nullptr );

   // Generate IL for GetGreeting.
   ILGenerator^ methodIL = myMethod->GetILGenerator();
   methodIL->Emit( OpCodes::Ldstr, "Display method get called." );
   methodIL->Emit( OpCodes::Ret );

   // Returns the type HelloWorld.
   return (helloWorldClass->CreateType());
}
*/ 

int main()
{
   AssemblyName^ assemName = gcnew 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 = AssemblyFileVersionAttribute::typeid;

   // To identify the constructor, use an array of types representing 
   // the constructor's parameter types. This ctor takes a string. 
   // 
   array<Type^>^ ctorParameters = { String::typeid };

   // 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. 
   // 
   array<Object^>^ ctorArgs = { "2.0.3033.0" };
   CustomAttributeBuilder^ attribute = 
      gcnew 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 = AssemblyTitleAttribute::typeid;
   ctor = attributeType->GetConstructor(ctorParameters);
   ctorArgs = gcnew array<Object^> { "The Application Title" };
   attribute = gcnew CustomAttributeBuilder(ctor, ctorArgs);
   myAssembly->SetCustomAttribute(attribute);

   // The AssemblyCopyrightAttribute sets the Copyright field on 
   // the Version tab. 
   //
   attributeType = AssemblyCopyrightAttribute::typeid;
   ctor = attributeType->GetConstructor(ctorParameters);
   ctorArgs = gcnew array<Object^> { "� My Example Company 1991-2005" };
   attribute = gcnew CustomAttributeBuilder(ctor, ctorArgs);
   myAssembly->SetCustomAttribute(attribute);

   // The AssemblyDescriptionAttribute sets the Comment item. 
   //
   attributeType = AssemblyDescriptionAttribute::typeid;
   ctor = attributeType->GetConstructor(ctorParameters);
   attribute = gcnew CustomAttributeBuilder(ctor, 
      gcnew array<Object^> { "This is a comment." });
   myAssembly->SetCustomAttribute(attribute);

   // The AssemblyCompanyAttribute sets the Company item. 
   //
   attributeType = AssemblyCompanyAttribute::typeid;
   ctor = attributeType->GetConstructor(ctorParameters);
   attribute = gcnew CustomAttributeBuilder(ctor, 
      gcnew array<Object^> { "My Example Company" });
   myAssembly->SetCustomAttribute(attribute);

   // The AssemblyProductAttribute sets the Product Name item. 
   //
   attributeType = AssemblyProductAttribute::typeid;
   ctor = attributeType->GetConstructor(ctorParameters);
   attribute = gcnew CustomAttributeBuilder(ctor, 
      gcnew array<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");
}

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

XNA Framework

Supported in: 3.0, 2.0, 1.0

Portable Class Library

Supported in: Portable Class Library

Supported in: Windows Phone 8.1

Supported in: Windows Phone Silverlight 8.1

Supported in: Windows Phone Silverlight 8

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Show:
© 2015 Microsoft