获取helptring属性应用于通过COM接口公开的C#属性

时间:2011-07-12 17:34:21

标签: c# com interface properties interop

我目前正在开发一个将要向COM公开的库,以便在正在升级的旧项目中使用。我正在创建要公开的接口,并且它们具有long,int等类型的属性。使用DescriptionAttribute,我可以获得.tlb中为接口,类和方法生成的帮助字符串,但由于某种原因,它似乎不想用于属性。反正有没有在TLB输出中为属性生成一个帮助字符串?

1 个答案:

答案 0 :(得分:8)

您必须单独将属性放在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中也是必需的。

相关问题