ProgIdAttribute Klasa

Definicja

Umożliwia użytkownikowi określenie identyfikatora ProgID klasy.

public ref class ProgIdAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.Class, Inherited=false)]
public sealed class ProgIdAttribute : Attribute
[System.AttributeUsage(System.AttributeTargets.Class, Inherited=false)]
[System.Runtime.InteropServices.ComVisible(true)]
public sealed class ProgIdAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Class, Inherited=false)>]
type ProgIdAttribute = class
    inherit Attribute
[<System.AttributeUsage(System.AttributeTargets.Class, Inherited=false)>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type ProgIdAttribute = class
    inherit Attribute
Public NotInheritable Class ProgIdAttribute
Inherits Attribute
Dziedziczenie
ProgIdAttribute
Atrybuty

Przykłady

W poniższym przykładzie pokazano, jak zastosować klasę ProgIdAttribute . Następnie aplikacja pobiera wszystkie atrybuty MyClassi wyświetla Value właściwość .ProgIdAttribute

[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 );
   }
}
[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 Class [MyClass]
      
      Public Sub New()
      End Sub
   End Class

   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
   End Class
End Namespace 'InteropSample

Uwagi

Ten atrybut można zastosować do klas.

Identyfikatory ProgID są generowane automatycznie dla klasy przez połączenie przestrzeni nazw z nazwą typu. Może to jednak spowodować nieprawidłowy identyfikator ProgID, ponieważ identyfikatory progid są ograniczone do 39 znaków i mogą nie zawierać interpunkcji innej niż kropka. W takim przypadku identyfikator ProgID można ręcznie przypisać do klasy przy użyciu polecenia ProgIdAttribute.

Konstruktory

ProgIdAttribute(String)

Inicjuje ProgIdAttribute nowe wystąpienie obiektu za pomocą określonego identyfikatora ProgID.

Właściwości

TypeId

Po zaimplementowaniu w klasie pochodnej pobiera unikatowy identyfikator dla tego Attributeelementu .

(Odziedziczone po Attribute)
Value

Pobiera identyfikator ProgID klasy.

Metody

Equals(Object)

Zwraca wartość wskazującą, czy to wystąpienie jest równe podanemu obiektowi.

(Odziedziczone po Attribute)
GetHashCode()

Zwraca wartość skrótu dla tego wystąpienia.

(Odziedziczone po Attribute)
GetType()

Type Pobiera wartość bieżącego wystąpienia.

(Odziedziczone po Object)
IsDefaultAttribute()

W przypadku zastąpienia w klasie pochodnej wskazuje, czy wartość tego wystąpienia jest wartością domyślną klasy pochodnej.

(Odziedziczone po Attribute)
Match(Object)

Po przesłonięciu w klasie pochodnej zwraca wartość wskazującą, czy to wystąpienie jest równe określonemu obiektowi.

(Odziedziczone po Attribute)
MemberwiseClone()

Tworzy płytkią kopię bieżącego Objectelementu .

(Odziedziczone po Object)
ToString()

Zwraca ciąg reprezentujący bieżący obiekt.

(Odziedziczone po Object)

Jawne implementacje interfejsu

_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

Zestaw nazw jest mapowany na odpowiedni zestaw identyfikatorów wysyłania.

(Odziedziczone po Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

Pobiera informacje o typie dla obiektu, który może służyć do pobierania informacji o typie dla interfejsu.

(Odziedziczone po Attribute)
_Attribute.GetTypeInfoCount(UInt32)

Pobiera informację o liczbie typów interfejsów, jakie zawiera obiekt (0 lub 1).

(Odziedziczone po Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

Umożliwia dostęp do właściwości i metod udostępnianych przez obiekt.

(Odziedziczone po Attribute)

Dotyczy