Export (0) Print
Expand All

CodeModel2.CodeTypeFromFullName Method

[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]

Returns a code element based on a fully qualified name.

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

CodeType CodeTypeFromFullName(
	string Name
)

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.

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.

NoteNote

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).

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

Show:
© 2014 Microsoft