Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello guys help for a beginner.
How to enumerate CodeElement inside the body of a function?
thank you
I want to try to write an addin that can write a Select Case of an enumerated variable inside a function.
I tried with this code with Visual Studio 2010 :
VB
Imports EnvDTE
  Imports EnvDTE80
  Imports System.Collections.Generic
  Imports System.Text
  Public Class Form1
    Private dte As DTE2 = System.Runtime.InteropServices.Marshal.GetActiveObject("VisualStudio.DTE.10.0")
    Dim lElements As New List(Of String)
    Public Enum Sizes
      Small
      Medium
      Large
      ExtraLarge
    End Enum
    Private Sub Test(mysize As Sizes)
      Dim prova As Sizes        'not found in FileCodeModel
      prova = Sizes.ExtraLarge   'not found in FileCodeModel
    End Sub
    Private Sub RecursiveLoop(cdElements As CodeElements)
      Dim children As String
      Dim elem As CodeElement
      Try
        For Each elem In cdElements
          lElements.Add(elem.Name & vbCrLf)
          RecursiveLoop(elem.Children)
        Next
      Catch ex As Exception
        System.Windows.Forms.MessageBox.Show(ex.ToString)
      End Try
    End Sub
    Sub CodeElementsExample(ByVal dte As DTE2)
      Dim fcm As FileCodeModel = _
            dte.ActiveDocument.ProjectItem.FileCodeModel
      RecursiveLoop(fcm.CodeElements)
      Dim sBuilder As New StringBuilder
      For Each item As String In lElements
        sBuilder.Append(item)
      Next
      MsgBox(sBuilder.ToString)
    End Sub
    Private Sub Form1_Load(sender As Object, e As System.EventArgs) Handles Me.Load
      Stop   ' open code window
      CodeElementsExample(dte)
    End Sub
  End Class
Posted
Updated 4-Aug-14 6:44am
v4
Comments
Sergey Alexandrovich Kryukov 4-Aug-14 11:53am    
Not clear. You need to tag your language (if the language is "Basic", it's not specific enough), platform, provide all the detail on the problem. Are you using EnvDTE? Why? And so on...
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900