CodeVariable.Access 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
定义此项的访问修饰符。
public:
property EnvDTE::vsCMAccess Access { EnvDTE::vsCMAccess get(); void set(EnvDTE::vsCMAccess value); };
public:
property EnvDTE::vsCMAccess Access { EnvDTE::vsCMAccess get(); void set(EnvDTE::vsCMAccess value); };
[System.Runtime.InteropServices.DispId(36)]
public EnvDTE.vsCMAccess Access { [System.Runtime.InteropServices.DispId(36)] get; [System.Runtime.InteropServices.DispId(36)] set; }
[<System.Runtime.InteropServices.DispId(36)>]
[<get: System.Runtime.InteropServices.DispId(36)>]
[<set: System.Runtime.InteropServices.DispId(36)>]
member this.Access : EnvDTE.vsCMAccess with get, set
Public Property Access As vsCMAccess
属性值
一个 vsCMAccess 值。
- 属性
示例
Sub AccessExample(ByVal dte As DTE2)
' Before running this example, open a code document from a project
' and place the insertion point inside a variable definition.
Try
' Retrieve the CodeVariable at the insertion point.
Dim sel As TextSelection = _
CType(dte.ActiveDocument.Selection, TextSelection)
Dim var As CodeVariable = _
CType(sel.ActivePoint.CodeElement( _
vsCMElement.vsCMElementVariable), CodeVariable)
' Display the CodeVariable's accessibility.
Dim access As String
Dim varAccess As vsCMAccess = var.Access
Dim val As vsCMAccess
For Each val In [Enum].GetValues(varAccess.GetType())
If (val And varAccess) <> 0 Then
access &= val.ToString() & vbCrLf
End If
Next
MsgBox(var.Name & " has the following accessibility:" & _
vbCrLf & vbCrLf & access)
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
public void AccessExample(DTE2 dte)
{
// Before running this example, open a code document from a project
// and place the insertion point inside a variable definition.
try
{
// Retrieve the CodeVariable at the insertion point.
TextSelection sel =
(TextSelection)dte.ActiveDocument.Selection;
CodeVariable var =
(CodeVariable)sel.ActivePoint.get_CodeElement(
vsCMElement.vsCMElementVariable);
// Display the CodeVariable's accessibility.
string access = "";
vsCMAccess varAccess = var.Access;
foreach (vsCMAccess val in Enum.GetValues(varAccess.GetType()))
{
if ((val & varAccess) != 0)
access += val.ToString() + "\r\n";
}
MessageBox.Show(var.Name +
" has the following accessibility:\r\n\r\n" + access);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
注解
Access 返回实际的访问权限以及其他代码可能访问此代码元素的方式。
备注
对于 Visual Basic 源代码中的代码元素,此属性是只读的。
此外,在进行某些类型的编辑之后,代码模型元素(例如类、结构、函数、特性、委托等)的值可能是不确定的,这意味着无法依赖于它们的值始终保持不变。 有关详细信息,请参阅 "代码模型元素值在 使用代码模型查找代码时 可能发生变化" (Visual Basic) "。