Partager via


CodeModel2.CodeTypeFromFullName(String) Method

Definition

Returns a code element based on a fully qualified name.

public:
 EnvDTE::CodeType ^ CodeTypeFromFullName(System::String ^ Name);
public:
 EnvDTE::CodeType ^ CodeTypeFromFullName(Platform::String ^ Name);
EnvDTE::CodeType CodeTypeFromFullName(std::wstring const & Name);
[System.Runtime.InteropServices.DispId(5)]
public EnvDTE.CodeType CodeTypeFromFullName (string Name);
[<System.Runtime.InteropServices.DispId(5)>]
abstract member CodeTypeFromFullName : string -> EnvDTE.CodeType
Public Function CodeTypeFromFullName (Name As String) As CodeType

Parameters

Name
String

Required. A fully qualified symbol name, such as Namespace1.Namespace2.Class1.Member1.

Returns

A CodeType object.

Implements

Attributes

Examples

Sub CodeTypeFromFullNameExample(ByVal dte As DTE2)  

    ' Before running this example, open a project.  
    Try  
        Dim proj As Project  
        For Each proj In dte.Solution  
            Dim cm As CodeModel = proj.CodeModel  
            If IsNothing(cm) = False Then  
                Dim name As String = _  
                    ConvertFullName(cm, "System.Object")  
                Dim typ As CodeType = cm.CodeTypeFromFullName(name)  

                If IsNothing(typ) = False Then  
                    MsgBox(proj.Name & vbCrLf & name & "'s kind is " _  
                        & typ.Kind.ToString())  
                Else  
                    MsgBox(proj.Name & _  
                        ": CodeTypeFromFullName failed.")  
                End If  
            End If  
        Next  
    Catch ex As Exception  
        MsgBox(ex.Message)  
    End Try  

End Sub  

Function ConvertFullName(ByVal cm As CodeModel, _  
    ByVal fullName As String) As String  

    ' Convert a .NET type name into a C++ type name.  
    If (cm.Language = CodeModelLanguageConstants.vsCMLanguageVC) Or _  
        (cm.Language = CodeModelLanguageConstants.vsCMLanguageMC) Then  
        Return fullName.Replace(".", "::")  
    Else  
        Return fullName  
    End If  

End Function  
public void CodeTypeFromFullNameExample(DTE2 dte)  
{  
    // Before running this example, open a project.  
    try  
    {  
        foreach (Project proj in dte.Solution)  
        {  
            CodeModel cm = proj.CodeModel;  
            if (cm != null)  
            {  
                string name = ConvertFullName(cm, "System.Object");  
                CodeType typ = cm.CodeTypeFromFullName(name);  

                if (typ != null)  
                    MessageBox.Show(proj.Name + "\r\n" +   
                        name + "'s kind is " + typ.Kind.ToString());  
                else  
                    MessageBox.Show(proj.Name +   
                        ": CodeTypeFromFullName failed.");  
            }  
        }  
    }  
    catch (Exception ex)  
    {  
        MessageBox.Show(ex.Message);  
    }  
}  

string ConvertFullName(CodeModel cm, string fullName)  
{  
    // Convert a .NET type name into a C++ type name.  
    if ((cm.Language == CodeModelLanguageConstants.vsCMLanguageVC) ||   
        (cm.Language == CodeModelLanguageConstants.vsCMLanguageMC))  
        return fullName.Replace(".", "::");  
    else  
        return fullName;  
}  

Remarks

If the specified name is not found in the project or any of its references, CodeTypeFromFullName returns Nothing, rather than returning a code element with a Kind property of vsCMElementOther and a InfoLocation property of vsCMInfoLocationNone.

Note

The values of code model elements such as classes, structs, functions, attributes, delegates, and so forth can be non-deterministic after making certain kinds of edits, meaning that their values cannot be relied upon to always remain the same

Applies to