MethodBase.IsHideBySig MethodBase.IsHideBySig MethodBase.IsHideBySig MethodBase.IsHideBySig Property

Definition

Ruft einen Wert ab, der angibt, ob nur ein Member derselben Art mit einer identischen Signatur in der abgeleiteten Klasse verborgen ist.Gets a value indicating whether only a member of the same kind with exactly the same signature is hidden in the derived class.

public:
 property bool IsHideBySig { bool get(); };
public bool IsHideBySig { get; }
member this.IsHideBySig : bool
Public ReadOnly Property IsHideBySig As Boolean

Eigenschaftswert

true, wenn der Member durch die Signatur verborgen ist, andernfalls false.true if the member is hidden by signature; otherwise, false.

Implementiert

Beispiele

Das folgende Codebeispiel enthält eine Basisklasse mit einer überladenen-Methode und eine abgeleitete Klasse, die eine der-über Ladungen ausblendet.The following code example contains a base class with an overloaded method, and a derived class that hides one of the overloads. In der Visual Basic-Version des Code Beispiels gibt die IsHideBySig -Eigenschaft false für den Member in der abgeleiteten Klasse zurück.In the Visual Basic version of the code example, the IsHideBySig property returns false for the member in the derived class. In der C# -Version des Code Beispiels gibt die-Eigenschaft true für den Member in der abgeleiteten Klasse zurück.In the C# version of the code sample, the property returns true for the member in the derived class.

using namespace System;
using namespace System::Reflection;

// The base class Parent contains an overloaded method PrintCall.
//
public ref class Parent
{
public:
    virtual void PrintCall()
    {
        Console::WriteLine("Parent's PrintCall()");
    }
public:
    virtual void PrintCall(int x)
    {
        Console::WriteLine("Parent's PrintCall({0})", x);
    }
};

// The derived class Child hides one overload of the inherited 
// method PrintCall.
//
public ref class Child : public Parent
{
public:
    void PrintCall(int i) new
    {
        Console::WriteLine("Child's PrintCall({0})", i);
    }
};

int main()
{
    Child^ childInstance = gcnew Child();

    // In C#, the method in the derived class hides by name and by
    // signature, so the overload in the derived class hides only one
    // of the overloads in the base class.
    //
    Console::WriteLine("------ List the overloads of PrintCall in the " +
        "derived class Child ------");
    Type^ t = childInstance->GetType();
    for each(MethodInfo^ minfo in t->GetMethods())
    {
        if (minfo->Name == "PrintCall")
        {
            Console::WriteLine("Overload of PrintCall: {0}" +
                " IsHideBySig = {1}, DeclaringType = {2}", 
                minfo, minfo->IsHideBySig, minfo->DeclaringType);
        }
    }

    // The method PrintCall in the derived class hides one overload of the 
    // method in Parent.  Contrast this with Visual Basic, which hides by
    // name instead of by name and signature.  In Visual Basic, the
    // parameterless overload of PrintCall would be unavailable from Child.
    //
    Console::WriteLine(
        "------ Call the overloads of PrintCall available in Child ------");
    childInstance->PrintCall();
    childInstance->PrintCall(42);

    // If Child is cast to the base type Parent, both overloads of the 
    // shadowed method can be called.
    //
    Console::WriteLine(
        "------ Call the shadowed overloads of PrintCall ------");
    Parent^ parentInstance = childInstance;
    parentInstance->PrintCall();
    parentInstance->PrintCall(42);
}

/* This code example produces the following output:

------ List the overloads of PrintCall in the derived class Child ------
Overload of PrintCall: Void PrintCall(Int32) IsHideBySig = True, DeclaringType = Child
Overload of PrintCall: Void PrintCall() IsHideBySig = True, DeclaringType = Parent
Overload of PrintCall: Void PrintCall(Int32) IsHideBySig = True, DeclaringType = Parent
------ Call the overloads of PrintCall available in Child ------
Parent's PrintCall()
Child's PrintCall(42)
------ Call the shadowed overloads of PrintCall ------
Parent's PrintCall()
Parent's PrintCall(42)

*/

using System;
using System.Reflection;

// The base class B contains an overloaded method M.
//
public class B
{
    public virtual void M()
    {
        Console.WriteLine("B's M()");
    }
    public virtual void M(int x)
    {
        Console.WriteLine("B's M({0})", x);
    }
}

// The derived class D hides one overload of the inherited 
// method M.
//
public class D:
    B
{
    new public void M(int i)
    {
        Console.WriteLine("D's M({0})", i);
    }
}

public class Test
{
    public static void Main()
    {
        D dinst = new D();
        // In C#, the method in the derived class hides by name and by
        // signature, so the overload in the derived class hides only one
        // of the overloads in the base class.
        //
        Console.WriteLine("------ List the overloads of M in the derived class D ------");
        Type t = dinst.GetType();
        foreach( MethodInfo minfo in t.GetMethods() )
        {
            if (minfo.Name=="M") {Console.WriteLine("Overload of M: {0}  IsHideBySig = {1}, DeclaringType = {2}", minfo, minfo.IsHideBySig, minfo.DeclaringType);}
        }

        // The method M in the derived class hides one overload of the 
        // method in B.  Contrast this with Visual Basic, which hides by
        // name instead of by name and signature.  In Visual Basic, the
        // parameterless overload of M would be unavailable from D.
        //
        Console.WriteLine("------ Call the overloads of M available in D ------");
        dinst.M();
        dinst.M(42);
        
        // If D is cast to the base type B, both overloads of the 
        // shadowed method can be called.
        //
        Console.WriteLine("------ Call the shadowed overloads of M ------");
        B binst = dinst;
        binst.M();
        binst.M(42);
    } //Main
} //Test

