MethodBase.IsHideBySig 속성
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
정확히 동일한 시그니처를 가진 동일한 종류의 멤버만 파생 클래스에 숨겨져 있는지 여부를 나타내는 값을 가져옵니다.
public:
property bool IsHideBySig { bool get(); };
public bool IsHideBySig { get; }
member this.IsHideBySig : bool
Public ReadOnly Property IsHideBySig As Boolean
속성 값
true멤버가 서명으로 숨겨지면 그렇지 않으면 . false
구현
예제
다음 코드 예제에는 오버로드된 메서드가 있는 기본 클래스와 오버로드 중 하나를 숨기는 파생 클래스가 포함되어 있습니다. 코드 예제의 Visual Basic 버전에서 속성은 IsHideBySig 파생 클래스의 멤버에 대해 반환 false 합니다. 코드 샘플의 C# 버전에서 속성은 파생 클래스의 멤버에 대해 반환 true 합니다.
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
End Class
' 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)
설명
파생 클래스의 멤버가 C# new 한정자 또는 Visual Basic Shadows 한정자를 사용하여 선언되면 기본 클래스에서 동일한 이름의 멤버를 숨길 수 있습니다. C#은 서명별로 기본 클래스 멤버를 숨깁니다. 즉, 기본 클래스 멤버에 오버로드가 여러 개 있는 경우 숨겨진 유일한 멤버는 동일한 시그니처가 있는 멤버입니다. 반면 Visual Basic은 모든 기본 클래스 오버로드를 숨깁니다.
IsHideBySig 따라서 Visual Basic Shadows 한정자를 사용하여 선언된 멤버와 true C# new 한정자를 사용하여 선언된 멤버를 반환 false 합니다.
경고
이 속성은 메서드 NewSlot 에 특성이 있는지 여부를 결정하지 않습니다. 또는 Shadows 한정자를 NewSlot 사용하여 new 선언된 메서드에는 특성이 있지만 선언된 new 메서드(즉, C# 메서드만)IsHideBySig로 설정된 true메서드만 있습니다. 메서드 NewSlot 에 특성이 있는지 확인하려면 C# 또는 If (myMethodInfo.Attributes And MethodAttributes.VtableLayoutMask) = MethodAttributes.NewSlot Visual Basic에서 다음과 if ((myMethodInfo.Attributes & MethodAttributes.VtableLayoutMask) == MethodAttributes.NewSlot) 유사한 코드를 사용합니다. 그러나 특성을 사용하여 선언되거나 newShadowsNewSlot 있는 모든 메서드가 있지만 특성이 있는 모든 메서드가 NewSlot 선언되거나 Shadows선언되지 new 는 않습니다.