CodeModel2.CodeTypeFromFullName Method

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

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

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2015 Microsoft