CodeFunction2.MustImplement 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取或设置一个值,该值指示是否声明此项为抽象并需要实现。
public:
property bool MustImplement { bool get(); void set(bool value); };
public:
property bool MustImplement { bool get(); void set(bool value); };
[System.Runtime.InteropServices.DispId(41)]
public bool MustImplement { [System.Runtime.InteropServices.DispId(41)] get; [System.Runtime.InteropServices.DispId(41)] set; }
[<System.Runtime.InteropServices.DispId(41)>]
[<get: System.Runtime.InteropServices.DispId(41)>]
[<set: System.Runtime.InteropServices.DispId(41)>]
member this.MustImplement : bool with get, set
Public Property MustImplement As Boolean
属性值
如果声明此方法为抽象并需要实现,则布尔值为 true;否则为 false。
实现
- 属性
示例
Sub MustImplementExample(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
' Retrieve the CodeClass at the insertion point.
Dim sel As TextSelection = _
CType(dte.ActiveDocument.Selection, TextSelection)
Dim cls As CodeClass = _
CType(sel.ActivePoint.CodeElement( _
vsCMElement.vsCMElementClass), CodeClass)
Dim mustImpl As String
Dim elem As CodeElement
For Each elem In cls.Members
If (elem.Kind = vsCMElement.vsCMElementFunction) Then
Dim fun As CodeFunction = CType(elem, CodeFunction)
If fun.MustImplement Then
mustImpl &= fun.Prototype( _
vsCMPrototype.vsCMPrototypeParamNames Or _
vsCMPrototype.vsCMPrototypeParamTypes Or _
vsCMPrototype.vsCMPrototypeType) & vbCrLf
End If
End If
Next
MsgBox(cls.Name & " has the following abstract methods:" & _
vbCrLf & vbCrLf & mustImpl)
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
public void MustImplementExample(DTE2 dte)
{
// Before running this example, open a code document from a project
// and place the insertion point inside a class definition.
try
{
// Retrieve the CodeClass at the insertion point.
TextSelection sel =
(TextSelection)dte.ActiveDocument.Selection;
CodeClass cls =
(CodeClass)sel.ActivePoint.get_CodeElement(
vsCMElement.vsCMElementClass);
string mustImpl = "";
foreach (CodeElement elem in cls.Members)
{
if (elem.Kind == vsCMElement.vsCMElementFunction)
{
CodeFunction fun = (CodeFunction)elem;
if (fun.MustImplement)
mustImpl += fun.get_Prototype(
(int)(vsCMPrototype.vsCMPrototypeParamNames |
vsCMPrototype.vsCMPrototypeParamTypes |
vsCMPrototype.vsCMPrototypeType)) + "\n";
}
}
MessageBox.Show(cls.Name +
" has the following abstract methods:\n\n" + mustImpl);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
注解
MustImplement 返回或设置方法是在子类中实现还是需要实现。 请注意,对于某些语言,这可能始终是 false ,并且该设置 MustImplement 可能会失败,具体取决于语言。
备注
在进行了某些类型的编辑之后,代码模型元素(例如类、结构、函数、特性、委托等)的值可能变为非确定性的,这意味着不能确定它们的值始终保持不变。