将 helpstring 属性应用于通过 COM 接口公开的 C# 属性

Getting the helpstring attribute applied to C# properties exposed via COM interfaces(将 helpstring 属性应用于通过 COM 接口公开的 C# 属性)
本文介绍了将 helpstring 属性应用于通过 COM 接口公开的 C# 属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在开发一个库,该库将公开给 COM,以便在升级的旧项目中使用.我正在创建要公开的接口,它们具有 long、int 等类型的属性.使用 DescriptionAttribute,我可以获得在 .tlb 中为接口、类和方法生成的帮助字符串,但由于某种原因,它似乎不想为属性工作.无论如何要获得在 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和setter上.像这样:

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.

这篇关于将 helpstring 属性应用于通过 COM 接口公开的 C# 属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)