获取应用于通过COM接口公开的C#属性的helpstring属性 [英] Getting the helpstring attribute applied to C# properties exposed via COM interfaces
问题描述
我目前正在使用一个要暴露给COM的库,用于正在升级的旧项目。我创建了要暴露的接口,并且它们具有long,int等类型的属性。使用DescriptionAttribute,我可以获得在.tlb中为接口,类和方法生成的helpstrings,但由于某种原因,它似乎不想处理属性。是否还有在属性的TLB输出中产生一个帮助字符串?
I'm currently working on a library that's to be exposed to COM for use in a legacy project that's being upgraded. I'm creating interfaces that are to be exposed, and they have properties on them with long, int, etc types. Using the DescriptionAttribute, I can get helpstrings generated in the .tlb for interfaces, classes, and methods, but for some reason it doesn't seem to want to work for properties. Is there anyway to get a helpstring generated in the TLB output for properties ?
推荐答案
你必须将属性放在getter上,设置器。像这样:
You have to put the attribute on the getter and setter individually. Like this:
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中也需要。
Repeating the description is clumsy, but also required in IDL.
这篇关于获取应用于通过COM接口公开的C#属性的helpstring属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!