CodeClass2.Access 属性
设置或获取此代码类的访问特性。
命名空间: EnvDTE80
程序集: EnvDTE80(在 EnvDTE80.dll 中)
语法
声明
Property Access As vsCMAccess
vsCMAccess Access { get; set; }
property vsCMAccess Access {
vsCMAccess get ();
void set (vsCMAccess value);
}
abstract Access : vsCMAccess with get, set
function get Access () : vsCMAccess
function set Access (value : vsCMAccess)
属性值
类型:vsCMAccess
一个 vsCMAccess 值。
备注
Access 属性返回一个常数,该常数指示实际的访问以及其他代码访问此代码类的可能方式。
备注
在进行某些类型的编辑之后,代码模型元素(如类、结构、函数、特性、委托等)的值可能是非确定性的,这意味着不能指望它们的值总是保持不变。有关更多信息,请参见 使用代码模型查找代码 (Visual Basic) 中的“代码模型元素的值可能会更改”一节。
示例
[Visual Basic]
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
[C#]
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);
}
}
.NET Framework 安全性
- 对直接调用方的完全信任。此成员不能由部分信任的代码使用。有关详细信息,请参阅通过部分受信任的代码使用库。