Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6100917
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:26:26+00:00 2026-05-23T13:26:26+00:00

I’m using VB.NET with Visual Studio 2010. Is there any function or tool to

  • 0

I’m using VB.NET with Visual Studio 2010. Is there any function or tool to auto complete any .Net type name to fully qualified one?

I mean a tool/function that actually changing the source code from short hand to fully qualified name like following:

From String to System.String

From Process.Start to this System.Diagnostics.Process.Start

UPDATE:

Thanks for ReSharper suggestion. But
I’m not prepared to buy it or award
bounty for a commercial product
suggestion. Sorry about that. I should
make my question clear about that
requirement. I already tried ReSharper
before asking this question.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T13:26:27+00:00Added an answer on May 23, 2026 at 1:26 pm

    Here is a macro that works fine for C# code.

    When I tested it on a VB .Net project it didn’t work for types in assembly references. Seems like the project code model for VB.Net excludes external types.

    I include the code here anyway. Maybe someone else knows how to do it for VB


    First we need a function that finds the current context

    Private Function FindCodeElement(ByVal caretPosition As TextPoint, ByVal elems As CodeElements) As CodeElement
        If elems Is Nothing Then Return Nothing
        Return elems.Cast(Of CodeElement) _
                    .Where(Function(x) x.StartPoint.LessThan(caretPosition) AndAlso _
                                       x.EndPoint.GreaterThan(caretPosition)) _
                    .Select(Function(x) If(FindCodeElement(caretPosition, GetMembers(x)), x)) _
                    .FirstOrDefault()
    End Function
    

    We also need a function that create all candidate names based on using/import statements

    Private Sub FindAllCandidates(ByVal elem As Object, ByVal className As String)
        If TypeOf elem Is CodeFunction Then
            FindAllCandidates(CType(elem, CodeFunction).Parent, className)
        ElseIf TypeOf elem Is CodeClass Then
            mCandidates.Add(CType(elem, CodeClass).FullName & "." & className)
            FindAllCandidates(CType(elem, CodeClass).Parent, className)
        ElseIf TypeOf elem Is CodeStruct Then
            mCandidates.Add(CType(elem, CodeStruct).FullName & "." & className)
            FindAllCandidates(CType(elem, CodeStruct).Parent, className)
        ElseIf TypeOf elem Is CodeNamespace Then
            mCandidates.Add(CType(elem, CodeNamespace).FullName & "." & className)
            For Each ns As String In CType(elem, CodeNamespace).Members.OfType(Of CodeImport) _
                                                                       .Select(Function(x) x.Namespace)
                mCandidates.Add(ns & "." & className)
            Next
            FindAllCandidates(CType(elem, CodeNamespace).Parent, className)
        ElseIf TypeOf elem Is FileCodeModel Then
            For Each ns As String In CType(elem, FileCodeModel).CodeElements.OfType(Of CodeImport) _
                                                                            .Select(Function(x) x.Namespace)
                mCandidates.Add(ns & "." & className)
            Next
        End If
    End Sub
    

    And then a function that loops all available items to find one of the candidates

    Private Function FindClassInCodeElements(ByVal elems As CodeElements) As CodeElement
        If elems Is Nothing Then Return Nothing
        For Each elem As CodeElement In elems
            If IsClassType(elem) Then
                If mCandidates.Contains(elem.FullName) Then Return elem
            ElseIf TypeOf elem Is CodeNamespace Then
                For Each candidate As String In mCandidates
                    If candidate.StartsWith(elem.FullName) Then
                        Dim found As CodeElement = FindClassInCodeElements(GetMembers(elem))
                        If found IsNot Nothing Then Return found
                        Exit For
                    End If
                Next
            End If
        Next
        Return Nothing
    End Function
    

    Two small helper functions

    Private Function IsClassType(ByVal elem As CodeElement) As Boolean
        Return TypeOf elem Is CodeClass OrElse TypeOf elem Is CodeStruct OrElse TypeOf elem Is CodeInterface
    End Function
    
    Private Function GetMembers(ByVal elem As CodeElement) As CodeElements
        If TypeOf elem Is CodeClass Then
            Return CType(elem, CodeClass).Members
        ElseIf TypeOf elem Is CodeNamespace Then
            Return CType(elem, CodeNamespace).Members
        ElseIf TypeOf elem Is CodeStruct Then
            Return CType(elem, CodeStruct).Members
        ElseIf TypeOf elem Is CodeInterface Then
            Return CType(elem, CodeInterface).Members
        End If
        Return Nothing
    End Function
    

    And then we can write the main function which you can alter depending on how you want to use it.

    Dim mCandidates As New HashSet(Of String)
    
    Sub ExpandFullNameOfSelection()
        Dim selection As EnvDTE.TextSelection = CType(DTE.ActiveDocument.Selection(), EnvDTE.TextSelection)
        ' Assume type is selected
        Dim className As String = selection.Text
    
        ' Find current context
        Dim currentFunction As CodeElement = FindCodeElement(selection.ActivePoint, DTE.ActiveDocument.ProjectItem.FileCodeModel.CodeElements)
    
        mCandidates.Clear()
        FindAllCandidates(currentFunction, className)
    
        Dim classType As CodeElement = DTE.Solution.Projects.Cast(Of Project) _
                                                            .Where(Function(x) x.CodeModel IsNot Nothing) _
                                                            .Select(Function(x) FindClassInCodeElements(x.CodeModel.CodeElements)) _
                                                            .FirstOrDefault(Function(x) x IsNot Nothing)
        If classType IsNot Nothing Then
            selection.Text = classType.FullName ' replace with full name
        End If
    End Function
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.