我有这个类的这些属性,我想知道如何从类中访问它们。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());
发布于 2013-03-01 01:18:38
object [] attrs = GetType().GetCustomAttributes(typeof(ServedClassNameAttribute), true);将为您提供类上ServedClassNameAttribute类型的自定义属性的列表。然后您可以遍历属性实例,如下所示:
foreach (ServedClassNameAttribute attr in attrs)
{
// Do something with attr
}https://stackoverflow.com/questions/15141658
复制相似问题