locked
Programmatically getting VS Extensibility object properties RRS feed

  • Question

  • I'm trying to use the VS extensibility API but debugger support for looking at property values is poor, so I'm working on writing code to programmatically get object properties so I can explore the API at runtime to try and work out how to do things with it.

    However I've noticed something strange: when calling typeof(VSLangProj.Reference).GetProperties() I only get back those properties that I've made use of in the source code.

    eg:

    1)

    PropertyInfo[] props = typeof(Reference).GetProperties();
    int len = props.Length;

    in this case, len == 0 - Reference has no properties.

    2)

    PropertyInfo[] props = typeof(Reference).GetProperties();
    int len = props.Length;

    if (false)
    {
    Reference r;
    int bn = r.BuildNumber;
    }

    in this case, len == 1. Reference now has one property.

    Is there a way to 'populate' types with their type info so reflection works properly?

    Thursday, December 11, 2014 5:45 PM

Answers

  • Chances are that you have added the VSLangProj reference to your proyect "by hand" and its property "Embed Interop Types" (in the Properties toolwindow) is set to true. In that case props.Length returns 0, because if that property is set to false, props.Length should return 21 or similar value.

    * My new blog about VSX: http://www.visualstudioextensibility.com * Twitter: https://twitter.com/VSExtensibility * MZ-Tools productivity extension for Visual Studio: http://www.mztools.com.


    • Proposed as answer by Carlos J. Quintero Thursday, December 11, 2014 8:00 PM
    • Marked as answer by innes Friday, December 12, 2014 3:48 PM
    • Edited by Carlos J. Quintero Friday, December 12, 2014 4:31 PM fix typo
    Thursday, December 11, 2014 8:00 PM