Export (0) Print
Expand All

AssemblyCopyrightAttribute Class

Defines a copyright custom attribute for an assembly manifest.

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

[AttributeUsageAttribute(AttributeTargets.Assembly, Inherited=false)] 
[ComVisibleAttribute(true)] 
public sealed class AssemblyCopyrightAttribute : Attribute
/** @attribute AttributeUsageAttribute(AttributeTargets.Assembly, Inherited=false) */ 
/** @attribute ComVisibleAttribute(true) */ 
public final class AssemblyCopyrightAttribute extends Attribute
AttributeUsageAttribute(AttributeTargets.Assembly, Inherited=false) 
ComVisibleAttribute(true) 
public final class AssemblyCopyrightAttribute extends Attribute

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");

   }
}

import System.*;
import System.Threading.*;
import System.Reflection.*;
import System.Reflection.Emit.*;
import System.Resources.*;

public class MyEmitTest
{
    public static void main(String[] args)
    {
        AssemblyBuilder myAssembly = (AssemblyBuilder)(CreateAssembly(
            System.Threading.Thread.GetDomain()).get_Assembly());
        IResourceWriter myResourceWriter = 
            myAssembly.DefineResource("myResourceFile", 
            "A sample Resource File", "MyResourceFile.resources");

        myResourceWriter.AddResource("AddResource test", "Test resource added");

        // Define unmanaged version information resources.
        myAssembly.DefineVersionInfoResource();
        myAssembly.Save("MyEmittedAssembly.dll");
    } //main

    // Create the callee transient dynamic assembly.
    private static Type CreateAssembly(AppDomain myDomain) 
    {
        AssemblyName myAssemblyName =  new AssemblyName();
        myAssemblyName.set_Name("MyEmittedAssembly");
        AssemblyBuilder myAssembly = myDomain.DefineDynamicAssembly(
            myAssemblyName, AssemblyBuilderAccess.Save);

        // Set Company Attribute to the assembly.
        Type companyAttribute = AssemblyCompanyAttribute.class.ToType();
        ConstructorInfo myConstructorInfo1 = companyAttribute.GetConstructor(
            new Type[]{String.class.ToType()});
        CustomAttributeBuilder attributeBuilder1 =  
            new CustomAttributeBuilder(myConstructorInfo1, 
            new Object[]{"Microsoft Corporation"});
        myAssembly.SetCustomAttribute(attributeBuilder1);

        // Set Copyright Attribute to the assembly.
        Type copyrightAttribute = AssemblyCopyrightAttribute.class.ToType();
        ConstructorInfo myConstructorInfo2 = copyrightAttribute.GetConstructor(
            new Type[]{String.class.ToType()});
        CustomAttributeBuilder attributeBuilder2 = 
            new CustomAttributeBuilder(myConstructorInfo2, 
            new Object[]{"@Copyright Microsoft Corp. 1990-2001"});
        myAssembly.SetCustomAttribute(attributeBuilder2);

        ModuleBuilder myModule = myAssembly.DefineDynamicModule("EmittedModule",
            "EmittedModule.mod");

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

        // Define the Display method.
        MethodBuilder myMethod = helloWorldClass.DefineMethod("Display", 
            MethodAttributes.Public, String.class.ToType(), null);

        // 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();
    } //CreateAssembly
} //MyEmitTest

System.Object
   System.Attribute
    System.Reflection.AssemblyCopyrightAttribute

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

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft