CodeModel.Language 属性

获取用于创作代码的编程语言。

命名空间:  EnvDTE
程序集:  EnvDTE(在 EnvDTE.dll 中)

语法

声明
ReadOnly Property Language As String
    Get
string Language { get; }
property String^ Language {
    String^ get ();
}
abstract Language : string
function get Language () : String

属性值

类型:System.String
一个 CodeModelLanguageConstants 常数。

备注

提示

在进行某些类型的编辑之后,代码模型元素(如类、结构、函数、特性、委托等)的值可能是非确定性的,这意味着不能指望它们的值总是保持不变。 有关更多信息,请参见 使用代码模型查找代码 (Visual Basic) 中的“代码模型元素的值可能会更改”一节。

示例

Sub LanguageExample(ByVal dte As DTE2)

    ' Before running this example, open a solution that contains 
    ' one or more projects.
    Dim langs As String
    Dim proj As Project
    For Each proj In dte.Solution
        Try
            Dim cm As CodeModel = proj.CodeModel
            langs &= proj.Name & "'s language is "

            Select Case cm.Language
                Case CodeModelLanguageConstants.vsCMLanguageMC, _
                    CodeModelLanguageConstants.vsCMLanguageVC
                    langs &= "C++" & vbCrLf
                Case CodeModelLanguageConstants.vsCMLanguageCSharp
                    langs &= "C#" & vbCrLf
                Case CodeModelLanguageConstants.vsCMLanguageVB
                    langs &= "Visual Basic" & vbCrLf
                Case "{E6FDF8BF-F3D1-11D4-8576-0002A516ECE8}"
                    langs &= "J#" & vbCrLf
            End Select
        Catch
        End Try
    Next

    MsgBox(langs)

End Sub
public void LanguageExample(DTE2 dte)
{
    // Before running this example, open a solution that contains one 
    // or more projects.
    string langs = "";
    foreach (Project proj in dte.Solution)
    {
        try
        {
            CodeModel cm = proj.CodeModel;
            langs += proj.Name + "'s language is ";

            switch (cm.Language)
            {
                case CodeModelLanguageConstants.vsCMLanguageMC:
                case CodeModelLanguageConstants.vsCMLanguageVC:
                    langs += "C++" + Environment.NewLine;
                    break;
                case CodeModelLanguageConstants.vsCMLanguageCSharp:
                    langs += "C#" + Environment.NewLine;
                    break;
                case CodeModelLanguageConstants.vsCMLanguageVB:
                    langs += "Visual Basic" + Environment.NewLine;
                    break;
                case "{E6FDF8BF-F3D1-11D4-8576-0002A516ECE8}":
                    langs += "J#" + Environment.NewLine;
                    break;
            }
        }
        catch
        {
        }
    }

    MessageBox.Show(langs);
}

.NET Framework 安全性

请参见

参考

CodeModel 接口

EnvDTE 命名空间

其他资源

如何:编译和运行自动化对象模型代码示例

使用代码模型查找代码 (Visual Basic)

使用代码模型查找代码 (Visual C#)