/* This code example produces the following output:

------ List the overloads of M in the derived class D ------
Overload of M: Void M(Int32)  IsHideBySig = True, DeclaringType = B
Overload of M: Void M()  IsHideBySig = True, DeclaringType = B
Overload of M: Void M(Int32)  IsHideBySig = True, DeclaringType = D
------ Call the overloads of M available in D ------
B's M()
D's M(42)
------ Call the shadowed overloads of M ------
B's M()
B's M(42)
*/

Imports System.Reflection

' The base class B contains an overloaded method M.
'
Public Class B
    Public Overridable Sub M()
        Console.WriteLine("B's M()")
    End Sub
    Public Overridable Sub M(ByVal x As Integer)
        Console.WriteLine("B's M({0})", x)
    End Sub
End Class

' The derived class D hides the inherited method M.
'
Public Class D
    Inherits B
    Shadows Public Sub M(ByVal i As Integer)
        Console.WriteLine("D's M({0})", i)
    End Sub
End Class

Public Class Test
    Public Shared Sub Main()
        Dim dinst As New D()
        ' In Visual Basic, the method in the derived class hides by
        ' name, rather than by signature.  Thus, although a list of all the 
        ' overloads of M shows three overloads, only one can be called from
        ' class D.  
        '
        Console.WriteLine("------ List the overloads of M in the derived class D ------")
        Dim t As Type = dinst.GetType()
        For Each minfo As MethodInfo In t.GetMethods()
            If minfo.Name = "M" Then Console.WriteLine( _
                "Overload of M: {0}  IsHideBySig = {1}, DeclaringType = {2}", _
                minfo, minfo.IsHideBySig, minfo.DeclaringType)
        Next

        ' The method M in the derived class hides the method in B.
        '
        Console.WriteLine("------ Call the overloads of M available in D ------")
        ' The following line causes a compile error, because both overloads
        ' in the base class are hidden.  Contrast this with C#, where only 
        ' one of the overloads of B would be hidden.
        'dinst.M()
        dinst.M(42)
        
        ' If D is cast to the base type B, both overloads of the 
        ' shadowed method can be called.
        '
        Console.WriteLine("------ Call the shadowed overloads of M ------")
        Dim binst As B = dinst
        binst.M()
        binst.M(42)         
    End Sub 'Main
End Class 'Test

' This code example produces the following output:
' ------ List the overloads of M in the derived class D ------
' Overload of M: Void M(Int32)  IsHideBySig = False, DeclaringType = B
' Overload of M: Void M()  IsHideBySig = False, DeclaringType = B
' Overload of M: Void M(Int32)  IsHideBySig = False, DeclaringType = D
' ------ Call the overloads of M available in D ------
' D's M(42)
' ------ Call the shadowed overloads of M ------
' B's M()
' B's M(42)

Hinweise

Wenn ein Element in einer abgeleiteten Klasse mit dem C# new Modifizierer oder dem Visual Basic Shadows Modifizierer deklariert wird, kann ein Member mit demselben Namen in der Basisklasse ausgeblendet werden.When a member in a derived class is declared with the C# new modifier or the Visual Basic Shadows modifier, it can hide a member of the same name in the base class. C#Blendet Basisklassenmember nach Signatur aus.C# hides base class members by signature. Das heißt, wenn der Basisklassenmember über mehrere über Ladungen verfügt, ist der einzige, der ausgeblendet ist, der einzige, der die gleiche Signatur aufweist.That is, if the base class member has multiple overloads, the only one that is hidden is the one that has the identical signature. Im Gegensatz dazu blendet Visual Basic alle über Ladungen der Basisklasse aus.By contrast, Visual Basic hides all the base class overloads. C# new true Shadows Folglich gibt für false einen Member zurück, der mit dem Visual Basic Modifizierer deklariert wurde, und für einen Member, der mit dem-Modifizierer deklariert wird. IsHideBySigThus, IsHideBySig returns false on a member declared with the Visual Basic Shadows modifier, and true on a member declared with the C# new modifier.

Warnung

Diese Eigenschaft bestimmt nicht, ob eine Methode über das NewSlot -Attribut verfügt.This property does not determine whether a method has the NewSlot attribute. Eine Methode, die mit dem new - Shadows Modifizierer oder dem-Modifizierer deklariert wird, verfügt über das new NewSlot -Attribut, aber nur C# Methoden, die mit deklariert IsHideBySig werden (d. h. nur Methoden), legen die-Eigenschafttrue.A method that is declared with either the new or the Shadows modifier will have the NewSlot attribute, but only methods declared with new (that is, only C# methods) will have the IsHideBySig property set to true. Um zu ermitteln, ob eine Methode NewSlot über das-Attribut verfügt, verwenden Sie Code, C# der If (myMethodInfo.Attributes And MethodAttributes.VtableLayoutMask) = MethodAttributes.NewSlot dem folgenden ähnelt: if ((myMethodInfo.Attributes & MethodAttributes.VtableLayoutMask) == MethodAttributes.NewSlot) in oder in Visual Basic.To determine whether a method has the NewSlot attribute, use code similar to the following: if ((myMethodInfo.Attributes & MethodAttributes.VtableLayoutMask) == MethodAttributes.NewSlot) in C# or If (myMethodInfo.Attributes And MethodAttributes.VtableLayoutMask) = MethodAttributes.NewSlot in Visual Basic. Beachten Sie jedoch, dass, obwohl alle mit new oder Shadows deklarierten Methoden NewSlot über das-Attribut verfügen, nicht alle NewSlot Methoden, die über new das Shadows-Attribut verfügen, mit oder deklariert werden.Note, however, that although all methods declared with new or Shadows have the NewSlot attribute, not all methods that have the NewSlot attribute are declared with new or Shadows.

Gilt für: