Visual Studio Development Bookmark and Share   
 index > Visual Studio Extensibility > How to get generic type used in VB Code using Codemodel API ?
 

How to get generic type used in VB Code using Codemodel API ?


For the following piece of VB code, if we try to get the CodeClass.Base.Fullname, it gives the fullname as "c1(Of T)". Ideally it should give the fullname of the instance i.e. "c1(Of Integer)" where this works fine for C# code i.e returns "c1<int>". Similar behavior is observed when generic type is used to define a variable inside a class ( "attr1" in sample code). The CodeModel API behaves differently for VB and C# codes.

Visual Basic Code
-----------------------
     Public Class c1(Of T)

     End Class

     Public Class c2 Inherits c1(Of Integer)
          Dim attr1 As ICollection (Of Integer)
     End Class

C# Code
---------

     public class c1<T>
     {
     }
 
     public class c2 : c1<int>
     {
          ICollection<int> attr1;
     }
 
Why CodeModel API behave differently for C# & VB? Is this a defect in the CodeModel API? Is there any other way of getting the FullName for the Base Types OR Types which gives the actual type param information? Is there any other way using CodeModel to get the generic parameter information?
ManishPaul  Tuesday, October 13, 2009 10:34 AM
Why CodeModel API behave differently for C# & VB? Is this a defect in the CodeModel API? Is there any other way of getting the FullName for the Base Types OR Types which gives the actual type param information? Is there any other way using CodeModel to get the generic parameter information?

The VB and C# CodeModel implementations were written by different teams, with apparent slight differences in interpretation of interface documentation.  The difference you have described here is far from the only one between the two.  You may wish to report it as a bug at http://connect.microsoft.com/VisualStudio/feedback/.

As for a workaround, the VB implementation uses an extender to retrieve generic base type information.  e.g.:

        Dim extender = yourClass.Extender("VBGenericExtender")

        Dim baseTypeCount As Integer
        extender.GetBaseTypesCount(baseTypeCount)

        For i As Integer = 1 To baseTypeCount
            Console.WriteLine(extender.GetBaseGenericName(i))
        Next
Nicole Calinoiu  Tuesday, October 13, 2009 1:08 PM
Why CodeModel API behave differently for C# & VB? Is this a defect in the CodeModel API? Is there any other way of getting the FullName for the Base Types OR Types which gives the actual type param information? Is there any other way using CodeModel to get the generic parameter information?

The VB and C# CodeModel implementations were written by different teams, with apparent slight differences in interpretation of interface documentation.  The difference you have described here is far from the only one between the two.  You may wish to report it as a bug at http://connect.microsoft.com/VisualStudio/feedback/.

As for a workaround, the VB implementation uses an extender to retrieve generic base type information.  e.g.:

        Dim extender = yourClass.Extender("VBGenericExtender")

        Dim baseTypeCount As Integer
        extender.GetBaseTypesCount(baseTypeCount)

        For i As Integer = 1 To baseTypeCount
            Console.WriteLine(extender.GetBaseGenericName(i))
        Next
Nicole Calinoiu  Tuesday, October 13, 2009 1:08 PM

You can use google to search for other answers

Custom Search

More Threads

• Consuming MSSCCI plugins
• Save DSL diagram in debugging application
• STEP BY STEP document for End-End.WizardUIP sample
• Memory Leak in samples and default editors created by the wizard.
• Re-distributable assembly
• CTC constant for "Test Results" context menu?
• How to reference Oracle.DataAccess in Visual Studio Macro Editor
• Debugging a Project Flavor - throws NotImplementedException, and I cannot continue (I must stop debugging).
• Trivial Question: How to show a custom dialog box in VSPackage in C++?
• How to teaching MSBuild to copy a project reference to the output directory