Właściwość CodeFunction2.MustImplement —
Pobiera lub ustawia wartość wskazującą, czy element jest zadeklarowany jako abstrakcyjny i w związku z tym wymaga implementacji.
Przestrzeń nazw: EnvDTE80
Zestaw: EnvDTE80 (w EnvDTE80.dll)
Składnia
'Deklaracja
Property MustImplement As Boolean
bool MustImplement { get; set; }
property bool MustImplement {
bool get ();
void set (bool value);
}
abstract MustImplement : bool with get, set
function get MustImplement () : boolean
function set MustImplement (value : boolean)
Wartość właściwości
Typ: Boolean
Wartość logiczna, która jest true Jeśli metoda jest zadeklarowany jako abstrakcyjny i w związku z tym wymaga implementacji; w przeciwnym razie false.
Uwagi
MustImplement Zwraca lub ustawia, czy metoda jest zaimplementowana lub wymaga wykonania w podklasach.Należy zauważyć, że w przypadku niektórych języków może to zawsze być false, a ustawienie MustImplement może zakończyć się niepowodzeniem, w zależności od języka.
[!UWAGA]
Po wprowadzeniu niektóre rodzaje edycji, co oznacza, że ich wartości nie można polegać na zawsze jednocześnie może być niedeterministyczne wartości elementów modelu kodu, takich jak klasy, struktur, funkcje, atrybutów, delegatów i tak dalej.Aby uzyskać więcej informacji, zobacz sekcję wartości elementów modelu kod można zmienić w Odnajdowanie kodu za pomocą modelu kodu (Visual Basic).
Przykłady
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);
}
}
Zabezpieczenia programu .NET Framework
- Pełne zaufanie do bezpośredniego wywołującego. Tego elementu członkowskiego nie można używać w kodzie częściowo zaufanym. Aby uzyskać więcej informacji, zobacz Używanie bibliotek pochodzących z częściowo zaufanego kodu.
Zobacz też
Informacje
Inne zasoby
Porady: kompilowanie i uruchamianie kodu modelu obiektów automatyzacji — przykłady