Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 properties. Is there anyway to get a helpstring generated in the TLB output for properties ?

like image 999
Alex Marshall Avatar asked Jul 12 '11 17:07

Alex Marshall


People also ask

What is the use of [helpstring] attribute?

The [helpstring] attribute specifies a character string that is used to describe the element to which it applies. You can apply the [helpstring] attribute to library, importlib, interface, dispinterface, module, or coclass statements, typedefs, properties, and methods.

What does the attributeusage do in mvc4?

What does the AttributeUsage do in MVC4 11 Cascading the effect of an attribute to overridden properties in child classes 4 C# Attribute inheritance not working as I would expect

What are attributes in C++?

Last Updated : 05 Dec, 2018 Attributes are one of the key features of modern C++ which allows the programmer to specify additional information to the compiler to enforce constraints (conditions), optimise certain pieces of code or do some specific code generation.

How can I return a localized string from a descriptionattribute?

In order for the DescriptionAttribute to return a localized string, it requires a resource key and, ideally, /// a type reference as the base-key for the ResourceManager. A DescriptionAttribute could not provide this information without /// a reference to it's target type.


1 Answers

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.

like image 83
Hans Passant Avatar answered Sep 19 '22 02:09

Hans Passant