Freigeben über


ProgIdAttribute-Klasse

Ermöglicht dem Benutzer die Angabe der ProgID einer Klasse.

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

Syntax

'Declaration
<AttributeUsageAttribute(AttributeTargets.Class, Inherited:=False)> _
<ComVisibleAttribute(True)> _
Public NotInheritable Class ProgIdAttribute
    Inherits Attribute
'Usage
Dim instance As ProgIdAttribute
[AttributeUsageAttribute(AttributeTargets.Class, Inherited=false)] 
[ComVisibleAttribute(true)] 
public sealed class ProgIdAttribute : Attribute
[AttributeUsageAttribute(AttributeTargets::Class, Inherited=false)] 
[ComVisibleAttribute(true)] 
public ref class ProgIdAttribute sealed : public 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

Hinweise

Dieses Attribut kann auf Klassen angewendet werden.

ProgIDs werden für eine Klasse durch Kombination von Namespace und Typname automatisch generiert. Dies kann jedoch eine ungültige ProgID zur Folge haben, da ProgIDs auf 39 Zeichen beschränkt sind und keine anderen Satzzeichen als einen Punkt enthalten dürfen. In diesem Fall kann der Klasse eine ProgID mithilfe von ProgIdAttribute manuell zugewiesen werden.

Beispiel

Das folgende Beispiel veranschaulicht das Anwenden von ProgIdAttribute auf eine Klasse. Die Anwendung ruft dann alle Attribute von MyClass ab und zeigt die Value-Eigenschaft von ProgIdAttribute an.

   <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 
[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);
      }
   }
}
[ClassInterface(ClassInterfaceType::AutoDispatch)]
[ProgId("InteropSample.MyClass")]
public ref class MyClass
{
public:
   MyClass(){}

};

int main()
{
   try
   {
      AttributeCollection^ attributes;
      attributes = TypeDescriptor::GetAttributes( MyClass::typeid );
      ProgIdAttribute^ progIdAttributeObj = dynamic_cast<ProgIdAttribute^>(attributes[ ProgIdAttribute::typeid ]);
      Console::WriteLine( "ProgIdAttribute's value is set to : {0}", progIdAttributeObj->Value );
   }
   catch ( Exception^ e ) 
   {
      Console::WriteLine( "Exception : {0}", 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

Vererbungshierarchie

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

Threadsicherheit

Alle öffentlichen statischen (Shared in Visual Basic) Member dieses Typs sind threadsicher. Bei Instanzmembern ist die Threadsicherheit nicht gewährleistet.

Plattformen

Windows 98, Windows 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

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

Siehe auch

Referenz

ProgIdAttribute-Member
System.Runtime.InteropServices-Namespace