我目前正在开发一个库,该库将向 COM 公开以用于正在升级的遗留项目。我正在创建要公开的接口(interface),它们具有 long、int 等类型的属性。使用 DescriptionAttribute,我可以获得在 .tlb 中为接口(interface)、类和方法生成的帮助字符串,但出于某种原因,它似乎不想为属性工作。有没有办法在 TLB 输出中为属性生成帮助字符串?
最佳答案
您必须将属性分别放在 getter 和 setter 上。像这样:
using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
namespace ClassLibrary1 {
[ComVisible(true), InterfaceType(ComInterfaceType.InterfaceIsDual)]
public interface IFoo {
int property {
[Description("prop")]
get;
[Description("prop")]
set;
}
}
}
重复描述是笨拙的,但在 IDL 中也是必需的。
关于c# - 获取应用于通过 COM 接口(interface)公开的 C# 属性的帮助字符串属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6668500/