【问题标题】:Getting the helpstring attribute applied to C# properties exposed via COM interfaces将 helpstring 属性应用于通过 COM 接口公开的 C# 属性
【发布时间】:2011-10-03 20:29:18
【问题描述】:

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

【问题讨论】:

    标签: c# com interface properties interop


    【解决方案1】:

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

    【讨论】:

    • 是的,成功了。有没有办法用方法参数做同样的事情?我也不能让那些工作。对于方法本身来说,这很好,但不是参数或返回值。
    • 否,类型库不支持。
    • 我知道这是噪音,但我需要感谢@HansPassant。每次我有关于 COM 的问题时,你都会得到答案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多