CodeClass.Language 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取用于创作代码的编程语言。
public:
property System::String ^ Language { System::String ^ get(); };
public:
property Platform::String ^ Language { Platform::String ^ get(); };
[System.Runtime.InteropServices.DispId(9)]
public string Language { [System.Runtime.InteropServices.DispId(9)] [System.Runtime.InteropServices.TypeLibFunc(1024)] get; }
[<System.Runtime.InteropServices.DispId(9)>]
[<get: System.Runtime.InteropServices.DispId(9)>]
[<get: System.Runtime.InteropServices.TypeLibFunc(1024)>]
member this.Language : string
Public ReadOnly Property Language As String
属性值
一个 CodeModelLanguageConstants 常数。
- 属性
示例
Public Sub CodeClassExample(ByVal dte As DTE2)
' Before running this example, open a code document from a
' project and place the insertion point inside a class definition.
Try
Dim objTextSel As TextSelection
Dim objCodeCls As CodeClass
objTextSel = CType(dte.ActiveDocument.Selection, TextSelection)
objCodeCls = CType(objTextSel.ActivePoint.CodeElement(vsCMElement.vsCMElementClass), CodeClass)
' Add comments to CodeClass objCodeClass - notice change in code document.
objCodeCls.Comment = "Comments for the CodeClass object."
' Access top-level object through the CodeClass object
' and return the file name of that top-level object.
MessageBox.Show("Top-level object's filename: " + objCodeCls.DTE.FileName)
' Get the language used to code the CodeClass object - returns a GUID.
MessageBox.Show(objCodeCls.Language)
' Get a collection of elements contained by the CodeClass object.
Dim members As String = "Member Elements of " + objCodeCls.Name + ": " + vbCrLf
Dim elem As CodeElement
For Each elem In objCodeCls.Members
members = members + (elem.Name + vbCrLf)
Next elem
MessageBox.Show(members)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
public void CodeClassExample(DTE2 dte)
{
// Before running this example, open a code document from a
// project and place the insertion point inside a class definition.
try
{
TextSelection objTextSel;
CodeClass objCodeCls;
objTextSel = (TextSelection)dte.ActiveDocument.Selection;
objCodeCls = (CodeClass)objTextSel.ActivePoint.get_CodeElement(vsCMElement.vsCMElementClass);
// Add comments to CodeClass objCodeClass - notice change in code document.
objCodeCls.Comment = "Comments for the CodeClass object.";
// Access top-level object through the CodeClass object
// and return the file name of that top-level object.
MessageBox.Show("Top-level object's filename: " + objCodeCls.DTE.FileName);
// Get the language used to code the CodeClass object - returns a GUID,
MessageBox.Show(objCodeCls.Language);
// Get a collection of elements contained by the CodeClass object.
string members = "Member Elements of " + objCodeCls.Name + ": \n";
foreach (CodeElement elem in objCodeCls.Members)
{
members = members + (elem.Name + "\n");
}
MessageBox.Show(members);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
注解
备注
在进行了某些类型的编辑之后,代码模型元素(例如类、结构、函数、特性、委托等)的值可能变为非确定性的,这意味着不能确定它们的值始终保持不变。 有关详细信息,请参阅 "代码模型元素值在 使用代码模型查找代码时 可能发生变化" (Visual Basic) "。