ProgIdAttribute Class
Allows the user to specify the ProgID of a class.
For a list of all members of this type, see ProgIdAttribute Members.
System.Object
System.Attribute
System.Runtime.InteropServices.ProgIdAttribute
[Visual Basic] <AttributeUsage(AttributeTargets.Class)> NotInheritable Public Class ProgIdAttribute Inherits Attribute [C#] [AttributeUsage(AttributeTargets.Class)] public sealed class ProgIdAttribute : Attribute [C++] [AttributeUsage(AttributeTargets::Class)] public __gc __sealed class ProgIdAttribute : public Attribute [JScript] public AttributeUsage(AttributeTargets.Class) class ProgIdAttribute extends Attribute
Thread Safety
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Remarks
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.
Example
[Visual Basic, C#, C++] 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.
[Visual Basic] <ClassInterface(ClassInterfaceType.AutoDispatch), ProgId("InteropSample.MyClass")> _ Public Class [MyClass] Public Sub New() End Sub 'New End Class '[MyClass] Class TestApplication Public Shared Sub Main() Try Dim attributes As AttributeCollection attributes = TypeDescriptor.GetAttributes(GetType([MyClass])) Dim progIdAttributeObj As ProgIdAttribute = CType(attributes(GetType(ProgIdAttribute)), ProgIdAttribute) Console.WriteLine(("ProgIdAttribute's value is set to : " + progIdAttributeObj.Value)) Catch e As Exception Console.WriteLine(("Exception : " + e.Message.ToString())) End Try End Sub 'Main End Class 'TestApplication End Namespace 'InteropSample [C#] [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); } } } [C++] [ClassInterface(ClassInterfaceType::AutoDispatch)] [ProgId(S"InteropSample::MyClass")] public __gc class MyClass { public: MyClass() {} }; int main() { try { AttributeCollection* attributes; attributes = TypeDescriptor::GetAttributes(__typeof(MyClass)); ProgIdAttribute* progIdAttributeObj = dynamic_cast<ProgIdAttribute *>(attributes->Item[__typeof(ProgIdAttribute)]); Console::WriteLine(S"ProgIdAttribute's value is set to : {0}", progIdAttributeObj->Value); } catch (Exception* e) { Console::WriteLine(S"Exception : {0}", e->Message); } }
[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button
in the upper-left corner of the page.
Requirements
Namespace: System.Runtime.InteropServices
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family
Assembly: Mscorlib (in Mscorlib.dll)
See Also
ProgIdAttribute Members | System.Runtime.InteropServices Namespace