4

このクラスにはこれらの属性があり、クラス内からそれらにアクセスする方法を考えています。ServedClassNameはカスタム属性であり、実際にアクセスしようとしているものです。

[Guid("24889af6-e174-460b-ab52-7fb5a925926e")]
[ServedClassName("ASCOM ProxyClient Telescope")]
[ProgId("ASCOM.DeviceProxyClient.Telescope")]
[ClassInterface(ClassInterfaceType.None)]
public class Telescope : ReferenceCountedObjectBase, ITelescopeV3

ProgID にアクセスするには、次を使用します。Marshal.GenerateProgIdForType(this.GetType());

4

1 に答える 1

6
object [] attrs = GetType().GetCustomAttributes(typeof(ServedClassNameAttribute), true);

クラスのタイプ ServedClassNameAttribute のカスタム属性のリストが表示されます。次に、次のように属性インスタンスをウォークスルーできます。

foreach (ServedClassNameAttribute attr in attrs)
{
    // Do something with attr
}
于 2013-02-28T17:18:38.057 に答える