Export (0) Print
Expand All

MethodBase.IsHideBySig Property

Gets a value indicating whether only a member of the same kind with exactly the same signature is hidden in the derived class.

Namespace:  System.Reflection
Assembly:  mscorlib (in mscorlib.dll)

public bool IsHideBySig { get; }

Property Value

Type: System.Boolean
true if the member is hidden by signature; otherwise, false.

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# hides base class members by signature. That is, if the base class member has multiple overloads, the only one that is hidden is the one with the identical signature. By contrast, Visual Basic hides all the base class overloads. Thus, IsHideBySig returns false on a member declared with the Visual Basic Shadows modifier, and true on a member declared with the C# new modifier.

The following code example contains a base class with an overloaded method, and a derived class that hides one of the overloads. In the Visual Basic version of the code example, the IsHideBySig property returns false for the member in the derived class. In the C# version of the code sample, the property returns true for the member in the derived class.

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)
*/

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360, Zune

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 3.5, 2.0, 1.0

XNA Framework

Supported in: 3.0, 2.0, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft