开发者

Getting the helpstring attribute applied to C# properties exposed via COM interfaces

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 prope开发者_运维问答rties. Is there anyway to get a helpstring generated in the TLB output for properties ?


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;
        }
    }
}

Repeating the description is clumsy, but also required in IDL.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