次の方法で共有


ProgIdAttribute クラス

ユーザーがクラスの ProgID を指定することを許可します。

この型のすべてのメンバの一覧については、ProgIdAttribute メンバ を参照してください。

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

<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

スレッドセーフ

この型の public static (Visual Basicでは Shared) のすべてのメンバは、マルチスレッド操作で安全に使用できます。インスタンスのメンバの場合は、スレッドセーフであるとは限りません。

解説

この属性は、クラスに適用できます。

ProgID は、名前空間と型名を結合することによって、クラスに対して自動的に生成されます。ただし、ProgID は 39 文字に制限され、ピリオド以外の区切り記号を使用できないため、無効な ProgID が生成されることがあります。このような場合は、 ProgIdAttribute を使用して、ProgID をクラスに手動で割り当てることができます。

使用例

[Visual Basic, C#, C++] ProgIdAttribute をクラスに適用する方法を次の例に示します。この例では、 MyClass のすべての属性を取得し、 ProgIdAttributeValue プロパティを出力します。

 
<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] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

名前空間: System.Runtime.InteropServices

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ

アセンブリ: Mscorlib (Mscorlib.dll 内)

参照

ProgIdAttribute メンバ | System.Runtime.InteropServices 名前空間