共用方式為


CodeModel.Language 屬性

取得用來撰寫程式碼的程式語言。

命名空間:  EnvDTE
組件:  EnvDTE (在 EnvDTE.dll 中)

語法

'宣告
ReadOnly Property Language As String
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 命名空間

其他資源

HOW TO:編譯和執行 Automation 物件模型程式碼範例

使用程式碼模型探索程式碼 (Visual Basic)

使用程式碼模型探索程式碼 (Visual C#)