Compartilhar via


Classe ProgIdAttribute

 

Permite que o usuário especifique o ProgID de uma classe.

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

Hierarquia de Herança

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

Sintaxe

[AttributeUsageAttribute(AttributeTargets.Class, Inherited = false)]
[ComVisibleAttribute(true)]
public sealed class ProgIdAttribute : Attribute
[AttributeUsageAttribute(AttributeTargets::Class, Inherited = false)]
[ComVisibleAttribute(true)]
public ref class ProgIdAttribute sealed : Attribute
[<Sealed>]
[<AttributeUsageAttribute(AttributeTargets.Class, Inherited = false)>]
[<ComVisibleAttribute(true)>]
type ProgIdAttribute = 
    class
        inherit Attribute
    end
<AttributeUsageAttribute(AttributeTargets.Class, Inherited := False)>
<ComVisibleAttribute(True)>
Public NotInheritable Class ProgIdAttribute
    Inherits Attribute

Construtores

Nome Descrição
System_CAPS_pubmethod ProgIdAttribute(String)

Inicializa uma nova instância de ProgIdAttribute com o ProgID especificado.

Propriedades

Nome Descrição
System_CAPS_pubproperty TypeId

Quando implementado em uma classe derivada, obtém um identificador exclusivo para este Attribute.(Herdado de Attribute.)

System_CAPS_pubproperty Value

Obtém o ProgID da classe.

Métodos

Nome Descrição
System_CAPS_pubmethod Equals(Object)

Esta API dá suporte à infraestrutura produto e não se destina a ser usada diretamente do seu código. Retorna um valor que indica se essa instância é igual a um objeto especificado.(Herdado de Attribute.)

System_CAPS_pubmethod GetHashCode()

Retorna o código hash para essa instância.(Herdado de Attribute.)

System_CAPS_pubmethod GetType()

Obtém o Type da instância atual.(Herdado de Object.)

System_CAPS_pubmethod IsDefaultAttribute()

Quando substituído em uma classe derivada, indica se o valor dessa instância é o valor padrão para a classe derivada.(Herdado de Attribute.)

System_CAPS_pubmethod Match(Object)

Quando substituído em uma classe derivada, retorna um valor que indica se essa instância é igual a um objeto especificado.(Herdado de Attribute.)

System_CAPS_pubmethod ToString()

Retorna uma cadeia de caracteres que representa o objeto atual.(Herdado de Object.)

Implementações Explícitas da Interface

Nome Descrição
System_CAPS_pubinterfaceSystem_CAPS_privmethod _Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

Mapeia um conjunto de nomes para um conjunto correspondente de identificadores de expedição.(Herdado de Attribute.)

System_CAPS_pubinterfaceSystem_CAPS_privmethod _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

Recupera as informações de tipo para um objeto, que pode ser usado para obter as informações de tipo para uma interface.(Herdado de Attribute.)

System_CAPS_pubinterfaceSystem_CAPS_privmethod _Attribute.GetTypeInfoCount(UInt32)

Retorna o número de interfaces de informações do tipo que um objeto fornece (0 ou 1).(Herdado de Attribute.)

System_CAPS_pubinterfaceSystem_CAPS_privmethod _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

Fornece acesso a propriedades e métodos expostos por um objeto.(Herdado de Attribute.)

Comentários

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 T:System.Runtime.InteropServices.ProgIdAttribute.

Exemplos

The following example demonstrates how to apply ProgIdAttribute on a class. The application then gets all attributes of MyClass, and prints the P:System.Runtime.InteropServices.ProgIdAttribute.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);
      }
   }
}
   <ClassInterface(ClassInterfaceType.AutoDispatch), ProgId("InteropSample.MyClass")>  _
   Public Class [MyClass]

      Public Sub New()
      End Sub 'NewNew
   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 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 );
   }
}

Informações de Versão

.NET Framework
Disponível desde 1.1

Acesso thread-safe

Quaisquer membros estáticos públicos ( Compartilhado no Visual Basic) desse tipo são thread-safe. Não há garantia de que qualquer membro de instância seja thread-safe.

Confira Também

Namespace System.Runtime.InteropServices

Retornar ao início