CodeFunction2.Overloads 属性
获取此项的重载方法集合。
命名空间: EnvDTE80
程序集: EnvDTE80(在 EnvDTE80.dll 中)
语法
声明
ReadOnly Property Overloads As CodeElements
CodeElements Overloads { get; }
property CodeElements^ Overloads {
CodeElements^ get ();
}
abstract Overloads : CodeElements
function get Overloads () : CodeElements
属性值
类型:EnvDTE.CodeElements
一个 CodeElements 集合。
备注
Overloads 返回具有相同名称的所有方法的集合,这些名称与指定的代码函数一起按原文定义的(即,以相同的类定义语法按词汇定义的)。 如果 IsOverloaded 为 false,则此集合仅包含一个元素(即指定的代码函数)。
备注
在进行某些类型的编辑之后,代码模型元素(如类、结构、函数、特性、委托等)的值可能是非确定性的,这意味着不能指望它们的值总是保持不变。有关更多信息,请参见 使用代码模型查找代码 (Visual Basic) 中的“代码模型元素的值可能会更改”一节。
示例
Sub OverloadsExample(ByVal dte As DTE2)
' Before running this example, open a code document from a project
' and place the insertion point inside a function.
Try
' Retrieve the CodeFunction at the insertion point.
Dim sel As TextSelection = _
CType(dte.ActiveDocument.Selection, TextSelection)
Dim fun As CodeFunction = _
CType(sel.ActivePoint.CodeElement( _
vsCMElement.vsCMElementFunction), CodeFunction)
Dim ovrloads As String
If fun.IsOverloaded Then
' Display all the overloads.
Dim ovrload As CodeFunction
For Each ovrload In fun.Overloads
ovrloads &= ovrload.Prototype( _
vsCMPrototype.vsCMPrototypeParamNames Or _
vsCMPrototype.vsCMPrototypeParamTypes Or _
vsCMPrototype.vsCMPrototypeType) & vbCrLf
Next
MsgBox(fun.Name & " has the following overloads:" & _
vbCrLf & vbCrLf & ovrloads)
Else
MsgBox(fun.Name & " isn't overloaded.")
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
public void OverloadsExample(DTE2 dte)
{
// Before running this example, open a code document from a project
// and place the insertion point inside a function.
try
{
// Retrieve the CodeFunction at the insertion point.
TextSelection sel =
(TextSelection)dte.ActiveDocument.Selection;
CodeFunction fun =
(CodeFunction)sel.ActivePoint.get_CodeElement(
vsCMElement.vsCMElementFunction);
string ovrloads = "";
if (fun.IsOverloaded)
{
// Display all the overloads.
foreach (CodeFunction ovrload in fun.Overloads)
{
ovrloads += ovrload.get_Prototype(
(int)(vsCMPrototype.vsCMPrototypeParamNames |
vsCMPrototype.vsCMPrototypeParamTypes |
vsCMPrototype.vsCMPrototypeType)) + "\n";
}
MessageBox.Show(fun.Name +
" has the following overloads:\n\n" + ovrloads);
}
else
{
MessageBox.Show(fun.Name + " isn't overloaded.");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
.NET Framework 安全性
- 对直接调用方的完全信任。此成员不能由部分信任的代码使用。有关更多信息,请参见通过部分受信任的代码使用库。