MSIL 방법에서 hidebysig의 목적은 무엇입니까?
ildasm 및 C # 프로그램 사용 예
static void Main(string[] args)
{
}
제공합니다 :
.method private hidebysig static void Main(string[] args) cil managed
{
.entrypoint
// Code size 2 (0x2)
.maxstack 8
IL_0000: nop
IL_0001: ret
} // end of method Program::Main
hidebysig 구조는 무엇을합니까?
에서 ECMA 335 , 파티션 1의 섹션 8.10.4 :
CTS는 기본 유형에서 표시되는 이름 (숨김)과 파생 클래스의 레이아웃 슬롯 공유 (재정의)에 대한 독립적 인 제어를 제공합니다. 숨기기는 파생 클래스의 멤버를 이름으로 숨기기 또는 이름 및 서명으로 숨기기로 표시하여 제어됩니다. 숨기기는 항상 멤버의 종류에 따라 수행됩니다. 즉, 파생 필드 이름은 기본 필드 이름을 숨길 수 있지만 메서드 이름, 속성 이름 또는 이벤트 이름은 숨길 수 없습니다. 파생 멤버가 이름으로 숨기기로 표시되면 동일한 이름을 가진 기본 클래스에서 동일한 종류의 멤버가 파생 클래스에 표시되지 않습니다. 멤버가 이름 및 서명으로 숨기기로 표시되면 정확히 동일한 이름 및 유형 (필드의 경우) 또는 메서드 서명 (메서드의 경우)을 가진 동일한 종류의 멤버 만 파생 클래스에서 숨겨집니다. 이 두 가지 형태의 은폐를 구분하는 구현은 전적으로 소스 언어 컴파일러와 리플렉션 라이브러리에 의해 제공됩니다. VES 자체에는 직접적인 영향을주지 않습니다.
(즉시 명확하지는 않지만 hidebysig
"이름 및 서명으로 숨기기"를 의미합니다.)
또한 파티션 2의 섹션 15.4.2.2에서 :
hidebysig는 도구 사용을 위해 제공되며 VES에서 무시됩니다. 선언 된 메서드가 일치하는 메서드 서명이있는 기본 클래스 형식의 모든 메서드를 숨기도록 지정합니다. 생략하면 서명에 관계없이 동일한 이름의 모든 메서드를 숨겨야합니다.
예를 들어 다음이 있다고 가정합니다.
public class Base
{
public void Bar()
{
}
}
public class Derived : Base
{
public void Bar(string x)
{
}
}
...
Derived d = new Derived();
d.Bar();
때문에 즉, 유효입니다 Bar(string)
하지 않습니다 숨기기 Bar()
때문에 C # 컴파일러의 사용, hidebysig
. "이름으로 숨기기"의미 체계를 사용하는 경우 Bar()
유형 참조에 대해 전혀 호출 Derived
할 수 없지만 여전히 Base로 캐스트하고 그렇게 호출 할 수는 있습니다.
EDIT: I've just tried this by compiling the above code to a DLL, ildasming it, removing hidebysig
for Bar()
and Bar(string)
, ilasming it again, then trying to call Bar()
from other code:
Derived d = new Derived();
d.Bar();
Test.cs(6,9): error CS1501: No overload for method 'Bar' takes '0' arguments
However:
Base d = new Derived();
d.Bar();
(No compilation problems.)
As per THE SKEET's answer, in addition the reason for this is that Java and C# allow the client of a class to call any methods with the same name, including those from base classes. Whereas C++ does not: if the derived class defines even a single method with the same name as a method in the base class, then the client cannot directly call the base class method, even if it doesn't take the same arguments. So the feature was included in CIL to support both approaches to overloading.
In C++ you can effectively import one named set of overloads from the base class with a using
directive, so that they become part of the "overload set" for that method name.
According to Microsoft Docs
When a member in a derived class is declared with the C#
new
modifier or the Visual BasicShadows
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 that has the identical signature. By contrast, Visual Basic hides all the base class overloads. Thus, IsHideBySig returnsfalse
on a member declared with the Visual BasicShadows
modifier, andtrue
on a member declared with the C#new
modifier.
참고URL : https://stackoverflow.com/questions/656325/what-is-the-purpose-of-hidebysig-in-a-msil-method
'IT박스' 카테고리의 다른 글
부트 스트랩 3-navbar 축소 비활성화 (0) | 2020.09.14 |
---|---|
TensorFlow에서 사전 학습 된 단어 임베딩 (word2vec 또는 Glove) 사용 (0) | 2020.09.14 |
Java에서 JSON 개체 구문 분석 (0) | 2020.09.14 |
TypeError : p.easing [this.easing]은 함수가 아닙니다. (0) | 2020.09.14 |
여러 환경에 대한 requirements.txt를 사용자 지정하는 방법은 무엇입니까? (0) | 2020.09.14 |