8

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 ?

Alex Marshall
  • 9,406
  • 11
  • 65
  • 109

1 Answers1

10

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.

Hans Passant
  • 873,011
  • 131
  • 1,552
  • 2,371
  • 1
    Yep, that did the trick. Is there any way to do the same thing with method parameters ? I can't get those to work either. For methods themselves, it's fine, but not the parameters, or return values. – Alex Marshall Jul 12 '11 at 18:24
  • 1
    No, not supported by type libraries. – Hans Passant Jul 12 '11 at 18:28
  • 1
    I know this is noise, but I *needed* to thank you @HansPassant. Every time I have a question about COM, there you are with an answer. – RubberDuck Feb 10 '15 at 13:59