Udostępnij za pośrednictwem


CodeModel2.CodeTypeFromFullName Method

Returns a code element based on a fully qualified name.

Namespace:  EnvDTE80
Assembly:  EnvDTE80 (in EnvDTE80.dll)

Syntax

'Declaration
Function CodeTypeFromFullName ( _
    Name As String _
) As CodeType
CodeType CodeTypeFromFullName(
    string Name
)
CodeType^ CodeTypeFromFullName(
    String^ Name
)
abstract CodeTypeFromFullName : 
        Name:string -> CodeType 
function CodeTypeFromFullName(
    Name : String
) : CodeType

Parameters

  • Name
    Type: System.String
    Required. A fully qualified symbol name, such as Namespace1.Namespace2.Class1.Member1.

Return Value

Type: EnvDTE.CodeType
A CodeType object.

Implements

CodeModel.CodeTypeFromFullName(String)

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. For more information, see the section Code Model Element Values Can Change in Discovering Code by Using the Code Model (Visual Basic).

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;
}

.NET Framework Security

See Also

Reference

CodeModel2 Interface

EnvDTE80 Namespace

Other Resources

How to: Compile and Run the Automation Object Model Code Examples

Discovering Code by Using the Code Model (Visual Basic)

Discovering Code by Using the Code Model (Visual C#)