Export (0) Print
Expand All

ProgIdAttribute Class

Allows the user to specify the ProgID of a class.

Namespace: System.Runtime.InteropServices
Assembly: mscorlib (in mscorlib.dll)

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

You can apply this attribute to classes.

ProgIDs are automatically generated for a class by combining the namespace with the type name. This can produce an invalid ProgID however, as ProgIDs are limited to 39 characters and can contain no punctuation other than a period. In such case, a ProgID can be manually assigned to the class using ProgIdAttribute.

The following example demonstrates how to apply ProgIdAttribute on a class. The application then gets all attributes of MyClass, and prints the Value property of ProgIdAttribute.

[ClassInterface(ClassInterfaceType.AutoDispatch)]
[ProgId("InteropSample.MyClass")]
public class MyClass
{
    public MyClass() {}
}

class TestApplication
{      
   public static void Main()
   {
      try
      {
         AttributeCollection attributes;
         attributes = TypeDescriptor.GetAttributes(typeof(MyClass));
         ProgIdAttribute progIdAttributeObj = (ProgIdAttribute)attributes[typeof(ProgIdAttribute)];
         Console.WriteLine("ProgIdAttribute's value is set to : " + progIdAttributeObj.Value);
      }         
      catch(Exception e)
      {
         Console.WriteLine("Exception : " + e.Message);
      }
   }
}

/** @attribute ClassInterface(ClassInterfaceType.AutoDispatch)
 */
/** @attribute ProgId("InteropSample.MyClass")
 */
public class MyClass
{
    public MyClass()
    {
    } //MyClass
} //MyClass

class TestApplication
{
    public static void main(String[] args)
    {
        try {
            AttributeCollection attributes;
            attributes = TypeDescriptor.GetAttributes(MyClass.class.ToType());
            ProgIdAttribute progIdAttributeObj = (ProgIdAttribute)
                (attributes.get_Item(ProgIdAttribute.class.ToType()));
            Console.WriteLine("ProgIdAttribute's value is set to : " 
                + progIdAttributeObj.get_Value());
        }
        catch (System.Exception e) {
            Console.WriteLine("Exception : " + e.get_Message());
        }
    } //main
} //TestApplication

System.Object
   System.Attribute
    System.Runtime.InteropServices.ProgIdAttribute

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 Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft